Skip to content
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
5 changes: 5 additions & 0 deletions src/nginx/t/grpc_auth_pkey.t
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ plans {
request {
text: "Hello, world!"
}
expected_metadata_keys: ["x-endpoint-api-userinfo"]
}
}
EOF
Expand All @@ -157,6 +158,10 @@ results {
echo {
text: "Hello, world!"
}
additional_metadata {
key: "x-endpoint-api-userinfo"
value: "eyJpc3N1ZXIiOiI2Mjg2NDU3NDE4ODEtbm9hYml1MjNmNWE4bThvdmQ4dWN2Njk4bGo3OHZ2MGxAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJpZCI6IjYyODY0NTc0MTg4MS1ub2FiaXUyM2Y1YThtOG92ZDh1Y3Y2OThsajc4dnYwbEBkZXZlbG9wZXIuZ3NlcnZpY2VhY2NvdW50LmNvbSJ9"
}
}
EOF
is($test_results, $test_results_expected, 'Client tests completed as expected.');
Expand Down
43 changes: 42 additions & 1 deletion src/nginx/t/transcoding_metadata.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use warnings;
################################################################################

use src::nginx::t::ApiManager; # Must be first (sets up import path to the Nginx test module)
use src::nginx::t::Auth;
use src::nginx::t::HttpServer;
use src::nginx::t::ServiceControl;
use Test::Nginx; # Imports Nginx's test module
Expand All @@ -42,15 +43,30 @@ use JSON::PP;
my $NginxPort = ApiManager::pick_port();
my $ServiceControlPort = ApiManager::pick_port();
my $GrpcServerPort = ApiManager::pick_port();
my $PubkeyPort = ApiManager::pick_port();

my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(7);
my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(8);

$t->write_file('service.pb.txt',
ApiManager::get_grpc_test_service_config($GrpcServerPort) .
ApiManager::read_test_file('testdata/logs_metrics.pb.txt') . <<"EOF");
control {
environment: "http://127.0.0.1:${ServiceControlPort}"
}
authentication {
providers {
id: "test_auth"
issuer: "628645741881-noabiu23f5a8m8ovd8ucv698lj78vv0l\@developer.gserviceaccount.com"
jwks_uri: "http://127.0.0.1:${PubkeyPort}/pubkey"
}
rules {
selector: "test.grpc.Test.Echo"
requirements {
provider_id: "test_auth"
audiences: "ok_audience_1,ok_audience_2"
}
}
}
EOF

$t->write_file_expand('nginx.conf', <<EOF);
Expand All @@ -76,6 +92,10 @@ http {
}
EOF

my $pkey_jwk = Auth::get_public_key_jwk;
my $auth_token = Auth::get_auth_token('./src/nginx/t/matching-client-secret.json', 'ok_audience_1');

$t->run_daemon(\&pubkey, $t, $PubkeyPort, $pkey_jwk, 'pubkey.log');
$t->run_daemon(\&service_control, $t, $ServiceControlPort, 'servicecontrol.log');
$t->run_daemon(\&ApiManager::grpc_test_server, $t, "127.0.0.1:${GrpcServerPort}");

Expand All @@ -100,6 +120,7 @@ my $content_length = length($request);
my $response = ApiManager::http($NginxPort,<<EOF . $request);
POST /echo?key=api-key HTTP/1.0
Host: 127.0.0.1:${NginxPort}
Authorization: Bearer $auth_token
Content-Type: application/json
Content-Length: $content_length
client-text: text
Expand All @@ -112,9 +133,12 @@ $t->stop_daemons();
my ($headers, $actual_body) = split /\r\n\r\n/, $response, 2;

my $json_response = decode_json($actual_body);
my $expected_userinfo = "ZXlKcGMzTjFaWElpT2lJMk1qZzJORFUzTkRFNE9ERXRibTloWW1sMU1qTm1OV0U0YlRodmRtUTRkV04yTmprNGJHbzNPSFoyTUd4QVpHVjJaV3h2Y0dWeUxtZHpaWEoyYVdObFlXTmpiM1Z1ZEM1amIyMGlMQ0pwWkNJNklqWXlPRFkwTlRjME1UZzRNUzF1YjJGaWFYVXlNMlkxWVRodE9HOTJaRGgxWTNZMk9UaHNhamM0ZG5Zd2JFQmtaWFpsYkc5d1pYSXVaM05sY25acFkyVmhZMk52ZFc1MExtTnZiU0o5";

is('dGV4dA==', $json_response->{receivedMetadata}->{'client-text'}, "Received client-text metadata");
is('YmluYXJ5', $json_response->{receivedMetadata}->{'client-binary-bin'}, "Received client-binary metadata");
is($expected_userinfo, $json_response->{receivedMetadata}->{'x-endpoint-api-userinfo'}, "Received x-endpoint-api-userinfo");

like($headers, qr/initial-text: text/, "Server returns initial text metadata");
like($headers, qr/initial-binary-bin: YmluYXJ5/, "Server returns initial binary metadata");

Expand Down Expand Up @@ -143,3 +167,20 @@ EOF
}

################################################################################

sub pubkey {
my ($t, $port, $pkey, $file) = @_;
my $server = HttpServer->new($port, $t->testdir() . '/' . $file)
or die "Can't create test server socket: $!\n";
local $SIG{PIPE} = 'IGNORE';

$server->on('GET', '/pubkey', <<"EOF");
HTTP/1.1 200 OK
Connection: close

$pkey
EOF

$server->run();
}

7 changes: 7 additions & 0 deletions test/grpc/client-test-lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ class Echo {
result.mutable_echo()->set_verified_metadata(verified_metadata);
ok &= metadata_results->size() == 0;
}

for (auto key : echo->desc_.expected_metadata_keys()) {
auto it = echo->response_.received_metadata().find(key);
if (it != echo->response_.received_metadata().end()) {
(*(result.mutable_additional_metadata()))[key] = it->second;
}
}
done(ok, result);
}));
}
Expand Down
6 changes: 6 additions & 0 deletions test/grpc/grpc-test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ message EchoTest {

// The final RPC status to expect in the response.
CallStatus expected_status = 3;

// The expected metadata keys that the grpc server should receive.
repeated string expected_metadata_keys = 4;
}

message EchoResult {
Expand Down Expand Up @@ -355,6 +358,9 @@ message TestResult {
ProbeUpstreamMessageLimitResult probe_upstream_message_limit = 7;
EchoReportResult echo_report = 8;
}

// Additional metadata that can be added by ESP during the Check processing.
map<string, bytes> additional_metadata = 9;
}

// Test results.
Expand Down