@@ -64,6 +64,7 @@ func TestGetIDToken(t *testing.T) {
64
64
Repository : & protocol.Repository {
65
65
CloneURL : "https://github.com/gitpod-io/gitpod.git" ,
66
66
},
67
+ NormalizedContextURL : "https://github.com/gitpod-io/gitpod" ,
67
68
},
68
69
},
69
70
},
@@ -112,6 +113,7 @@ func TestGetIDToken(t *testing.T) {
112
113
Repository : & protocol.Repository {
113
114
CloneURL : "https://github.com/gitpod-io/gitpod.git" ,
114
115
},
116
+ NormalizedContextURL : "https://github.com/gitpod-io/gitpod" ,
115
117
},
116
118
},
117
119
},
@@ -174,6 +176,9 @@ func TestGetIDToken(t *testing.T) {
174
176
& protocol.WorkspaceInfo {
175
177
Workspace : & protocol.Workspace {
176
178
ContextURL : "https://github.com/gitpod-io/gitpod" ,
179
+ Context : & protocol.WorkspaceContext {
180
+ NormalizedContextURL : "https://github.com/gitpod-io/gitpod" ,
181
+ },
177
182
},
178
183
},
179
184
nil ,
@@ -226,6 +231,7 @@ func TestGetIDToken(t *testing.T) {
226
231
Repository : & protocol.Repository {
227
232
CloneURL : "https://github.com/gitpod-io/gitpod.git" ,
228
233
},
234
+ NormalizedContextURL : "https://github.com/gitpod-io/gitpod" ,
229
235
},
230
236
},
231
237
},
@@ -268,6 +274,9 @@ func TestGetIDToken(t *testing.T) {
268
274
& protocol.WorkspaceInfo {
269
275
Workspace : & protocol.Workspace {
270
276
ContextURL : "https://github.com/gitpod-io/gitpod" ,
277
+ Context : & protocol.WorkspaceContext {
278
+ NormalizedContextURL : "https://github.com/gitpod-io/gitpod" ,
279
+ },
271
280
},
272
281
},
273
282
nil ,
@@ -344,36 +353,64 @@ func (f functionIDTokenSource) IDToken(ctx context.Context, org string, audience
344
353
}
345
354
346
355
func TestGetOIDCSubject (t * testing.T ) {
347
- contextUrl := "https://github.com/gitpod-io/gitpod"
356
+ normalizedContextUrl := "https://github.com/gitpod-io/gitpod"
357
+ defaultWorkspace := & protocol.Workspace {
358
+ ContextURL : "SOME_ENV=test/" + normalizedContextUrl ,
359
+ Context : & protocol.WorkspaceContext {
360
+ NormalizedContextURL : normalizedContextUrl ,
361
+ }}
348
362
tests := []struct {
349
- Name string
350
- Keys string
351
- Claims map [string ]interface {}
352
- Subject string
363
+ Name string
364
+ Keys string
365
+ Claims map [string ]interface {}
366
+ Subject string
367
+ Workspace * protocol.Workspace
353
368
}{
354
369
{
355
- Name : "happy path" ,
356
- Keys : "" ,
357
- Claims : map [string ]interface {}{},
358
- Subject : contextUrl ,
370
+ Name : "happy path" ,
371
+ Keys : "" ,
372
+ Claims : map [string ]interface {}{},
373
+ Subject : normalizedContextUrl ,
374
+ Workspace : defaultWorkspace ,
359
375
},
360
376
{
361
- Name : "happy path 2" ,
362
- Keys : "undefined" ,
363
- Claims : map [string ]interface {}{},
364
- Subject : contextUrl ,
377
+ Name : "happy path 2" ,
378
+ Keys : "undefined" ,
379
+ Claims : map [string ]interface {}{},
380
+ Subject : normalizedContextUrl ,
381
+ Workspace : defaultWorkspace ,
365
382
},
366
383
{
367
- Name : "with custom keys" ,
368
- Keys : "key1,key3,key2" ,
369
- Claims : map [string ]interface {}{"key1" : 1 , "key2" : "hello" },
370
- Subject : "key1:1:key3::key2:hello" ,
384
+ Name : "with custom keys" ,
385
+ Keys : "key1,key3,key2" ,
386
+ Claims : map [string ]interface {}{"key1" : 1 , "key2" : "hello" },
387
+ Subject : "key1:1:key3::key2:hello" ,
388
+ Workspace : defaultWorkspace ,
371
389
},
372
390
{
373
- Name : "with custom keys" ,
374
- Keys : "key1,key3,key2" ,
375
- Claims : map [string ]interface {}{"key1" : 1 , "key3" : errors .New ("test" )},
376
- Subject : "key1:1:key3:test:key2:" ,
391
+ Name : "with custom keys" ,
392
+ Keys : "key1,key3,key2" ,
393
+ Claims : map [string ]interface {}{"key1" : 1 , "key3" : errors .New ("test" )},
394
+ Subject : "key1:1:key3:test:key2:" ,
395
+ Workspace : defaultWorkspace ,
396
+ },
397
+ {
398
+ Name : "happy path with strange prefix" ,
399
+ Keys : "" ,
400
+ Claims : map [string ]interface {}{},
401
+ Subject : normalizedContextUrl ,
402
+ Workspace : & protocol.Workspace {ContextURL : "referrer:jetbrains-gateway:intellij/" + normalizedContextUrl , Context : & protocol.WorkspaceContext {
403
+ NormalizedContextURL : normalizedContextUrl ,
404
+ }},
405
+ },
406
+ {
407
+ Name : "happy path without NormalizedContextURL" ,
408
+ Keys : "" ,
409
+ Claims : map [string ]interface {}{},
410
+ Subject : "no-context" ,
411
+ Workspace : & protocol.Workspace {ContextURL : "referrer:jetbrains-gateway:intellij/" + normalizedContextUrl , Context : & protocol.WorkspaceContext {
412
+ NormalizedContextURL : "" ,
413
+ }},
377
414
},
378
415
}
379
416
@@ -389,7 +426,7 @@ func TestGetOIDCSubject(t *testing.T) {
389
426
userinfo .AppendClaims (k , v )
390
427
}
391
428
act := svc .getOIDCSubject (context .Background (), userinfo , & protocol.User {}, & protocol.WorkspaceInfo {
392
- Workspace : & protocol .Workspace { ContextURL : contextUrl } ,
429
+ Workspace : test .Workspace ,
393
430
})
394
431
if diff := cmp .Diff (test .Subject , act ); diff != "" {
395
432
t .Errorf ("getOIDCSubject() mismatch (-want +got):\n %s" , diff )
0 commit comments