@@ -9,7 +9,20 @@ import (
9
9
"testing"
10
10
)
11
11
12
- var jwtJSONKeyUniverseDomain = []byte (`{
12
+ var saJSONJWT = []byte (`{
13
+ "type": "service_account",
14
+ "project_id": "fake_project",
15
+ "private_key_id": "268f54e43a1af97cfc71731688434f45aca15c8b",
16
+ "private_key": "super secret key",
17
+ "client_email": "[email protected] ",
18
+ "client_id": "gopher.apps.googleusercontent.com",
19
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
20
+ "token_uri": "https://oauth2.googleapis.com/token",
21
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
22
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gopher%40fake_project.iam.gserviceaccount.com"
23
+ }` )
24
+
25
+ var saJSONJWTUniverseDomain = []byte (`{
13
26
"type": "service_account",
14
27
"project_id": "fake_project",
15
28
"universe_domain": "example.com",
@@ -23,13 +36,49 @@ var jwtJSONKeyUniverseDomain = []byte(`{
23
36
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gopher%40fake_project.iam.gserviceaccount.com"
24
37
}` )
25
38
26
- func TestCredentialsFromJSONWithParams_UniverseDomain (t * testing.T ) {
39
+ var userJSON = []byte (`{
40
+ "client_id": "abc123.apps.googleusercontent.com",
41
+ "client_secret": "shh",
42
+ "refresh_token": "refreshing",
43
+ "type": "authorized_user",
44
+ "quota_project_id": "fake_project2"
45
+ }` )
46
+
47
+ var userJSONUniverseDomain = []byte (`{
48
+ "client_id": "abc123.apps.googleusercontent.com",
49
+ "client_secret": "shh",
50
+ "refresh_token": "refreshing",
51
+ "type": "authorized_user",
52
+ "quota_project_id": "fake_project2",
53
+ "universe_domain": "example.com"
54
+ }` )
55
+
56
+ func TestCredentialsFromJSONWithParams_SA (t * testing.T ) {
57
+ ctx := context .Background ()
58
+ scope := "https://www.googleapis.com/auth/cloud-platform"
59
+ params := CredentialsParams {
60
+ Scopes : []string {scope },
61
+ }
62
+ creds , err := CredentialsFromJSONWithParams (ctx , saJSONJWT , params )
63
+ if err != nil {
64
+ t .Fatal (err )
65
+ }
66
+
67
+ if want := "fake_project" ; creds .ProjectID != want {
68
+ t .Fatalf ("got %q, want %q" , creds .ProjectID , want )
69
+ }
70
+ if want := "googleapis.com" ; creds .UniverseDomain () != want {
71
+ t .Fatalf ("got %q, want %q" , creds .UniverseDomain (), want )
72
+ }
73
+ }
74
+
75
+ func TestCredentialsFromJSONWithParams_SA_UniverseDomain (t * testing.T ) {
27
76
ctx := context .Background ()
28
77
scope := "https://www.googleapis.com/auth/cloud-platform"
29
78
params := CredentialsParams {
30
79
Scopes : []string {scope },
31
80
}
32
- creds , err := CredentialsFromJSONWithParams (ctx , jwtJSONKeyUniverseDomain , params )
81
+ creds , err := CredentialsFromJSONWithParams (ctx , saJSONJWTUniverseDomain , params )
33
82
if err != nil {
34
83
t .Fatal (err )
35
84
}
@@ -41,3 +90,35 @@ func TestCredentialsFromJSONWithParams_UniverseDomain(t *testing.T) {
41
90
t .Fatalf ("got %q, want %q" , creds .UniverseDomain (), want )
42
91
}
43
92
}
93
+
94
+ func TestCredentialsFromJSONWithParams_User (t * testing.T ) {
95
+ ctx := context .Background ()
96
+ scope := "https://www.googleapis.com/auth/cloud-platform"
97
+ params := CredentialsParams {
98
+ Scopes : []string {scope },
99
+ }
100
+ creds , err := CredentialsFromJSONWithParams (ctx , userJSON , params )
101
+ if err != nil {
102
+ t .Fatal (err )
103
+ }
104
+
105
+ if want := "googleapis.com" ; creds .UniverseDomain () != want {
106
+ t .Fatalf ("got %q, want %q" , creds .UniverseDomain (), want )
107
+ }
108
+ }
109
+
110
+ func TestCredentialsFromJSONWithParams_User_UniverseDomain (t * testing.T ) {
111
+ ctx := context .Background ()
112
+ scope := "https://www.googleapis.com/auth/cloud-platform"
113
+ params := CredentialsParams {
114
+ Scopes : []string {scope },
115
+ }
116
+ creds , err := CredentialsFromJSONWithParams (ctx , userJSONUniverseDomain , params )
117
+ if err != nil {
118
+ t .Fatal (err )
119
+ }
120
+
121
+ if want := "googleapis.com" ; creds .UniverseDomain () != want {
122
+ t .Fatalf ("got %q, want %q" , creds .UniverseDomain (), want )
123
+ }
124
+ }
0 commit comments