Skip to content

Commit

Permalink
fix(initiateAuth): invoke post auth lambda before generating tokens […
Browse files Browse the repository at this point in the history
…281]
  • Loading branch information
stocks29 authored and jagregory committed Aug 1, 2022
1 parent 48cbdde commit 8c06e2a
Show file tree
Hide file tree
Showing 7 changed files with 8,544 additions and 10,037 deletions.
1 change: 1 addition & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "jest-extended";
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module.exports = {
roots: ["<rootDir>/src"],
setupFiles: ["jest-date-mock"],
setupFilesAfterEnv: ["<rootDir>/setupTests.ts"],
setupFilesAfterEnv: [
"<rootDir>/setupTests.ts",
"jest-extended/all"
],
transform: {
"^.+\\.ts$": "esbuild-jest",
},
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@babel/preset-typescript": "^7.16.0",
"@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0",
"@jest/globals": "^27.0.6",
"@jest/globals": "^27.4.3",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
Expand All @@ -49,12 +49,13 @@
"eslint-config-prettier": "^6.15.0",
"husky": "^7.0.4",
"jest": "^27.4.3",
"jest-extended": "^3.0.1",
"jest-date-mock": "^1.0.8",
"lint-staged": "^10.1.3",
"markdown-toc": "^1.2.0",
"nodemon": "^2.0.3",
"prettier": "^2.5.1",
"semantic-release": "^18.0.1",
"semantic-release": "^19.0.3",
"supertest": "^6.1.6",
"ts-node": "^10.4.0",
"typescript": "^4.5.2"
Expand Down
6 changes: 5 additions & 1 deletion src/targets/initiateAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe("InitiateAuth target", () => {
});

describe("when Post Authentication trigger is enabled", () => {
it("invokes the trigger", async () => {
it("invokes the trigger before generating tokens", async () => {
mockTokenGenerator.generate.mockResolvedValue({
AccessToken: "access",
IdToken: "id",
Expand Down Expand Up @@ -474,6 +474,10 @@ describe("InitiateAuth target", () => {
userPoolId: userPoolClient.UserPoolId,
}
);

expect(
mockTriggers.postAuthentication as jest.Mock
).toHaveBeenCalledBefore(mockTokenGenerator.generate as jest.Mock);
});
});
});
Expand Down
18 changes: 8 additions & 10 deletions src/targets/initiateAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,6 @@ const userPasswordAuthFlow = async (
return verifyMfaChallenge(ctx, user, req, userPool, services);
}

const result = verifyPasswordChallenge(
ctx,
user,
req,
userPool,
userPoolClient,
services
);

if (services.triggers.enabled("PostAuthentication")) {
await services.triggers.postAuthentication(ctx, {
clientId: req.ClientId,
Expand All @@ -211,7 +202,14 @@ const userPasswordAuthFlow = async (
});
}

return result;
return verifyPasswordChallenge(
ctx,
user,
req,
userPool,
userPoolClient,
services
);
};

const refreshTokenAuthFlow = async (
Expand Down
13 changes: 11 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"strict": true,
"target": "ES2019"
},
"include": ["./setupTests.ts", "src/**/*.ts", "integration-tests/**/*.ts"],
"exclude": ["lib"]
"include": [
"./setupTests.ts",
"src/**/*.ts",
"integration-tests/**/*.ts"
],
"exclude": [
"lib"
],
"files": [
"global.d.ts"
]
}
Loading

0 comments on commit 8c06e2a

Please sign in to comment.