Skip to content
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

aws_iam: Increase code coverage for AWS IAM credential provider #12394

Merged
merged 3 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class GrpcAwsIamClientIntegrationTest : public GrpcSslClientIntegrationTest {
}

void expectExtraHeaders(FakeStream& fake_stream) override {
if (call_credentials_ != CallCredentials::FromPlugin) {
return;
}
AssertionResult result = fake_stream.waitForHeadersComplete();
RELEASE_ASSERT(result, result.message());
Http::TestRequestHeaderMapImpl stream_headers(fake_stream.headers());
Expand All @@ -57,41 +60,55 @@ class GrpcAwsIamClientIntegrationTest : public GrpcSslClientIntegrationTest {
ssl_creds->mutable_root_certs()->set_filename(
TestEnvironment::runfilesPath("test/config/integration/certs/upstreamcacert.pem"));

std::string config_yaml;
switch (region_location_) {
case RegionLocation::InEnvironment:
TestEnvironment::setEnvVar("AWS_REGION", region_name_, 1);
ABSL_FALLTHROUGH_INTENDED;
case RegionLocation::NotProvided:
config_yaml = fmt::format(R"EOF(
"@type": type.googleapis.com/envoy.config.grpc_credential.v2alpha.AwsIamConfig
service_name: {}
)EOF",
service_name_);
break;
case RegionLocation::InConfig:
config_yaml = fmt::format(R"EOF(
"@type": type.googleapis.com/envoy.config.grpc_credential.v2alpha.AwsIamConfig
service_name: {}
region: {}
)EOF",
service_name_, region_name_);
break;
switch (call_credentials_) {
case CallCredentials::FromPlugin: {
std::string config_yaml;
switch (region_location_) {
case RegionLocation::InEnvironment:
TestEnvironment::setEnvVar("AWS_REGION", region_name_, 1);
ABSL_FALLTHROUGH_INTENDED;
case RegionLocation::NotProvided:
config_yaml = fmt::format(R"EOF(
"@type": type.googleapis.com/envoy.config.grpc_credential.v2alpha.AwsIamConfig
service_name: {}
)EOF",
service_name_);
break;
case RegionLocation::InConfig:
config_yaml = fmt::format(R"EOF(
"@type": type.googleapis.com/envoy.config.grpc_credential.v2alpha.AwsIamConfig
service_name: {}
region: {}
)EOF",
service_name_, region_name_);
break;
}

auto* plugin_config = google_grpc->add_call_credentials()->mutable_from_plugin();
plugin_config->set_name(credentials_factory_name_);
Envoy::TestUtility::loadFromYaml(config_yaml, *plugin_config->mutable_typed_config());
return config;
}
case CallCredentials::AccessToken:
google_grpc->add_call_credentials()->mutable_access_token()->assign("foo");
return config;
default:
return config;
}

auto* plugin_config = google_grpc->add_call_credentials()->mutable_from_plugin();
plugin_config->set_name(credentials_factory_name_);
Envoy::TestUtility::loadFromYaml(config_yaml, *plugin_config->mutable_typed_config());
return config;
}

enum class RegionLocation {
NotProvided,
InEnvironment,
InConfig,
};

enum class CallCredentials {
FromPlugin,
AccessToken,
};

RegionLocation region_location_ = RegionLocation::NotProvided;
CallCredentials call_credentials_ = CallCredentials::FromPlugin;
std::string service_name_{};
std::string region_name_{};
std::string credentials_factory_name_{};
Expand Down Expand Up @@ -133,6 +150,16 @@ TEST_P(GrpcAwsIamClientIntegrationTest, AwsIamGrpcAuth_NoRegion) {
EXPECT_THROW_WITH_REGEX(initialize();, EnvoyException, "AWS region");
}

TEST_P(GrpcAwsIamClientIntegrationTest, AwsIamGrpcAuth_UnexpectedCallCredentials) {
SKIP_IF_GRPC_CLIENT(ClientType::EnvoyGrpc);
call_credentials_ = CallCredentials::AccessToken;
credentials_factory_name_ = Extensions::GrpcCredentials::GrpcCredentialsNames::get().AwsIam;
initialize();
auto request = createRequest(empty_metadata_);
request->sendReply();
dispatcher_helper_.runDispatcher();
}

} // namespace
} // namespace Grpc
} // namespace Envoy
1 change: 0 additions & 1 deletion test/per_file_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ declare -a KNOWN_LOW_COVERAGE=(
"source/extensions/filters/common/fault:95.8"
"source/extensions/filters/common/lua:95.9"
"source/extensions/grpc_credentials:92.0"
"source/extensions/grpc_credentials/aws_iam:86.8"
"source/extensions/health_checkers:95.9"
"source/extensions/health_checkers/redis:95.9"
"source/extensions/quic_listeners:84.8"
Expand Down