-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix oauth filter sds update #16253
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
fix oauth filter sds update #16253
Changes from all commits
5108686
948a0f4
6ee2773
d4b5c12
f8c5d39
f4b3755
d166c84
cd71d20
e87f907
4ac587a
05cee4f
21e7131
4da1c5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| #include "common/http/message_impl.h" | ||
| #include "common/protobuf/message_validator_impl.h" | ||
| #include "common/protobuf/utility.h" | ||
| #include "common/secret/secret_manager_impl.h" | ||
|
|
||
| #include "extensions/filters/http/oauth2/filter.h" | ||
|
|
||
|
|
@@ -155,6 +156,81 @@ class OAuth2Test : public testing::Test { | |
| Event::SimulatedTimeSystem test_time_; | ||
| }; | ||
|
|
||
| // Verifies that the OAuth SDSSecretReader correctly updates dynamic generic secret. | ||
| TEST_F(OAuth2Test, SdsDynamicGenericSecret) { | ||
| NiceMock<Server::MockConfigTracker> config_tracker; | ||
| Secret::SecretManagerImpl secret_manager{config_tracker}; | ||
| envoy::config::core::v3::ConfigSource config_source; | ||
|
|
||
| NiceMock<Server::Configuration::MockTransportSocketFactoryContext> secret_context; | ||
| NiceMock<LocalInfo::MockLocalInfo> local_info; | ||
| Api::ApiPtr api = Api::createApiForTest(); | ||
| Stats::IsolatedStoreImpl stats; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least this one can use the store_ defined on the fixture class instead of redefining one here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will be more readable if we leave it in the function scope to save the context. |
||
| NiceMock<Init::MockManager> init_manager; | ||
| Init::TargetHandlePtr init_handle; | ||
| NiceMock<Event::MockDispatcher> dispatcher; | ||
| EXPECT_CALL(secret_context, localInfo()).WillRepeatedly(ReturnRef(local_info)); | ||
| EXPECT_CALL(secret_context, api()).WillRepeatedly(ReturnRef(*api)); | ||
| EXPECT_CALL(secret_context, dispatcher()).WillRepeatedly(ReturnRef(dispatcher)); | ||
| EXPECT_CALL(secret_context, stats()).WillRepeatedly(ReturnRef(stats)); | ||
| EXPECT_CALL(secret_context, initManager()).WillRepeatedly(ReturnRef(init_manager)); | ||
| EXPECT_CALL(init_manager, add(_)) | ||
| .WillRepeatedly(Invoke([&init_handle](const Init::Target& target) { | ||
| init_handle = target.createHandle("test"); | ||
| })); | ||
|
|
||
| auto client_secret_provider = | ||
| secret_manager.findOrCreateGenericSecretProvider(config_source, "client", secret_context); | ||
| auto client_callback = secret_context.cluster_manager_.subscription_factory_.callbacks_; | ||
| auto token_secret_provider = | ||
| secret_manager.findOrCreateGenericSecretProvider(config_source, "token", secret_context); | ||
| auto token_callback = secret_context.cluster_manager_.subscription_factory_.callbacks_; | ||
|
|
||
| SDSSecretReader secret_reader(client_secret_provider, token_secret_provider, *api); | ||
| EXPECT_TRUE(secret_reader.clientSecret().empty()); | ||
| EXPECT_TRUE(secret_reader.tokenSecret().empty()); | ||
|
|
||
| const std::string yaml_client = R"EOF( | ||
| name: client | ||
| generic_secret: | ||
| secret: | ||
| inline_string: "client_test" | ||
| )EOF"; | ||
|
|
||
| envoy::extensions::transport_sockets::tls::v3::Secret typed_secret; | ||
| TestUtility::loadFromYaml(yaml_client, typed_secret); | ||
| const auto decoded_resources_client = TestUtility::decodeResources({typed_secret}); | ||
|
|
||
| client_callback->onConfigUpdate(decoded_resources_client.refvec_, ""); | ||
| EXPECT_EQ(secret_reader.clientSecret(), "client_test"); | ||
| EXPECT_EQ(secret_reader.tokenSecret(), ""); | ||
|
|
||
| const std::string yaml_token = R"EOF( | ||
| name: token | ||
| generic_secret: | ||
| secret: | ||
| inline_string: "token_test" | ||
| )EOF"; | ||
| TestUtility::loadFromYaml(yaml_token, typed_secret); | ||
| const auto decoded_resources_token = TestUtility::decodeResources({typed_secret}); | ||
|
|
||
| token_callback->onConfigUpdate(decoded_resources_token.refvec_, ""); | ||
| EXPECT_EQ(secret_reader.clientSecret(), "client_test"); | ||
| EXPECT_EQ(secret_reader.tokenSecret(), "token_test"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add another check where token stays the same, but the client secret is updated again? To make sure that an update to client secret doesn't overwrite the token. |
||
|
|
||
| const std::string yaml_client_recheck = R"EOF( | ||
| name: client | ||
| generic_secret: | ||
| secret: | ||
| inline_string: "client_test_recheck" | ||
| )EOF"; | ||
| TestUtility::loadFromYaml(yaml_client_recheck, typed_secret); | ||
| const auto decoded_resources_client_recheck = TestUtility::decodeResources({typed_secret}); | ||
|
|
||
| client_callback->onConfigUpdate(decoded_resources_client_recheck.refvec_, ""); | ||
| EXPECT_EQ(secret_reader.clientSecret(), "client_test_recheck"); | ||
| EXPECT_EQ(secret_reader.tokenSecret(), "token_test"); | ||
| } | ||
| // Verifies that we fail constructing the filter if the configured cluster doesn't exist. | ||
| TEST_F(OAuth2Test, InvalidCluster) { | ||
| ON_CALL(factory_context_.cluster_manager_, clusters()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding a test for this function? Ideally we have coverage for this outside of extensions. Thanks!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can copy-past some tests from utility_test.cpp with parseCookieValue check and trasnform them for parseSetCookieValue. Will it be okay?