Skip to content

Commit

Permalink
tls: improve validation that context is successfully created (#36512)
Browse files Browse the repository at this point in the history
`createSslClientContext` used to throw on error. Refactor to explictly check
success on the StatusOr.

Signed-off-by: Greg Greenway <[email protected]>
  • Loading branch information
ggreenway authored Oct 9, 2024
1 parent c6761de commit 1f05d19
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions test/common/tls/context_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,9 @@ TEST_F(ClientContextConfigImplTest, RSA2048Cert) {
*tls_context.mutable_common_tls_context()->add_tls_certificates());
auto client_context_config = *ClientContextConfigImpl::create(tls_context, factory_context_);
Stats::IsolatedStoreImpl store;
auto context = *manager_.createSslClientContext(*store.rootScope(), *client_context_config);
auto cleanup = cleanUpHelper(context);
auto context_or = manager_.createSslClientContext(*store.rootScope(), *client_context_config);
EXPECT_TRUE(context_or.ok());
auto cleanup = cleanUpHelper(*context_or);
}

// Validate that 1024-bit RSA certificates are rejected.
Expand Down Expand Up @@ -1370,8 +1371,9 @@ TEST_F(ClientContextConfigImplTest, RSA3072Cert) {
auto client_context_config = *ClientContextConfigImpl::create(tls_context, factory_context_);
ContextManagerImpl manager(server_factory_context_);
Stats::IsolatedStoreImpl store;
auto context = *manager_.createSslClientContext(*store.rootScope(), *client_context_config);
auto cleanup = cleanUpHelper(context);
auto context_or = manager_.createSslClientContext(*store.rootScope(), *client_context_config);
EXPECT_TRUE(context_or.ok());
auto cleanup = cleanUpHelper(*context_or);
}

// Validate that 4096-bit RSA certificates load successfully.
Expand All @@ -1387,8 +1389,9 @@ TEST_F(ClientContextConfigImplTest, RSA4096Cert) {
*tls_context.mutable_common_tls_context()->add_tls_certificates());
auto client_context_config = *ClientContextConfigImpl::create(tls_context, factory_context_);
Stats::IsolatedStoreImpl store;
auto context = *manager_.createSslClientContext(*store.rootScope(), *client_context_config);
auto cleanup = cleanUpHelper(context);
auto context_or = manager_.createSslClientContext(*store.rootScope(), *client_context_config);
EXPECT_TRUE(context_or.ok());
auto cleanup = cleanUpHelper(*context_or);
}

// Validate that P256 ECDSA certs load.
Expand All @@ -1404,8 +1407,9 @@ TEST_F(ClientContextConfigImplTest, P256EcdsaCert) {
*tls_context.mutable_common_tls_context()->add_tls_certificates());
auto client_context_config = *ClientContextConfigImpl::create(tls_context, factory_context_);
Stats::IsolatedStoreImpl store;
auto context = *manager_.createSslClientContext(*store.rootScope(), *client_context_config);
auto cleanup = cleanUpHelper(context);
auto context_or = manager_.createSslClientContext(*store.rootScope(), *client_context_config);
EXPECT_TRUE(context_or.ok());
auto cleanup = cleanUpHelper(*context_or);
}

// Validate that non-P256 ECDSA certs are rejected.
Expand Down

0 comments on commit 1f05d19

Please sign in to comment.