|
|
|
@ -406,6 +406,20 @@ TEST(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) { |
|
|
|
|
gpr_free(const_cast<char*>(c_arg.peer_cert)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CredentialsTest, TlsChannelCredentialsWithDefaultRoots) { |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options; |
|
|
|
|
options.set_server_verification_option(GRPC_TLS_SERVER_VERIFICATION); |
|
|
|
|
auto test_server_authorization_check = |
|
|
|
|
std::make_shared<TestTlsServerAuthorizationCheck>(); |
|
|
|
|
auto server_authorization_check_config = |
|
|
|
|
std::make_shared<TlsServerAuthorizationCheckConfig>( |
|
|
|
|
test_server_authorization_check); |
|
|
|
|
options.set_server_authorization_check_config( |
|
|
|
|
server_authorization_check_config); |
|
|
|
|
auto channel_credentials = grpc::experimental::TlsCredentials(options); |
|
|
|
|
GPR_ASSERT(channel_credentials.get() != nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST( |
|
|
|
|
CredentialsTest, |
|
|
|
|
TlsChannelCredentialsWithStaticDataCertificateProviderLoadingRootAndIdentity) { |
|
|
|
@ -421,8 +435,8 @@ TEST( |
|
|
|
|
auto server_authorization_check_config = |
|
|
|
|
std::make_shared<TlsServerAuthorizationCheckConfig>( |
|
|
|
|
test_server_authorization_check); |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options( |
|
|
|
|
certificate_provider); |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options; |
|
|
|
|
options.set_certificate_provider(certificate_provider); |
|
|
|
|
options.watch_root_certs(); |
|
|
|
|
options.set_root_cert_name(kRootCertName); |
|
|
|
|
options.watch_identity_key_cert_pairs(); |
|
|
|
@ -434,9 +448,6 @@ TEST( |
|
|
|
|
GPR_ASSERT(channel_credentials.get() != nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ChannelCredentials should always have root credential presented.
|
|
|
|
|
// Otherwise the system root certificates will be loaded, which will cause
|
|
|
|
|
// failure in some tests under MacOS/Windows.
|
|
|
|
|
TEST(CredentialsTest, |
|
|
|
|
TlsChannelCredentialsWithStaticDataCertificateProviderLoadingRootOnly) { |
|
|
|
|
auto certificate_provider = |
|
|
|
@ -448,8 +459,8 @@ TEST(CredentialsTest, |
|
|
|
|
test_server_authorization_check); |
|
|
|
|
GPR_ASSERT(certificate_provider != nullptr); |
|
|
|
|
GPR_ASSERT(certificate_provider->c_provider() != nullptr); |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options( |
|
|
|
|
certificate_provider); |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options; |
|
|
|
|
options.set_certificate_provider(certificate_provider); |
|
|
|
|
options.watch_root_certs(); |
|
|
|
|
options.set_root_cert_name(kRootCertName); |
|
|
|
|
options.set_server_verification_option(GRPC_TLS_SERVER_VERIFICATION); |
|
|
|
@ -459,13 +470,39 @@ TEST(CredentialsTest, |
|
|
|
|
GPR_ASSERT(channel_credentials.get() != nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST( |
|
|
|
|
CredentialsTest, |
|
|
|
|
TlsChannelCredentialsWithDefaultRootsAndStaticDataCertificateProviderLoadingIdentityOnly) { |
|
|
|
|
experimental::IdentityKeyCertPair key_cert_pair; |
|
|
|
|
key_cert_pair.private_key = kIdentityCertPrivateKey; |
|
|
|
|
key_cert_pair.certificate_chain = kIdentityCertContents; |
|
|
|
|
std::vector<experimental::IdentityKeyCertPair> identity_key_cert_pairs; |
|
|
|
|
identity_key_cert_pairs.emplace_back(key_cert_pair); |
|
|
|
|
auto certificate_provider = |
|
|
|
|
std::make_shared<StaticDataCertificateProvider>(identity_key_cert_pairs); |
|
|
|
|
auto test_server_authorization_check = |
|
|
|
|
std::make_shared<TestTlsServerAuthorizationCheck>(); |
|
|
|
|
auto server_authorization_check_config = |
|
|
|
|
std::make_shared<TlsServerAuthorizationCheckConfig>( |
|
|
|
|
test_server_authorization_check); |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options; |
|
|
|
|
options.set_certificate_provider(certificate_provider); |
|
|
|
|
options.watch_identity_key_cert_pairs(); |
|
|
|
|
options.set_identity_cert_name(kIdentityCertName); |
|
|
|
|
options.set_server_verification_option(GRPC_TLS_SERVER_VERIFICATION); |
|
|
|
|
options.set_server_authorization_check_config( |
|
|
|
|
server_authorization_check_config); |
|
|
|
|
auto channel_credentials = grpc::experimental::TlsCredentials(options); |
|
|
|
|
GPR_ASSERT(channel_credentials.get() != nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST( |
|
|
|
|
CredentialsTest, |
|
|
|
|
TlsChannelCredentialsWithFileWatcherCertificateProviderLoadingRootAndIdentity) { |
|
|
|
|
auto certificate_provider = std::make_shared<FileWatcherCertificateProvider>( |
|
|
|
|
SERVER_KEY_PATH, SERVER_CERT_PATH, CA_CERT_PATH, 1); |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options( |
|
|
|
|
certificate_provider); |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options; |
|
|
|
|
options.set_certificate_provider(certificate_provider); |
|
|
|
|
options.watch_root_certs(); |
|
|
|
|
options.set_root_cert_name(kRootCertName); |
|
|
|
|
options.watch_identity_key_cert_pairs(); |
|
|
|
@ -482,15 +519,12 @@ TEST( |
|
|
|
|
GPR_ASSERT(channel_credentials.get() != nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ChannelCredentials should always have root credential presented.
|
|
|
|
|
// Otherwise the system root certificates will be loaded, which will cause
|
|
|
|
|
// failure in some tests under MacOS/Windows.
|
|
|
|
|
TEST(CredentialsTest, |
|
|
|
|
TlsChannelCredentialsWithFileWatcherCertificateProviderLoadingRootOnly) { |
|
|
|
|
auto certificate_provider = |
|
|
|
|
std::make_shared<FileWatcherCertificateProvider>(CA_CERT_PATH, 1); |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options( |
|
|
|
|
certificate_provider); |
|
|
|
|
grpc::experimental::TlsChannelCredentialsOptions options; |
|
|
|
|
options.set_certificate_provider(certificate_provider); |
|
|
|
|
options.watch_root_certs(); |
|
|
|
|
options.set_root_cert_name(kRootCertName); |
|
|
|
|
options.set_server_verification_option(GRPC_TLS_SERVER_VERIFICATION); |
|
|
|
|