aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/end2end/end2end_test.cc91
-rw-r--r--test/cpp/interop/client.cc6
-rw-r--r--test/cpp/interop/interop_client.cc16
-rw-r--r--test/cpp/interop/interop_client.h1
4 files changed, 104 insertions, 10 deletions
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 111a1a4f2f..b3cfcd51a7 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -108,6 +108,39 @@ bool CheckIsLocalhost(const grpc::string& addr) {
addr.substr(0, kIpv6.size()) == kIpv6;
}
+class TestMetadataCredentialsPlugin : public MetadataCredentialsPlugin {
+ public:
+ static const char kMetadataKey[];
+
+ TestMetadataCredentialsPlugin(grpc::string_ref metadata_value,
+ bool is_blocking, bool is_successful)
+ : metadata_value_(metadata_value.data(), metadata_value.length()),
+ is_blocking_(is_blocking),
+ is_successful_(is_successful) {}
+
+ bool IsBlocking() const GRPC_OVERRIDE { return is_blocking_; }
+
+ Status GetMetadata(grpc::string_ref service_url,
+ std::multimap<grpc::string, grpc::string_ref>* metadata)
+ GRPC_OVERRIDE {
+ EXPECT_GT(service_url.length(), 0UL);
+ EXPECT_TRUE(metadata != nullptr);
+ if (is_successful_) {
+ metadata->insert(std::make_pair(kMetadataKey, metadata_value_));
+ return Status::OK;
+ } else {
+ return Status(StatusCode::NOT_FOUND, "Could not find plugin metadata.");
+ }
+ }
+
+ private:
+ grpc::string metadata_value_;
+ bool is_blocking_;
+ bool is_successful_;
+};
+
+const char TestMetadataCredentialsPlugin::kMetadataKey[] = "TestPluginMetadata";
+
class TestAuthMetadataProcessor : public AuthMetadataProcessor {
public:
static const char kGoodGuy[];
@@ -115,10 +148,15 @@ class TestAuthMetadataProcessor : public AuthMetadataProcessor {
TestAuthMetadataProcessor(bool is_blocking) : is_blocking_(is_blocking) {}
std::shared_ptr<Credentials> GetCompatibleClientCreds() {
- return AccessTokenCredentials(kGoodGuy);
+ return MetadataCredentialsFromPlugin(
+ std::unique_ptr<MetadataCredentialsPlugin>(
+ new TestMetadataCredentialsPlugin(kGoodGuy, is_blocking_, true)));
}
+
std::shared_ptr<Credentials> GetIncompatibleClientCreds() {
- return AccessTokenCredentials("Mr Hyde");
+ return MetadataCredentialsFromPlugin(
+ std::unique_ptr<MetadataCredentialsPlugin>(
+ new TestMetadataCredentialsPlugin("Mr Hyde", is_blocking_, true)));
}
// Interface implementation
@@ -130,10 +168,11 @@ class TestAuthMetadataProcessor : public AuthMetadataProcessor {
EXPECT_TRUE(consumed_auth_metadata != nullptr);
EXPECT_TRUE(context != nullptr);
EXPECT_TRUE(response_metadata != nullptr);
- auto auth_md = auth_metadata.find(GRPC_AUTHORIZATION_METADATA_KEY);
+ auto auth_md =
+ auth_metadata.find(TestMetadataCredentialsPlugin::kMetadataKey);
EXPECT_NE(auth_md, auth_metadata.end());
string_ref auth_md_value = auth_md->second;
- if (auth_md_value.ends_with(kGoodGuy)) {
+ if (auth_md_value == kGoodGuy) {
context->AddProperty(kIdentityPropName, kGoodGuy);
context->SetPeerIdentityPropertyName(kIdentityPropName);
consumed_auth_metadata->insert(
@@ -147,7 +186,7 @@ class TestAuthMetadataProcessor : public AuthMetadataProcessor {
}
}
- protected:
+ private:
static const char kIdentityPropName[];
bool is_blocking_;
};
@@ -876,7 +915,24 @@ TEST_F(End2endTest, OverridePerCallCredentials) {
EXPECT_TRUE(s.ok());
}
-TEST_F(End2endTest, NonBlockingAuthMetadataProcessorSuccess) {
+TEST_F(End2endTest, NonBlockingAuthMetadataPluginFailure) {
+ ResetStub(false);
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ context.set_credentials(
+ MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>(
+ new TestMetadataCredentialsPlugin(
+ "Does not matter, will fail anyway (see 3rd param)", false,
+ false))));
+ request.set_message("Hello");
+
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_FALSE(s.ok());
+ EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED);
+}
+
+TEST_F(End2endTest, NonBlockingAuthMetadataPluginAndProcessorSuccess) {
auto* processor = new TestAuthMetadataProcessor(false);
StartServer(std::shared_ptr<AuthMetadataProcessor>(processor));
ResetStub(false);
@@ -899,7 +955,7 @@ TEST_F(End2endTest, NonBlockingAuthMetadataProcessorSuccess) {
grpc::string("Bearer ") + TestAuthMetadataProcessor::kGoodGuy));
}
-TEST_F(End2endTest, NonBlockingAuthMetadataProcessorFailure) {
+TEST_F(End2endTest, NonBlockingAuthMetadataPluginAndProcessorFailure) {
auto* processor = new TestAuthMetadataProcessor(false);
StartServer(std::shared_ptr<AuthMetadataProcessor>(processor));
ResetStub(false);
@@ -914,7 +970,24 @@ TEST_F(End2endTest, NonBlockingAuthMetadataProcessorFailure) {
EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED);
}
-TEST_F(End2endTest, BlockingAuthMetadataProcessorSuccess) {
+TEST_F(End2endTest, BlockingAuthMetadataPluginFailure) {
+ ResetStub(false);
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ context.set_credentials(
+ MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>(
+ new TestMetadataCredentialsPlugin(
+ "Does not matter, will fail anyway (see 3rd param)", true,
+ false))));
+ request.set_message("Hello");
+
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_FALSE(s.ok());
+ EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED);
+}
+
+TEST_F(End2endTest, BlockingAuthMetadataPluginAndProcessorSuccess) {
auto* processor = new TestAuthMetadataProcessor(true);
StartServer(std::shared_ptr<AuthMetadataProcessor>(processor));
ResetStub(false);
@@ -937,7 +1010,7 @@ TEST_F(End2endTest, BlockingAuthMetadataProcessorSuccess) {
grpc::string("Bearer ") + TestAuthMetadataProcessor::kGoodGuy));
}
-TEST_F(End2endTest, BlockingAuthMetadataProcessorFailure) {
+TEST_F(End2endTest, BlockingAuthMetadataPluginAndProcessorFailure) {
auto* processor = new TestAuthMetadataProcessor(true);
StartServer(std::shared_ptr<AuthMetadataProcessor>(processor));
ResetStub(false);
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc
index ba44a918db..58c71cca35 100644
--- a/test/cpp/interop/client.cc
+++ b/test/cpp/interop/client.cc
@@ -68,6 +68,7 @@ DEFINE_string(test_case, "large_unary",
"cancel_after_begin : cancel stream after starting it; "
"cancel_after_first_response: cancel on first response; "
"timeout_on_sleeping_server: deadline exceeds on stream; "
+ "empty_stream : bi-di stream with no request/response; "
"compute_engine_creds: large_unary with compute engine auth; "
"jwt_token_creds: large_unary with JWT token auth; "
"oauth2_auth_token: raw oauth2 access token auth; "
@@ -113,6 +114,8 @@ int main(int argc, char** argv) {
client.DoCancelAfterFirstResponse();
} else if (FLAGS_test_case == "timeout_on_sleeping_server") {
client.DoTimeoutOnSleepingServer();
+ } else if (FLAGS_test_case == "empty_stream") {
+ client.DoEmptyStream();
} else if (FLAGS_test_case == "compute_engine_creds") {
client.DoComputeEngineCreds(FLAGS_default_service_account,
FLAGS_oauth_scope);
@@ -137,6 +140,7 @@ int main(int argc, char** argv) {
client.DoCancelAfterBegin();
client.DoCancelAfterFirstResponse();
client.DoTimeoutOnSleepingServer();
+ client.DoEmptyStream();
client.DoStatusWithMessage();
// service_account_creds and jwt_token_creds can only run with ssl.
if (FLAGS_enable_ssl) {
@@ -153,7 +157,7 @@ int main(int argc, char** argv) {
"Unsupported test case %s. Valid options are all|empty_unary|"
"large_unary|large_compressed_unary|client_streaming|server_streaming|"
"server_compressed_streaming|half_duplex|ping_pong|cancel_after_begin|"
- "cancel_after_first_response|timeout_on_sleeping_server|"
+ "cancel_after_first_response|timeout_on_sleeping_server|empty_stream|"
"compute_engine_creds|jwt_token_creds|oauth2_auth_token|per_rpc_creds",
FLAGS_test_case.c_str());
ret = 1;
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc
index 8124cae67a..02e10a50aa 100644
--- a/test/cpp/interop/interop_client.cc
+++ b/test/cpp/interop/interop_client.cc
@@ -554,6 +554,22 @@ void InteropClient::DoTimeoutOnSleepingServer() {
gpr_log(GPR_INFO, "Pingpong streaming timeout done.");
}
+void InteropClient::DoEmptyStream() {
+ gpr_log(GPR_INFO, "Starting empty_stream.");
+ std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_));
+
+ ClientContext context;
+ std::unique_ptr<ClientReaderWriter<StreamingOutputCallRequest,
+ StreamingOutputCallResponse>>
+ stream(stub->FullDuplexCall(&context));
+ stream->WritesDone();
+ StreamingOutputCallResponse response;
+ GPR_ASSERT(stream->Read(&response) == false);
+ Status s = stream->Finish();
+ AssertOkOrPrintErrorStatus(s);
+ gpr_log(GPR_INFO, "empty_stream done.");
+}
+
void InteropClient::DoStatusWithMessage() {
gpr_log(GPR_INFO, "Sending RPC with a request for status code 2 and message");
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_));
diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h
index 7bcb58571e..ebecd68c3f 100644
--- a/test/cpp/interop/interop_client.h
+++ b/test/cpp/interop/interop_client.h
@@ -62,6 +62,7 @@ class InteropClient {
void DoCancelAfterBegin();
void DoCancelAfterFirstResponse();
void DoTimeoutOnSleepingServer();
+ void DoEmptyStream();
void DoStatusWithMessage();
// Auth tests.
// username is a string containing the user email