-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use self-signed JWTs when non-default Universe Domains (#1722)
* feat: Use self-signed JWTs when non-default Universe Domains * feat: AL-9 * fix: remove unused
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1007,6 +1007,72 @@ describe('jwt', () => { | |
); | ||
}); | ||
|
||
it('signs JWT with audience if: user scope = true, default scope = true, audience = truthy, universeDomain = not default universe', async () => { | ||
const stubGetRequestHeaders = sandbox.stub().returns({}); | ||
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({ | ||
getRequestHeaders: stubGetRequestHeaders, | ||
}); | ||
const jwt = new JWT({ | ||
email: '[email protected]', | ||
key: fs.readFileSync(PEM_PATH, 'utf8'), | ||
scopes: ['scope1', 'scope2'], | ||
universeDomain: 'my-universe.com', | ||
}); | ||
jwt.defaultScopes = ['scope1', 'scope2']; | ||
await jwt.getRequestHeaders('https//beepboop.googleapis.com'); | ||
sandbox.assert.calledOnce(stubJWTAccess); | ||
sandbox.assert.calledWith( | ||
stubGetRequestHeaders, | ||
'https//beepboop.googleapis.com', | ||
undefined, | ||
undefined | ||
); | ||
}); | ||
|
||
it('signs JWT with audience if: user scope = true, default scope = true, audience = truthy, useJWTAccessWithScope = true, universeDomain = not default universe', async () => { | ||
const stubGetRequestHeaders = sandbox.stub().returns({}); | ||
const stubJWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({ | ||
getRequestHeaders: stubGetRequestHeaders, | ||
}); | ||
const jwt = new JWT({ | ||
email: '[email protected]', | ||
key: fs.readFileSync(PEM_PATH, 'utf8'), | ||
scopes: ['scope1', 'scope2'], | ||
universeDomain: 'my-universe.com', | ||
}); | ||
jwt.useJWTAccessWithScope = true; | ||
jwt.defaultScopes = ['scope1', 'scope2']; | ||
await jwt.getRequestHeaders('https//beepboop.googleapis.com'); | ||
sandbox.assert.calledOnce(stubJWTAccess); | ||
sandbox.assert.calledWith( | ||
stubGetRequestHeaders, | ||
'https//beepboop.googleapis.com', | ||
undefined, | ||
['scope1', 'scope2'] | ||
); | ||
}); | ||
|
||
it('throws on domain-wide delegation on non-default universe', async () => { | ||
const stubGetRequestHeaders = sandbox.stub().returns({}); | ||
sandbox.stub(jwtaccess, 'JWTAccess').returns({ | ||
getRequestHeaders: stubGetRequestHeaders, | ||
}); | ||
const jwt = new JWT({ | ||
email: '[email protected]', | ||
key: fs.readFileSync(PEM_PATH, 'utf8'), | ||
scopes: ['scope1', 'scope2'], | ||
subject: '[email protected]', | ||
universeDomain: 'my-universe.com', | ||
}); | ||
jwt.useJWTAccessWithScope = true; | ||
jwt.defaultScopes = ['scope1', 'scope2']; | ||
|
||
await assert.rejects( | ||
() => jwt.getRequestHeaders('https//beepboop.googleapis.com'), | ||
/Domain-wide delegation is not supported in universes other than/ | ||
); | ||
}); | ||
|
||
it('does not use self signed JWT if target_audience provided', async () => { | ||
const JWTAccess = sandbox.stub(jwtaccess, 'JWTAccess').returns({ | ||
getRequestHeaders: sinon.stub().returns({}), | ||
|