-
Notifications
You must be signed in to change notification settings - Fork 5.3k
ssl: remember stat names for configured ciphers. #14534
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
Changes from all commits
d3455ae
a8f7b25
5a6e778
fd85180
af644ed
ec3fb68
9fb5df3
9d7d0ed
91dbc25
e5e3192
26ca039
2f37980
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 |
|---|---|---|
|
|
@@ -1934,6 +1934,73 @@ TEST_F(ServerContextConfigImplTest, PrivateKeyMethodLoadFailureBothKeyAndMethod) | |
| "Certificate configuration can't have both private_key and private_key_provider"); | ||
| } | ||
|
|
||
| // Subclass ContextImpl so we can instantiate directly from tests, despite the | ||
| // constructor being protected. | ||
| class TestContextImpl : public ContextImpl { | ||
| public: | ||
| TestContextImpl(Stats::Scope& scope, const Envoy::Ssl::ContextConfig& config, | ||
| TimeSource& time_source) | ||
| : ContextImpl(scope, config, time_source), pool_(scope.symbolTable()), | ||
| fallback_(pool_.add("fallback")) {} | ||
|
|
||
| void incCounter(absl::string_view name, absl::string_view value) { | ||
| ContextImpl::incCounter(pool_.add(name), value, fallback_); | ||
| } | ||
|
|
||
| Stats::StatNamePool pool_; | ||
| const Stats::StatName fallback_; | ||
| }; | ||
|
|
||
| class SslContextStatsTest : public SslContextImplTest { | ||
| protected: | ||
| SslContextStatsTest() { | ||
| TestUtility::loadFromYaml(TestEnvironment::substitute(yaml), tls_context_); | ||
| client_context_config_ = | ||
| std::make_unique<ClientContextConfigImpl>(tls_context_, factory_context_); | ||
| context_ = std::make_unique<TestContextImpl>(store_, *client_context_config_, time_system_); | ||
| } | ||
|
|
||
| Stats::TestUtil::TestStore store_; | ||
| envoy::extensions::transport_sockets::tls::v3::UpstreamTlsContext tls_context_; | ||
| std::unique_ptr<ClientContextConfigImpl> client_context_config_; | ||
| std::unique_ptr<TestContextImpl> context_; | ||
| const std::string yaml = R"EOF( | ||
| common_tls_context: | ||
| tls_certificates: | ||
| certificate_chain: | ||
| filename: "{{ test_rundir }}/test/extensions/transport_sockets/tls/test_data/unittest_cert.pem" | ||
| private_key: | ||
| filename: "{{ test_rundir }}/test/extensions/transport_sockets/tls/test_data/unittest_key.pem" | ||
| )EOF"; | ||
| }; | ||
|
|
||
| TEST_F(SslContextStatsTest, IncOnlyKnownCounters) { | ||
| // Incrementing a value for a cipher that is part of the configuration works, and | ||
| // we'll be able to find the value in the stats store. | ||
| context_->incCounter("ssl.ciphers", "ECDHE-ECDSA-AES256-GCM-SHA384"); | ||
| Stats::CounterOptConstRef cipher = | ||
| store_.findCounterByString("ssl.ciphers.ECDHE-ECDSA-AES256-GCM-SHA384"); | ||
| ASSERT_TRUE(cipher.has_value()); | ||
| EXPECT_EQ(1, cipher->get().value()); | ||
|
|
||
| // Incrementing a stat for a random unknown cipher does not work. A | ||
| // rate-limited error log message will also be generated but that is hard to | ||
|
Member
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. As noted above, an ENVOY_BUG would make this easier to test
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. not super-easy, but done :) The trick with ENVOY_BUG is that (from what I saw) it won't execute the fallback logic when it aborts. |
||
| // test as it is dependent on timing and test-ordering. | ||
| EXPECT_DEBUG_DEATH(context_->incCounter("ssl.ciphers", "unexpected"), | ||
| "Unexpected ssl.ciphers value: unexpected"); | ||
| EXPECT_FALSE(store_.findCounterByString("ssl.ciphers.unexpected")); | ||
|
|
||
| // We will account for the 'unexpected' cipher as "fallback", however in debug | ||
| // mode that will not work as the ENVOY_BUG macro will assert first, thus the | ||
| // fallback registration does not occur. So we test for the fallback only in | ||
| // release builds. | ||
| #ifdef NDEBUG | ||
| cipher = store_.findCounterByString("ssl.ciphers.fallback"); | ||
| ASSERT_TRUE(cipher.has_value()); | ||
| EXPECT_EQ(1, cipher->get().value()); | ||
| #endif | ||
| } | ||
jmarantz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| } // namespace Tls | ||
| } // namespace TransportSockets | ||
| } // namespace Extensions | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.