Skip to content

Commit

Permalink
Add lerna and add cleaned up examples to lerna packages. (awsdocs#4187)
Browse files Browse the repository at this point in the history
* add lerna; update cognito

* update lambda and libs tests for lerna compat

* fix typo in unit test title

Co-authored-by: Steven Meyer <[email protected]>
  • Loading branch information
cpyle0819 and meyertst-aws authored Jan 5, 2023
1 parent 981d2a4 commit 57042f0
Show file tree
Hide file tree
Showing 52 changed files with 62,590 additions and 13,044 deletions.
1 change: 1 addition & 0 deletions javascriptv3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
6 changes: 3 additions & 3 deletions javascriptv3/example_code/cognito/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Code examples that show you how to accomplish a specific task by calling multipl
### Prerequisites

- [Set up AWS SDK for JavaScript](../README.rst)
- Run `yarn` to install dependencies.
- Run `npm i` to install dependencies.

### Instructions

Expand All @@ -65,8 +65,8 @@ its readme.

⚠️ Running the tests might result in charges to your AWS account.

1. Run `yarn`
1. Run `yarn test`
1. Run `npm i`.
2. Run `npm test`.

## Additional resources

Expand Down
10 changes: 5 additions & 5 deletions javascriptv3/example_code/cognito/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
"license": "Apache-2.0",
"type": "module",
"scripts": {
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
"test": "vitest run **/*.unit.test.js",
"integration-test": "vitest run **/*.integration.test.js"
},
"dependencies": {
"@aws-sdk/client-cognito-identity-provider": "^3.183.0",
"@aws-sdk/client-ses": "^3.183.0",
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.3",
"@types/qrcode-terminal": "^0.12.0",
"amazon-cognito-identity-js": "^5.2.10",
"aws-amplify": "^4.3.37",
"babel-jest": "^29.1.2",
"crypto-js": "^4.1.1",
"jest": "^29.1.2",
"qrcode-terminal": "^0.12.0",
"ramda": "^0.28.0"
},
"devDependencies": {
"vitest": "^0.26.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { describe, expect } from "@jest/globals";
import { describe, it, expect, afterAll } from "vitest";
import { createUserPool } from "../actions/create-user-pool.js";
import { getUniqueName } from "../../libs/utils/util-string.js";
import { deleteUserPool } from "../actions/delete-user-pool.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,57 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { testEqual } from "../../libs/utils/util-test.js";
import { describe, it, expect } from "vitest";
import { handler } from "../scenarios/lambda-triggers/functions/auth-challenge-create.mjs";

describe("auth-challenge-create function", () => {
it(
'should return the same request/response objects if the challenge name is not "CUSTOM_CHALLENGE"',
testEqual(
expect.objectContaining({ request: {}, response: {} }),
handler({ request: {}, response: {} })
)
);
it('should return the same request/response objects if the challenge name is not "CUSTOM_CHALLENGE"', async () => {
const result = await handler({ request: {}, response: {} });
expect(result).toEqual(
expect.objectContaining({ request: {}, response: {} })
);
});

it(
"should return the same request/response objects if there are no sessions",
testEqual(
expect.objectContaining({
request: { challengeName: "CUSTOM_CHALLENGE", session: [] },
response: {},
}),
handler({
request: { challengeName: "CUSTOM_CHALLENGE", session: [] },
response: {},
})
)
);
it("should return the same request/response objects if there are no sessions", async () => {
const result = await handler({
request: { challengeName: "CUSTOM_CHALLENGE", session: [] },
response: {},
});
expect(result).toEqual({
request: { challengeName: "CUSTOM_CHALLENGE", session: [] },
response: {},
});
});

it(
"should return a captcha challenge if the session length is 2",
testEqual(
it("should return a captcha challenge if the session length is 2", async () => {
const result = await handler({
request: { challengeName: "CUSTOM_CHALLENGE", session: [{}, {}] },
response: {},
});
expect(result).toEqual(
expect.objectContaining({
response: {
publicChallengeParameters: { captchaUrl: "url/123.jpg" },
privateChallengeParameters: { answer: "5" },
},
}),
handler({
request: { challengeName: "CUSTOM_CHALLENGE", session: [{}, {}] },
response: {},
})
)
);
);
});

it(
"should return a mascot challenge if the session length is 3",
testEqual(
it("should return a mascot challenge if the session length is 3", async () => {
const result = await handler({
request: { challengeName: "CUSTOM_CHALLENGE", session: [{}, {}, {}] },
response: {},
});
expect(result).toEqual(
expect.objectContaining({
response: {
publicChallengeParameters: {
securityQuestion: "Who is your favorite team mascot?",
},
privateChallengeParameters: { answer: "Peccy" },
},
}),
handler({
request: { challengeName: "CUSTOM_CHALLENGE", session: [{}, {}, {}] },
response: {},
})
)
);
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,116 +3,111 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { testEqual } from "../../libs/utils/util-test.js";
import { describe, it, expect } from "vitest";
import { handler } from "../scenarios/lambda-triggers/functions/auth-challenge-define.mjs";

describe("auth-challenge-define", () => {
it(
"should return a password verifier challenge if the challenge name is SRP_A",
testEqual(
it("should return a password verifier challenge if the challenge name is SRP_A", async () => {
const result = await handler({
response: {},
request: { session: [{ challengeName: "SRP_A" }] },
});
expect(result).toEqual(
expect.objectContaining({
response: {
issueTokens: false,
failAuthentication: false,
challengeName: "PASSWORD_VERIFIER",
},
}),
handler({
response: {},
request: { session: [{ challengeName: "SRP_A" }] },
})
)
);
);
});

it(
"should return a custom challenge if the password verifier challenge was successful",
testEqual(
it("should return a custom challenge if the password verifier challenge was successful", async () => {
const result = await handler({
request: {
session: [
{},
{ challengeName: "PASSWORD_VERIFIER", challengeResult: true },
],
},
response: {},
});
expect(result).toEqual(
expect.objectContaining({
response: {
issueTokens: false,
failAuthentication: false,
challengeName: "CUSTOM_CHALLENGE",
},
}),
handler({
request: {
session: [
{},
{ challengeName: "PASSWORD_VERIFIER", challengeResult: true },
],
},
response: {},
})
)
);
);
});

it(
"should return a custom challenge if we're on the 4th challenge and the last challenge was successful",
testEqual(
it("should return a custom challenge if we're on the 4th challenge and the last challenge was successful", async () => {
const result = await handler({
request: {
session: [
{},
{},
{ challengeName: "CUSTOM_CHALLENGE", challengeResult: true },
],
},
response: {},
});
expect(result).toEqual(
expect.objectContaining({
response: {
issueTokens: false,
failAuthentication: false,
challengeName: "CUSTOM_CHALLENGE",
},
}),
handler({
request: {
session: [
{},
{},
{ challengeName: "CUSTOM_CHALLENGE", challengeResult: true },
],
},
response: {},
})
)
);
);
});

it(
"should return tokens if the last challenge was successful",
testEqual(
it("should return tokens if the last challenge was successful", async () => {
const result = await handler({
request: {
session: [
{},
{},
{},
{ challengeName: "CUSTOM_CHALLENGE", challengeResult: true },
],
},
response: {},
});
expect(result).toEqual(
expect.objectContaining({
response: {
issueTokens: true,
failAuthentication: false,
},
}),
handler({
request: {
session: [
{},
{},
{},
{ challengeName: "CUSTOM_CHALLENGE", challengeResult: true },
],
},
response: {},
})
)
);
);
});

it(
"should fail authentication if there's no matching definition",
testEqual(
it("should fail authentication if there's no matching definition", async () => {
const result = await handler({
request: {
session: [
{},
{},
{},
{},
{ challengeName: "CUSTOM_CHALLENGE", challengeResult: true },
],
},
response: {},
});
expect(result).toEqual(
expect.objectContaining({
response: {
issueTokens: false,
failAuthentication: true,
},
}),
handler({
request: {
session: [
{},
{},
{},
{},
{ challengeName: "CUSTOM_CHALLENGE", challengeResult: true },
],
},
response: {},
})
)
);
);
});
});
Loading

0 comments on commit 57042f0

Please sign in to comment.