Merge pull request #12574 from yang-g/comp_call

Add CompositeCallCredentials
pull/13037/head
Yang Gao 7 years ago committed by GitHub
commit 226e9060b9
  1. 12
      src/cpp/client/secure_credentials.cc
  2. 28
      test/cpp/end2end/end2end_test.cc

@ -150,6 +150,18 @@ std::shared_ptr<ChannelCredentials> CompositeChannelCredentials(
return nullptr;
}
std::shared_ptr<CallCredentials> CompositeCallCredentials(
const std::shared_ptr<CallCredentials>& creds1,
const std::shared_ptr<CallCredentials>& creds2) {
SecureCallCredentials* s_creds1 = creds1->AsSecureCredentials();
SecureCallCredentials* s_creds2 = creds2->AsSecureCredentials();
if (s_creds1 != nullptr && s_creds2 != nullptr) {
return WrapCallCredentials(grpc_composite_call_credentials_create(
s_creds1->GetRawCreds(), s_creds2->GetRawCreds(), nullptr));
}
return nullptr;
}
void MetadataCredentialsPluginWrapper::Destroy(void* wrapper) {
if (wrapper == nullptr) return;
MetadataCredentialsPluginWrapper* w =

@ -1673,6 +1673,34 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginFailure) {
kTestCredsPluginErrorMsg);
}
TEST_P(SecureEnd2endTest, CompositeCallCreds) {
ResetStub();
EchoRequest request;
EchoResponse response;
ClientContext context;
const char kMetadataKey1[] = "call-creds-key1";
const char kMetadataKey2[] = "call-creds-key2";
const char kMetadataVal1[] = "call-creds-val1";
const char kMetadataVal2[] = "call-creds-val2";
context.set_credentials(CompositeCallCredentials(
MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>(
new TestMetadataCredentialsPlugin(kMetadataKey1, kMetadataVal1, true,
true))),
MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>(
new TestMetadataCredentialsPlugin(kMetadataKey2, kMetadataVal2, true,
true)))));
request.set_message("Hello");
request.mutable_param()->set_echo_metadata(true);
Status s = stub_->Echo(&context, request, &response);
EXPECT_TRUE(s.ok());
EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
kMetadataKey1, kMetadataVal1));
EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
kMetadataKey2, kMetadataVal2));
}
TEST_P(SecureEnd2endTest, ClientAuthContext) {
ResetStub();
EchoRequest request;

Loading…
Cancel
Save