@@ -51,6 +51,9 @@ function mockGithubOIDCResponse(aud= "https://github.com/hashicorp/vault-action"
5151 return rsasign . KJUR . jws . JWS . sign ( alg , JSON . stringify ( header ) , JSON . stringify ( payload ) , decryptedKey ) ;
5252}
5353
54+ // The sign call inside this function takes a while to run, so cache the default JWT in a constant.
55+ const defaultGithubJwt = mockGithubOIDCResponse ( ) ;
56+
5457describe ( 'jwt auth' , ( ) => {
5558 beforeAll ( async ( ) => {
5659 // Verify Connection
@@ -99,7 +102,8 @@ describe('jwt auth', () => {
99102 'X-Vault-Token' : 'testtoken' ,
100103 } ,
101104 json : {
102- jwt_validation_pubkeys : publicRsaKey
105+ jwt_validation_pubkeys : publicRsaKey ,
106+ default_role : "default"
103107 }
104108 } ) ;
105109
@@ -198,20 +202,20 @@ describe('jwt auth', () => {
198202 . calledWith ( 'jwtPrivateKey' )
199203 . mockReturnValueOnce ( '' ) ;
200204
201- when ( core . getInput )
202- . calledWith ( 'role' )
203- . mockReturnValueOnce ( 'default' ) ;
204-
205205 when ( core . getInput )
206206 . calledWith ( 'secrets' )
207207 . mockReturnValueOnce ( 'secret/data/test secret' ) ;
208+ } ) ;
209+
210+ it ( 'successfully authenticates' , async ( ) => {
211+ when ( core . getInput )
212+ . calledWith ( 'role' )
213+ . mockReturnValueOnce ( 'default' ) ;
208214
209215 when ( core . getIDToken )
210216 . calledWith ( )
211- . mockReturnValueOnce ( mockGithubOIDCResponse ( ) ) ;
212- } ) ;
217+ . mockReturnValueOnce ( defaultGithubJwt ) ;
213218
214- it ( 'successfully authenticates' , async ( ) => {
215219 await exportSecrets ( ) ;
216220 expect ( core . exportVariable ) . toBeCalledWith ( 'SECRET' , 'SUPERSECRET' ) ;
217221 } ) ;
@@ -233,6 +237,19 @@ describe('jwt auth', () => {
233237 expect ( core . exportVariable ) . toBeCalledWith ( 'SECRET' , 'SUPERSECRET' ) ;
234238 } )
235239
240+ it ( 'successfully authenticates as default role without specifying it' , async ( ) => {
241+ when ( core . getInput )
242+ . calledWith ( 'role' )
243+ . mockReturnValueOnce ( null ) ;
244+
245+ when ( core . getIDToken )
246+ . calledWith ( )
247+ . mockReturnValueOnce ( defaultGithubJwt ) ;
248+
249+ await exportSecrets ( ) ;
250+ expect ( core . exportVariable ) . toBeCalledWith ( 'SECRET' , 'SUPERSECRET' ) ;
251+ } )
252+
236253 } ) ;
237254
238255} ) ;
0 commit comments