Repository navigation
App Check (Desktop): register function registry calls on every App #1985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AustinBenoit
wants to merge
4
commits into
main
Choose a base branch
from
fix/app-check-register-per-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+188
−26
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
187db2c
App Check (Desktop): register function registry calls on every App
AustinBenoit d326365
App Check (Desktop): guard InitRegistryCalls and CleanupRegistryCalls…
AustinBenoit 79afaee
Merge remote-tracking branch 'origin/main' into fix/app-check-registe…
AustinBenoit 5775a36
Merge origin/main and test AppCheck CleanupRegistryCalls() per-App un…
AustinBenoit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <functional> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "app/src/function_registry.h" | ||
| #include "app/src/include/firebase/app.h" | ||
| #include "app/src/include/firebase/future.h" | ||
| #include "app/tests/include/firebase/app_for_testing.h" | ||
| #include "firebase/app_check.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace firebase { | ||
| namespace app_check { | ||
| namespace { | ||
|
|
||
| // Hands out a token that names the App the provider was created for. | ||
| class NamedTokenProvider : public AppCheckProvider { | ||
| public: | ||
| explicit NamedTokenProvider(App* app) | ||
| : token_(std::string("token-for-") + app->name()) {} | ||
|
|
||
| void GetToken(std::function<void(AppCheckToken, int, const std::string&)> | ||
| completion_callback) override { | ||
| AppCheckToken token; | ||
| token.token = token_; | ||
| token.expire_time_millis = 4102444800000LL; // 2100-01-01. | ||
| completion_callback(token, kAppCheckErrorNone, ""); | ||
| } | ||
|
|
||
| private: | ||
| std::string token_; | ||
| }; | ||
|
|
||
| class NamedTokenProviderFactory : public AppCheckProviderFactory { | ||
| public: | ||
| AppCheckProvider* CreateProvider(App* app) override { | ||
| providers_.push_back(std::make_unique<NamedTokenProvider>(app)); | ||
| return providers_.back().get(); | ||
| } | ||
|
|
||
| private: | ||
| std::vector<std::unique_ptr<NamedTokenProvider>> providers_; | ||
| }; | ||
|
|
||
| class AppCheckDesktopTest : public ::testing::Test { | ||
| protected: | ||
| void SetUp() override { AppCheck::SetAppCheckProviderFactory(&factory_); } | ||
| void TearDown() override { AppCheck::SetAppCheckProviderFactory(nullptr); } | ||
|
|
||
| NamedTokenProviderFactory factory_; | ||
| }; | ||
|
|
||
| // Regression tests for | ||
| // https://github.com/firebase/firebase-cpp-sdk/issues/1970. Other products look | ||
| // up App Check through the function registry of their own App, so every App | ||
| // with an AppCheck instance needs the functions registered. | ||
| TEST_F(AppCheckDesktopTest, RegistersRegistryFunctionsOnEveryApp) { | ||
| std::unique_ptr<App> default_app(testing::CreateApp()); | ||
| std::unique_ptr<App> second_app( | ||
| testing::CreateApp(testing::MockAppOptions(), "second")); | ||
| std::unique_ptr<AppCheck> default_app_check( | ||
| AppCheck::GetInstance(default_app.get())); | ||
| std::unique_ptr<AppCheck> second_app_check( | ||
| AppCheck::GetInstance(second_app.get())); | ||
|
|
||
| for (::firebase::internal::FunctionId id : | ||
| {::firebase::internal::FnAppCheckGetTokenAsync, | ||
| ::firebase::internal::FnAppCheckGetLimitedUseTokenAsync, | ||
| ::firebase::internal::FnAppCheckAddListener, | ||
| ::firebase::internal::FnAppCheckRemoveListener}) { | ||
| EXPECT_TRUE(default_app->function_registry()->FunctionExists(id)) << id; | ||
| EXPECT_TRUE(second_app->function_registry()->FunctionExists(id)) << id; | ||
| } | ||
| } | ||
|
|
||
| TEST_F(AppCheckDesktopTest, EachAppGetsItsOwnTokenThroughItsRegistry) { | ||
| std::unique_ptr<App> default_app(testing::CreateApp()); | ||
| std::unique_ptr<App> second_app( | ||
| testing::CreateApp(testing::MockAppOptions(), "second")); | ||
| std::unique_ptr<AppCheck> default_app_check( | ||
| AppCheck::GetInstance(default_app.get())); | ||
| std::unique_ptr<AppCheck> second_app_check( | ||
| AppCheck::GetInstance(second_app.get())); | ||
|
|
||
| for (App* app : {default_app.get(), second_app.get()}) { | ||
| Future<std::string> token; | ||
| ASSERT_TRUE(app->function_registry()->CallFunction( | ||
| ::firebase::internal::FnAppCheckGetTokenAsync, app, nullptr, &token)) | ||
| << app->name(); | ||
| ASSERT_EQ(token.status(), kFutureStatusComplete) << app->name(); | ||
| ASSERT_EQ(token.error(), kAppCheckErrorNone) << app->name(); | ||
| EXPECT_EQ(*token.result(), std::string("token-for-") + app->name()); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(AppCheckDesktopTest, | ||
| DestroyingAppCheckUnregistersOnlyItsAppsRegistryFunctions) { | ||
| const ::firebase::internal::FunctionId kAppCheckFunctions[] = { | ||
| ::firebase::internal::FnAppCheckGetTokenAsync, | ||
| ::firebase::internal::FnAppCheckGetLimitedUseTokenAsync, | ||
| ::firebase::internal::FnAppCheckAddListener, | ||
| ::firebase::internal::FnAppCheckRemoveListener, | ||
| }; | ||
| std::unique_ptr<App> default_app(testing::CreateApp()); | ||
| std::unique_ptr<App> second_app( | ||
| testing::CreateApp(testing::MockAppOptions(), "second")); | ||
| std::unique_ptr<AppCheck> default_app_check( | ||
| AppCheck::GetInstance(default_app.get())); | ||
| std::unique_ptr<AppCheck> second_app_check( | ||
| AppCheck::GetInstance(second_app.get())); | ||
|
|
||
| default_app_check.reset(); | ||
|
|
||
| for (::firebase::internal::FunctionId id : kAppCheckFunctions) { | ||
| EXPECT_FALSE(default_app->function_registry()->FunctionExists(id)) << id; | ||
| EXPECT_TRUE(second_app->function_registry()->FunctionExists(id)) << id; | ||
| } | ||
|
|
||
| Future<std::string> unregistered_token; | ||
| EXPECT_FALSE(default_app->function_registry()->CallFunction( | ||
| ::firebase::internal::FnAppCheckGetTokenAsync, default_app.get(), nullptr, | ||
| &unregistered_token)); | ||
| for (::firebase::internal::FunctionId id : kAppCheckFunctions) { | ||
| EXPECT_FALSE(default_app->function_registry()->FunctionExists(id)) << id; | ||
| } | ||
|
|
||
| Future<std::string> second_token; | ||
| ASSERT_TRUE(second_app->function_registry()->CallFunction( | ||
| ::firebase::internal::FnAppCheckGetTokenAsync, second_app.get(), nullptr, | ||
| &second_token)); | ||
| ASSERT_EQ(second_token.status(), kFutureStatusComplete); | ||
| ASSERT_EQ(second_token.error(), kAppCheckErrorNone); | ||
| EXPECT_EQ(*second_token.result(), "token-for-second"); | ||
|
|
||
| default_app_check.reset(AppCheck::GetInstance(default_app.get())); | ||
| ASSERT_NE(default_app_check, nullptr); | ||
| for (::firebase::internal::FunctionId id : kAppCheckFunctions) { | ||
| EXPECT_TRUE(default_app->function_registry()->FunctionExists(id)) << id; | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace app_check | ||
| } // namespace firebase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.