@@ -25,10 +25,12 @@ function getUserMock(user) {
25
25
const result = {
26
26
update : sinon . stub ( ) ,
27
27
sealToken : sinon . stub ( ) ,
28
+ unsealToken : sinon . stub ( ) . returns ( 'token' ) ,
28
29
getDisplayName : sinon . stub ( ) ,
29
30
id : user . id ,
30
31
username : user . username ,
31
- token : user . token
32
+ token : user . token ,
33
+ scmContext : user . scmContext
32
34
} ;
33
35
34
36
return result ;
@@ -93,7 +95,8 @@ describe('auth plugin test', () => {
93
95
scope : [ 'admin:repo_hook' , 'read:org' , 'repo:status' ]
94
96
}
95
97
} ,
96
- autoDeployKeyGenerationEnabled : sinon . stub ( ) . returns ( true )
98
+ autoDeployKeyGenerationEnabled : sinon . stub ( ) . returns ( true ) ,
99
+ decorateAuthor : sinon . stub ( )
97
100
} ;
98
101
userFactoryMock = {
99
102
get : sinon . stub ( ) ,
@@ -335,6 +338,7 @@ describe('auth plugin test', () => {
335
338
} ) ;
336
339
337
340
expect ( profile . username ) . to . contain ( 'batman' ) ;
341
+ expect ( profile . scmUserId ) . to . equal ( 1312 ) ;
338
342
expect ( profile . scmContext ) . to . contain ( 'github:github.com' ) ;
339
343
expect ( profile . scope ) . to . contain ( 'user' ) ;
340
344
expect ( profile . scope ) . to . contain ( 'admin' ) ;
@@ -344,12 +348,14 @@ describe('auth plugin test', () => {
344
348
it ( 'does not add admin scope for non-admins' , ( ) => {
345
349
const profile = server . plugins . auth . generateProfile ( {
346
350
username : 'robin' ,
351
+ scmUserId : 1357 ,
347
352
scmContext : 'github:mygithub.com' ,
348
353
scope : [ 'user' ] ,
349
354
metadata : { }
350
355
} ) ;
351
356
352
357
expect ( profile . username ) . to . contain ( 'robin' ) ;
358
+ expect ( profile . scmUserId ) . to . equal ( 1357 ) ;
353
359
expect ( profile . scmContext ) . to . contain ( 'github:mygithub.com' ) ;
354
360
expect ( profile . scope ) . to . contain ( 'user' ) ;
355
361
expect ( profile . scope ) . to . not . contain ( 'admin' ) ;
@@ -359,12 +365,14 @@ describe('auth plugin test', () => {
359
365
it ( 'does not add admin scope for admins without SCM user id' , ( ) => {
360
366
const profile = server . plugins . auth . generateProfile ( {
361
367
username : 'batman' ,
368
+ scmUserId : 1359 ,
362
369
scmContext : 'github:mygithub.com' ,
363
370
scope : [ 'user' ] ,
364
371
metadata : { }
365
372
} ) ;
366
373
367
374
expect ( profile . username ) . to . contain ( 'batman' ) ;
375
+ expect ( profile . scmUserId ) . to . equal ( 1359 ) ;
368
376
expect ( profile . scmContext ) . to . contain ( 'github:mygithub.com' ) ;
369
377
expect ( profile . scope ) . to . contain ( 'user' ) ;
370
378
expect ( profile . scope ) . to . not . contain ( 'admin' ) ;
@@ -405,6 +413,7 @@ describe('auth plugin test', () => {
405
413
} ) ;
406
414
407
415
expect ( profile . username ) . to . contain ( 'batman' ) ;
416
+ expect ( profile . scmUserId ) . to . equal ( 1312 ) ;
408
417
expect ( profile . scmContext ) . to . contain ( 'github:github.com' ) ;
409
418
expect ( profile . scope ) . to . contain ( 'user' ) ;
410
419
expect ( profile . scope ) . to . contain ( 'admin' ) ;
@@ -414,12 +423,14 @@ describe('auth plugin test', () => {
414
423
it ( 'does not add admin scope for non-admins' , ( ) => {
415
424
const profile = server . plugins . auth . generateProfile ( {
416
425
username : 'robin' ,
426
+ scmUserId : 1357 ,
417
427
scmContext : 'github:mygithub.com' ,
418
428
scope : [ 'user' ] ,
419
429
metadata : { }
420
430
} ) ;
421
431
422
432
expect ( profile . username ) . to . contain ( 'robin' ) ;
433
+ expect ( profile . scmUserId ) . to . equal ( 1357 ) ;
423
434
expect ( profile . scmContext ) . to . contain ( 'github:mygithub.com' ) ;
424
435
expect ( profile . scope ) . to . contain ( 'user' ) ;
425
436
expect ( profile . scope ) . to . not . contain ( 'admin' ) ;
@@ -429,12 +440,14 @@ describe('auth plugin test', () => {
429
440
it ( 'adds admin scope for admins without SCM user id' , ( ) => {
430
441
const profile = server . plugins . auth . generateProfile ( {
431
442
username : 'batman' ,
443
+ scmUserId : 1359 ,
432
444
scmContext : 'github:mygithub.com' ,
433
445
scope : [ 'user' ] ,
434
446
metadata : { }
435
447
} ) ;
436
448
437
449
expect ( profile . username ) . to . contain ( 'batman' ) ;
450
+ expect ( profile . scmUserId ) . to . equal ( 1359 ) ;
438
451
expect ( profile . scmContext ) . to . contain ( 'github:mygithub.com' ) ;
439
452
expect ( profile . scope ) . to . contain ( 'user' ) ;
440
453
expect ( profile . scope ) . to . contain ( 'admin' ) ;
@@ -1029,7 +1042,8 @@ describe('auth plugin test', () => {
1029
1042
{
1030
1043
username : 'robin' ,
1031
1044
scope : [ 'user' ] ,
1032
- environment : 'beta'
1045
+ environment : 'beta' ,
1046
+ scmUserId : 1579
1033
1047
} ,
1034
1048
jwtPrivateKey ,
1035
1049
{
@@ -1046,6 +1060,7 @@ describe('auth plugin test', () => {
1046
1060
assert . equal ( reply . statusCode , 200 , 'Login route should be available' ) ;
1047
1061
assert . ok ( reply . result . token , 'Token not returned' ) ;
1048
1062
expect ( reply . result . token ) . to . be . a . jwt . and . deep . include ( {
1063
+ scmUserId : 1579 ,
1049
1064
username : 'robin' ,
1050
1065
scope : [ 'user' ] ,
1051
1066
environment : 'beta'
@@ -1054,75 +1069,33 @@ describe('auth plugin test', () => {
1054
1069
1055
1070
it ( 'returns user signed token given an API access token' , ( ) => {
1056
1071
tokenMock . userId = id ;
1057
- server
1058
- . inject ( {
1059
- url : `/auth/token?api_token=${ apiKey } ` ,
1060
- auth : {
1061
- credentials : {
1062
- username : 'robin' ,
1063
- scope : [ 'user' ] ,
1064
- token : jwt . sign (
1065
- {
1066
- username : 'robin' ,
1067
- scope : [ 'user' ]
1068
- } ,
1069
- jwtPrivateKey ,
1070
- {
1071
- algorithm : 'RS256' ,
1072
- expiresIn : '2h' ,
1073
- jwtid : 'abc'
1074
- }
1075
- )
1076
- } ,
1077
- strategy : [ 'token' ]
1078
- }
1079
- } )
1080
- . then ( reply => {
1081
- assert . equal ( reply . statusCode , 200 , 'Login route should be available' ) ;
1082
- assert . ok ( reply . result . token , 'Token not returned' ) ;
1083
- expect ( reply . result . token ) . to . be . a . jwt . and . deep . include ( {
1084
- username : 'robin' ,
1085
- scope : [ 'user' ]
1086
- } ) ;
1072
+ scm . decorateAuthor . resolves ( { id : 1315 } ) ;
1073
+ collectionFactoryMock . list . resolves ( [ [ 1 ] , [ 2 ] ] ) ;
1074
+
1075
+ return server . inject ( { url : `/auth/token?api_token=${ apiKey } ` } ) . then ( reply => {
1076
+ assert . equal ( reply . statusCode , 200 , 'Login route should be available' ) ;
1077
+ assert . ok ( reply . result . token , 'Token not returned' ) ;
1078
+ expect ( reply . result . token ) . to . be . a . jwt . and . deep . include ( {
1079
+ scmUserId : 1315 ,
1080
+ username : 'batman' ,
1081
+ scope : [ 'user' ] ,
1082
+ scmContext : 'github:github.com'
1087
1083
} ) ;
1084
+ } ) ;
1088
1085
} ) ;
1089
1086
1090
1087
it ( 'returns pipeline signed token given an API access token' , ( ) => {
1091
1088
tokenMock . pipelineId = pipelineId ;
1092
1089
1093
- server
1094
- . inject ( {
1095
- url : `/auth/token?api_token=${ apiKey } ` ,
1096
- auth : {
1097
- credentials : {
1098
- username : 'robin' ,
1099
- scope : [ 'pipeline' ] ,
1100
- token : jwt . sign (
1101
- {
1102
- username : 'robin' ,
1103
- pipelineId : 1 ,
1104
- scope : [ 'pipeline' ]
1105
- } ,
1106
- jwtPrivateKey ,
1107
- {
1108
- algorithm : 'RS256' ,
1109
- expiresIn : '2h' ,
1110
- jwtid : 'abc'
1111
- }
1112
- )
1113
- } ,
1114
- strategy : [ 'token' ]
1115
- }
1116
- } )
1117
- . then ( reply => {
1118
- assert . equal ( reply . statusCode , 200 , 'Login route should be available' ) ;
1119
- assert . ok ( reply . result . token , 'Token not returned' ) ;
1120
- expect ( reply . result . token ) . to . be . a . jwt . and . deep . include ( {
1121
- username : 'robin' ,
1122
- scope : [ 'pipeline' ] ,
1123
- pipelineId : 1
1124
- } ) ;
1090
+ return server . inject ( { url : `/auth/token?api_token=${ apiKey } ` } ) . then ( reply => {
1091
+ assert . equal ( reply . statusCode , 200 , 'Login route should be available' ) ;
1092
+ assert . ok ( reply . result . token , 'Token not returned' ) ;
1093
+ expect ( reply . result . token ) . to . be . a . jwt . and . deep . include ( {
1094
+ username : 'batman' ,
1095
+ scope : [ 'pipeline' ] ,
1096
+ pipelineId : 12345
1125
1097
} ) ;
1098
+ } ) ;
1126
1099
} ) ;
1127
1100
1128
1101
it ( 'fails to issue a jwt given an invalid application auth token' , ( ) => {
0 commit comments