Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 5.3.1 #56

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [5.3.1] - 2023-10-25

### Fixed

The `getUserToken()` and `getUserPrincipal()` order was wrongly set in version `5.3.0`. The new fixed
priority order:

`getUserToken()`

1. `request.authorizerContext.jwt`
2. `request.authorizerContext.accessToken` (new)
3. `request.headers.Authorization`

`getUserPrincipal()`

1. `authorizerContext.canonicalId` (**prefer canonicalId**)
2. `authorizerContext.principalId` (new)
3. `request.headers.Authorization`

## [5.3.0] - 2023-09-07

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lambda-essentials-ts",
"version": "5.3.0",
"version": "5.3.1",
"description": "A selection of the finest modules supporting authorization, API routing, error handling, logging and sending HTTP requests.",
"main": "lib/index.js",
"private": false,
Expand Down
4 changes: 2 additions & 2 deletions src/openApi/openApiWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ export default class OpenApiWrapper {
} {
if (authorizerContext) {
return {
userPrincipal: authorizerContext.principalId ?? authorizerContext.canonicalId,
userToken: authorizerContext.accessToken ?? authorizerContext.jwt,
userPrincipal: authorizerContext.canonicalId ?? authorizerContext.principalId,
userToken: authorizerContext.jwt ?? authorizerContext.accessToken,
};
}

Expand Down
20 changes: 20 additions & 0 deletions tests/openApi/openApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ describe('Open API Wrapper', () => {
requestId: 'tests-request-id',
},
};
const requestWithOldAndNewStyleAuthorizer: ApiRequest<any> = {
...request,
requestContext: {
authorizer: {
canonicalId,
principalId,
jwt,
accessToken,
},
requestId: 'tests-request-id',
},
};
const testJwt =
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaHR0cHM6Ly9jbGFpbXMuY2ltcHJlc3MuaW8vY2Fub25pY2FsX2lkIjoiam9obkBkb2Uub3JnIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.XNjjaJDz4g8AecLBIDZY6aDwANCNMKg2NrcNxaJ-0JaqoGm0fBGPCZfbtGuf4-8DVqnwmrWslt7tMEj8QIU_TL1cWsX83ZGggM4crGva8tLw54Vhg5BrNWCOBiMphxGzU-5DbXPWvtnWatJgDdBuRSegZK5slpa8DnmXiMNkXxZhyulTbZYkArE2e16NFZhVANWmR3A4K_0ETF-s3uARvua9rPOxkaaxHPIkoZ58CsuD1p6pqi8KDthiW0OCry6o2uPIG-MfyP0gKDPD88XtVD5pcr6WWhNv37ZnucG75wuxE8c6eMj_pPCrt_eoM8ygUc9GY7XoLmZZAvI-szlivw';
const requestWithAuthorizationHeader: ApiRequest<any> = {
Expand Down Expand Up @@ -105,6 +117,14 @@ describe('Open API Wrapper', () => {
expect(openApi.getUserPrincipal()).toEqual(canonicalId);
});

test('sets userToken and userPrincipal from old-style Authorizer with priority', async () => {
const openApi = new OpenApiWrapper(new LoggerMock());
await openApi.api.requestMiddleware(requestWithOldAndNewStyleAuthorizer);

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);
Expand Down
Loading