Skip to content

Commit

Permalink
fix: confirmation ode from 4-digit to 6-digit (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
KeishiroKuma authored Apr 15, 2022
1 parent 3d70533 commit e2053fe
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 81 deletions.
4 changes: 2 additions & 2 deletions integration-tests/userPoolService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("User Pool Service", () => {
Username: username,
Password: "hunter3",
UserStatus: "UNCONFIRMED",
ConfirmationCode: "1234",
ConfirmationCode: "123456",
Attributes: [
{ Name: "sub", Value: "uuid-1234" },
{ Name: "email", Value: "example@example.com" },
Expand All @@ -114,7 +114,7 @@ describe("User Pool Service", () => {
Username: username,
Password: "hunter3",
UserStatus: "UNCONFIRMED",
ConfirmationCode: "1234",
ConfirmationCode: "123456",
Attributes: [
{ Name: "sub", Value: "uuid-1234" },
{ Name: "email", Value: "example@example.com" },
Expand Down
8 changes: 4 additions & 4 deletions src/services/messageDelivery/consoleMessageSender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("consoleMessageSender", () => {
describe.each(["sendEmail", "sendSms"] as const)("%s", (fn) => {
it("prints the message to the console", async () => {
await sender[fn](TestContext, user, destination, {
__code: "1234",
__code: "123456",
});

expect(TestContext.logger.info).toHaveBeenCalledWith(
Expand All @@ -24,13 +24,13 @@ describe("consoleMessageSender", () => {
expect.stringMatching(/Destination:\s+example@example.com/)
);
expect(TestContext.logger.info).toHaveBeenCalledWith(
expect.stringMatching(/Code:\s+1234/)
expect.stringMatching(/Code:\s+123456/)
);
});

it("doesn't print undefined fields", async () => {
await sender[fn](TestContext, user, destination, {
__code: "1234",
__code: "123456",
emailMessage: undefined,
});

Expand All @@ -41,7 +41,7 @@ describe("consoleMessageSender", () => {

it("prints additional fields", async () => {
await sender[fn](TestContext, user, destination, {
__code: "1234",
__code: "123456",
emailMessage: "this is the email message",
});

Expand Down
16 changes: 8 additions & 8 deletions src/services/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("messages service", () => {
"clientId",
"userPoolId",
user,
"1234",
"123456",
{
client: "metadata",
},
Expand All @@ -65,7 +65,7 @@ describe("messages service", () => {
clientMetadata: {
client: "metadata",
},
code: "1234",
code: "123456",
source: `CustomMessage_${source}`,
userAttributes: user.Attributes,
userPoolId: "userPoolId",
Expand All @@ -77,7 +77,7 @@ describe("messages service", () => {
user,
deliveryDetails,
{
__code: "1234",
__code: "123456",
emailMessage: "email",
emailSubject: "email subject",
smsMessage: "sms",
Expand All @@ -103,7 +103,7 @@ describe("messages service", () => {
"clientId",
"userPoolId",
user,
"1234",
"123456",
{
client: "metadata",
},
Expand All @@ -115,7 +115,7 @@ describe("messages service", () => {
clientMetadata: {
client: "metadata",
},
code: "1234",
code: "123456",
source: `CustomMessage_${source}`,
userAttributes: user.Attributes,
userPoolId: "userPoolId",
Expand All @@ -127,7 +127,7 @@ describe("messages service", () => {
user,
deliveryDetails,
{
__code: "1234",
__code: "123456",
}
);
});
Expand All @@ -145,7 +145,7 @@ describe("messages service", () => {
"clientId",
"userPoolId",
user,
"1234",
"123456",
{
client: "metadata",
},
Expand All @@ -158,7 +158,7 @@ describe("messages service", () => {
user,
deliveryDetails,
{
__code: "1234",
__code: "123456",
}
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/services/otp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { otp } from "./otp";

describe("otp", () => {
it("generates a code", () => {
expect(otp()).toMatch(/^[0-9]{4}$/);
expect(otp()).toMatch(/^[0-9]{6}$/);
});
});
4 changes: 2 additions & 2 deletions src/services/otp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const otp = (): string =>
Math.floor(Math.random() * 9999)
Math.floor(Math.random() * 999999)
.toString()
.padStart(4, "0");
.padStart(6, "0");
8 changes: 4 additions & 4 deletions src/services/triggers/customMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("CustomMessage trigger", () => {
const message = await customMessage(TestContext, {
clientId: "clientId",
clientMetadata: undefined,
code: "1234",
code: "123456",
source: "CustomMessage_ForgotPassword",
userAttributes: [],
username: "username",
Expand All @@ -45,7 +45,7 @@ describe("CustomMessage trigger", () => {
clientMetadata: {
client: "metadata",
},
code: "1234",
code: "123456",
source: "CustomMessage_ForgotPassword",
userAttributes: [{ Name: "user", Value: "attribute" }],
username: "example@example.com",
Expand Down Expand Up @@ -73,11 +73,11 @@ describe("CustomMessage trigger", () => {

expect(message).not.toBeNull();
expect(message?.emailMessage).toEqual(
"hi example@example.com your code is 1234. via email"
"hi example@example.com your code is 123456. via email"
);
expect(message?.emailSubject).toEqual("email subject");
expect(message?.smsMessage).toEqual(
"hi example@example.com your code is 1234. via sms"
"hi example@example.com your code is 123456. via sms"
);
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/targets/adminUpdateUserAttributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("AdminUpdateUserAttributes target", () => {
clock,
cognito: newMockCognitoService(mockUserPoolService),
messages: mockMessages,
otp: () => "1234",
otp: () => "123456",
});
});

Expand Down Expand Up @@ -232,7 +232,7 @@ describe("AdminUpdateUserAttributes target", () => {
null,
"test",
user,
"1234",
"123456",
{ client: "metadata" },
{
AttributeName: "email",
Expand All @@ -244,7 +244,7 @@ describe("AdminUpdateUserAttributes target", () => {
expect(mockUserPoolService.saveUser).toHaveBeenCalledWith(
TestContext,
expect.objectContaining({
AttributeVerificationCode: "1234",
AttributeVerificationCode: "123456",
})
);
});
Expand Down
18 changes: 9 additions & 9 deletions src/targets/confirmForgotPassword.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ describe("ConfirmForgotPassword target", () => {
confirmForgotPassword(TestContext, {
ClientId: "clientId",
Username: "janice",
ConfirmationCode: "1234",
ConfirmationCode: "123456",
Password: "newPassword",
})
).rejects.toBeInstanceOf(UserNotFoundError);
});

it("throws if confirmation code doesn't match stored value", async () => {
const user = TDB.user({
ConfirmationCode: "4567",
ConfirmationCode: "456789",
UserStatus: "UNCONFIRMED",
});

Expand All @@ -58,7 +58,7 @@ describe("ConfirmForgotPassword target", () => {
confirmForgotPassword(TestContext, {
ClientId: "clientId",
Username: "janice",
ConfirmationCode: "1234",
ConfirmationCode: "123456",
Password: "newPassword",
})
).rejects.toBeInstanceOf(CodeMismatchError);
Expand All @@ -67,7 +67,7 @@ describe("ConfirmForgotPassword target", () => {
describe("when code matches", () => {
it("updates the user's password", async () => {
const user = TDB.user({
ConfirmationCode: "4567",
ConfirmationCode: "456789",
UserStatus: "UNCONFIRMED",
});

Expand All @@ -79,7 +79,7 @@ describe("ConfirmForgotPassword target", () => {
await confirmForgotPassword(TestContext, {
ClientId: "clientId",
Username: user.Username,
ConfirmationCode: "4567",
ConfirmationCode: "456789",
Password: "newPassword",
});

Expand All @@ -97,7 +97,7 @@ describe("ConfirmForgotPassword target", () => {
mockTriggers.enabled.mockReturnValue(true);

const user = TDB.user({
ConfirmationCode: "4567",
ConfirmationCode: "456789",
UserStatus: "UNCONFIRMED",
});

Expand All @@ -109,7 +109,7 @@ describe("ConfirmForgotPassword target", () => {
client: "metadata",
},
Username: user.Username,
ConfirmationCode: "4567",
ConfirmationCode: "456789",
Password: "newPassword",
});

Expand Down Expand Up @@ -137,7 +137,7 @@ describe("ConfirmForgotPassword target", () => {
mockTriggers.enabled.mockReturnValue(false);

const user = TDB.user({
ConfirmationCode: "4567",
ConfirmationCode: "456789",
UserStatus: "UNCONFIRMED",
});

Expand All @@ -146,7 +146,7 @@ describe("ConfirmForgotPassword target", () => {
await confirmForgotPassword(TestContext, {
ClientId: "clientId",
Username: user.Username,
ConfirmationCode: "4567",
ConfirmationCode: "456789",
Password: "newPassword",
});

Expand Down
18 changes: 9 additions & 9 deletions src/targets/confirmSignUp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ describe("ConfirmSignUp target", () => {
confirmSignUp(TestContext, {
ClientId: "clientId",
Username: "janice",
ConfirmationCode: "1234",
ConfirmationCode: "123456",
ForceAliasCreation: false,
})
).rejects.toBeInstanceOf(NotAuthorizedError);
});

it("throws if confirmation code doesn't match stored value", async () => {
const user = TDB.user({
ConfirmationCode: "4567",
ConfirmationCode: "456789",
UserStatus: "UNCONFIRMED",
});

Expand All @@ -54,15 +54,15 @@ describe("ConfirmSignUp target", () => {
confirmSignUp(TestContext, {
ClientId: "clientId",
Username: user.Username,
ConfirmationCode: "1234",
ConfirmationCode: "123456",
})
).rejects.toBeInstanceOf(CodeMismatchError);
});

describe("when code matches", () => {
it("updates the user's confirmed status", async () => {
const user = TDB.user({
ConfirmationCode: "4567",
ConfirmationCode: "456789",
UserStatus: "UNCONFIRMED",
});

Expand All @@ -74,7 +74,7 @@ describe("ConfirmSignUp target", () => {
await confirmSignUp(TestContext, {
ClientId: "clientId",
Username: user.Username,
ConfirmationCode: "4567",
ConfirmationCode: "456789",
});

expect(mockUserPoolService.saveUser).toHaveBeenCalledWith(TestContext, {
Expand All @@ -90,7 +90,7 @@ describe("ConfirmSignUp target", () => {
mockTriggers.enabled.mockReturnValue(true);

const user = TDB.user({
ConfirmationCode: "4567",
ConfirmationCode: "456789",
UserStatus: "UNCONFIRMED",
});

Expand All @@ -102,7 +102,7 @@ describe("ConfirmSignUp target", () => {
client: "metadata",
},
Username: "janice",
ConfirmationCode: "4567",
ConfirmationCode: "456789",
ForceAliasCreation: false,
});

Expand Down Expand Up @@ -130,7 +130,7 @@ describe("ConfirmSignUp target", () => {
mockTriggers.enabled.mockReturnValue(false);

const user = TDB.user({
ConfirmationCode: "4567",
ConfirmationCode: "456789",
UserStatus: "UNCONFIRMED",
});

Expand All @@ -139,7 +139,7 @@ describe("ConfirmSignUp target", () => {
await confirmSignUp(TestContext, {
ClientId: "clientId",
Username: user.Username,
ConfirmationCode: "4567",
ConfirmationCode: "456789",
});

expect(mockTriggers.postConfirmation).not.toHaveBeenCalled();
Expand Down
6 changes: 3 additions & 3 deletions src/targets/forgotPassword.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("ForgotPassword target", () => {
beforeEach(() => {
mockUserPoolService = newMockUserPoolService();
mockMessages = newMockMessages();
mockOtp = jest.fn().mockReturnValue("1234");
mockOtp = jest.fn().mockReturnValue("123456");
forgotPassword = ForgotPassword({
cognito: newMockCognitoService(mockUserPoolService),
clock: new ClockFake(currentDate),
Expand Down Expand Up @@ -57,7 +57,7 @@ describe("ForgotPassword target", () => {
"clientId",
"test",
user,
"1234",
"123456",
{ client: "metadata" },
{
AttributeName: "email",
Expand Down Expand Up @@ -88,7 +88,7 @@ describe("ForgotPassword target", () => {
expect(mockUserPoolService.saveUser).toHaveBeenCalledWith(TestContext, {
...user,
UserLastModifiedDate: currentDate,
ConfirmationCode: "1234",
ConfirmationCode: "123456",
});
});
});
Loading

0 comments on commit e2053fe

Please sign in to comment.