Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
64d7c246
Commit
64d7c246
authored
9 years ago
by
Jan Tattermusch
Browse files
Options
Downloads
Patches
Plain Diff
make C# auth interop tests up to spec
parent
b58de50f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+22
-9
22 additions, 9 deletions
src/csharp/Grpc.IntegrationTesting/InteropClient.cs
tools/run_tests/run_interop_tests.py
+4
-0
4 additions, 0 deletions
tools/run_tests/run_interop_tests.py
with
26 additions
and
9 deletions
src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+
22
−
9
View file @
64d7c246
...
...
@@ -46,6 +46,7 @@ using Grpc.Auth;
using
Grpc.Core
;
using
Grpc.Core.Utils
;
using
Grpc.Testing
;
using
Newtonsoft.Json.Linq
;
using
NUnit.Framework
;
namespace
Grpc.IntegrationTesting
...
...
@@ -180,13 +181,13 @@ namespace Grpc.IntegrationTesting
RunComputeEngineCreds
(
client
,
options
.
DefaultServiceAccount
,
options
.
OAuthScope
);
break
;
case
"jwt_token_creds"
:
RunJwtTokenCreds
(
client
,
options
.
DefaultServiceAccount
);
RunJwtTokenCreds
(
client
);
break
;
case
"oauth2_auth_token"
:
await
RunOAuth2AuthTokenAsync
(
client
,
options
.
DefaultServiceAccount
,
options
.
OAuthScope
);
await
RunOAuth2AuthTokenAsync
(
client
,
options
.
OAuthScope
);
break
;
case
"per_rpc_creds"
:
await
RunPerRpcCredsAsync
(
client
,
options
.
DefaultServiceAccount
,
options
.
OAuthScope
);
await
RunPerRpcCredsAsync
(
client
,
options
.
OAuthScope
);
break
;
case
"cancel_after_begin"
:
await
RunCancelAfterBeginAsync
(
client
);
...
...
@@ -364,7 +365,7 @@ namespace Grpc.IntegrationTesting
Console
.
WriteLine
(
"Passed!"
);
}
public
static
void
RunJwtTokenCreds
(
TestService
.
TestServiceClient
client
,
string
defaultServiceAccount
)
public
static
void
RunJwtTokenCreds
(
TestService
.
TestServiceClient
client
)
{
Console
.
WriteLine
(
"running jwt_token_creds"
);
...
...
@@ -381,11 +382,11 @@ namespace Grpc.IntegrationTesting
Assert
.
AreEqual
(
PayloadType
.
COMPRESSABLE
,
response
.
Payload
.
Type
);
Assert
.
AreEqual
(
314159
,
response
.
Payload
.
Body
.
Length
);
Assert
.
AreEqual
(
default
ServiceAccount
,
response
.
Username
);
Assert
.
AreEqual
(
GetEmailFrom
ServiceAccount
File
()
,
response
.
Username
);
Console
.
WriteLine
(
"Passed!"
);
}
public
static
async
Task
RunOAuth2AuthTokenAsync
(
TestService
.
TestServiceClient
client
,
string
defaultServiceAccount
,
string
oauthScope
)
public
static
async
Task
RunOAuth2AuthTokenAsync
(
TestService
.
TestServiceClient
client
,
string
oauthScope
)
{
Console
.
WriteLine
(
"running oauth2_auth_token"
);
ITokenAccess
credential
=
(
await
GoogleCredential
.
GetApplicationDefaultAsync
()).
CreateScoped
(
new
[]
{
oauthScope
});
...
...
@@ -402,11 +403,11 @@ namespace Grpc.IntegrationTesting
Assert
.
False
(
string
.
IsNullOrEmpty
(
response
.
OauthScope
));
Assert
.
True
(
oauthScope
.
Contains
(
response
.
OauthScope
));
Assert
.
AreEqual
(
default
ServiceAccount
,
response
.
Username
);
Assert
.
AreEqual
(
GetEmailFrom
ServiceAccount
File
()
,
response
.
Username
);
Console
.
WriteLine
(
"Passed!"
);
}
public
static
async
Task
RunPerRpcCredsAsync
(
TestService
.
TestServiceClient
client
,
string
defaultServiceAccount
,
string
oauthScope
)
public
static
async
Task
RunPerRpcCredsAsync
(
TestService
.
TestServiceClient
client
,
string
oauthScope
)
{
Console
.
WriteLine
(
"running per_rpc_creds"
);
ITokenAccess
googleCredential
=
(
await
GoogleCredential
.
GetApplicationDefaultAsync
()).
CreateScoped
(
new
[]
{
oauthScope
});
...
...
@@ -419,7 +420,7 @@ namespace Grpc.IntegrationTesting
var
response
=
client
.
UnaryCall
(
request
,
new
CallOptions
(
credentials
:
credentials
));
Assert
.
AreEqual
(
default
ServiceAccount
,
response
.
Username
);
Assert
.
AreEqual
(
GetEmailFrom
ServiceAccount
File
()
,
response
.
Username
);
Console
.
WriteLine
(
"Passed!"
);
}
...
...
@@ -499,5 +500,17 @@ namespace Grpc.IntegrationTesting
{
return
new
Payload
{
Body
=
ByteString
.
CopyFrom
(
new
byte
[
size
])
};
}
// extracts the client_email field from service account file used for auth test cases
private
static
string
GetEmailFromServiceAccountFile
()
{
string
keyFile
=
Environment
.
GetEnvironmentVariable
(
"GOOGLE_APPLICATION_CREDENTIALS"
);
Assert
.
IsNotNull
(
keyFile
);
var
jobject
=
JObject
.
Parse
(
File
.
ReadAllText
(
keyFile
));
string
email
=
jobject
.
GetValue
(
"client_email"
).
Value
<
string
>();
Assert
.
IsTrue
(
email
.
Length
>
0
);
// spec requires nonempty client email.
return
email
;
}
}
}
This diff is collapsed.
Click to expand it.
tools/run_tests/run_interop_tests.py
+
4
−
0
View file @
64d7c246
...
...
@@ -312,6 +312,10 @@ def add_auth_options(language, test_case, cmdline, env):
if
test_case
in
[
'
per_rpc_creds
'
,
'
oauth2_auth_token
'
]:
cmdline
+=
[
oauth_scope_arg
]
if
test_case
==
'
oauth2_auth_token
'
and
language
==
'
c++
'
:
# C++ oauth2 test uses GCE creds and thus needs to know the default account
cmdline
+=
[
default_account_arg
]
if
test_case
==
'
compute_engine_creds
'
:
cmdline
+=
[
oauth_scope_arg
,
default_account_arg
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment