-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple user authorization sources
- Loading branch information
Showing
6 changed files
with
113 additions
and
388 deletions.
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
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
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 |
---|---|---|
|
@@ -14,6 +14,8 @@ describe('Open API Wrapper', () => { | |
const path = '/path'; | ||
const principalId = 'tests-principal-id'; | ||
const canonicalId = 'tests-canonical-id'; | ||
const jwt = 'tests-jwt'; | ||
const accessToken = 'test-access-token'; | ||
const correlationId = 'test-correlation-id'; | ||
const request: ApiRequest<any> = { | ||
headers, | ||
|
@@ -22,9 +24,8 @@ describe('Open API Wrapper', () => { | |
pathParameters: { param: 'param' }, | ||
requestContext: { | ||
authorizer: { | ||
canonicalId, | ||
jwt: 'tests-jwt', | ||
principalId, | ||
accessToken, | ||
}, | ||
requestId: 'tests-request-id', | ||
}, | ||
|
@@ -41,6 +42,28 @@ describe('Open API Wrapper', () => { | |
'orion-correlation-id-root': correlationId, | ||
}, | ||
}; | ||
const requestWithOldStyleAuthorizer: ApiRequest<any> = { | ||
...request, | ||
requestContext: { | ||
authorizer: { | ||
canonicalId, | ||
jwt, | ||
}, | ||
requestId: 'tests-request-id', | ||
}, | ||
}; | ||
const testJwt = | ||
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaHR0cHM6Ly9jbGFpbXMuY2ltcHJlc3MuaW8vY2Fub25pY2FsX2lkIjoiam9obkBkb2Uub3JnIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.XNjjaJDz4g8AecLBIDZY6aDwANCNMKg2NrcNxaJ-0JaqoGm0fBGPCZfbtGuf4-8DVqnwmrWslt7tMEj8QIU_TL1cWsX83ZGggM4crGva8tLw54Vhg5BrNWCOBiMphxGzU-5DbXPWvtnWatJgDdBuRSegZK5slpa8DnmXiMNkXxZhyulTbZYkArE2e16NFZhVANWmR3A4K_0ETF-s3uARvua9rPOxkaaxHPIkoZ58CsuD1p6pqi8KDthiW0OCry6o2uPIG-MfyP0gKDPD88XtVD5pcr6WWhNv37ZnucG75wuxE8c6eMj_pPCrt_eoM8ygUc9GY7XoLmZZAvI-szlivw'; | ||
const requestWithAuthorizationHeader: ApiRequest<any> = { | ||
...request, | ||
headers: { | ||
Authorization: `Bearer ${testJwt}`, | ||
}, | ||
requestContext: { | ||
authorizer: undefined, | ||
requestId: 'tests-request-id', | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
LoggerMock.mockImplementation(() => ({ | ||
|
@@ -60,11 +83,35 @@ describe('Open API Wrapper', () => { | |
level: 'INFO', | ||
title: 'RequestLogger', | ||
method: httpMethod, | ||
user: canonicalId, | ||
user: principalId, | ||
path, | ||
headers, | ||
}); | ||
}); | ||
|
||
test('sets userToken and userPrincipal from new-style Authorizer', async () => { | ||
const openApi = new OpenApiWrapper(new LoggerMock()); | ||
await openApi.api.requestMiddleware(request); | ||
|
||
expect(openApi.getUserToken()).toEqual(accessToken); | ||
expect(openApi.getUserPrincipal()).toEqual(principalId); | ||
}); | ||
|
||
test('sets userToken and userPrincipal from old-style Authorizer', async () => { | ||
const openApi = new OpenApiWrapper(new LoggerMock()); | ||
await openApi.api.requestMiddleware(requestWithOldStyleAuthorizer); | ||
|
||
expect(openApi.getUserToken()).toEqual(jwt); | ||
expect(openApi.getUserPrincipal()).toEqual(canonicalId); | ||
}); | ||
|
||
test('sets userToken and userPrincipal from Authorization header', async () => { | ||
const openApi = new OpenApiWrapper(new LoggerMock()); | ||
await openApi.api.requestMiddleware(requestWithAuthorizationHeader); | ||
|
||
expect(openApi.getUserToken()).toEqual(testJwt); | ||
expect(openApi.getUserPrincipal()).toEqual('[email protected]'); | ||
}); | ||
}); | ||
|
||
describe('responseMiddleware', () => { | ||
|
Oops, something went wrong.