Skip to content

Commit

Permalink
eslint formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcallister0210 committed Sep 15, 2024
1 parent 9300ed0 commit 99956e4
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/__tests__/integration/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { CognitoIdentityProviderClient, SignUpCommand } from "@aws-sdk/client-cognito-identity-provider";
import { createSecretHash } from "../../cognito-srp-helper";
import { CognitoIdentityServiceProvider } from "aws-sdk";

import { createSecretHash } from "../../cognito-srp-helper";

type SignupOptionsV2 = {
username: string;
password: string;
Expand Down
23 changes: 12 additions & 11 deletions src/__tests__/integration/sdk-v2-device-flow.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { faker } from "@faker-js/faker";
import { CognitoIdentityServiceProvider } from "aws-sdk";
import dotenv from "dotenv";
import path from "path";
import RandExp from "randexp";
import { TOTP } from "totp-generator";

import {
createDeviceVerifier,
Expand All @@ -12,9 +15,7 @@ import {
wrapAuthChallenge,
wrapInitiateAuth,
} from "../../cognito-srp-helper";
import { faker } from "@faker-js/faker";
import RandExp from "randexp";
import { TOTP } from "totp-generator";

import { signupV2 } from "./helpers";

// Load in env variables from .env if it / they exist..
Expand Down Expand Up @@ -190,7 +191,7 @@ describe("SDK v2 integration - DEVICE_SRP_AUTH flow", () => {
if (!SecretCode) throw Error("SecretCode is undefined");
const { otp: otp1, expires } = TOTP.generate(SecretCode);

const verifySoftwareTokenRes = await cognitoIdentityServiceProvider
await cognitoIdentityServiceProvider
.verifySoftwareToken({
AccessToken,
UserCode: otp1,
Expand All @@ -199,7 +200,7 @@ describe("SDK v2 integration - DEVICE_SRP_AUTH flow", () => {

// ---------- Set MFA preference to TOTP ----------

const setUserMFAPreferenceRes = await cognitoIdentityServiceProvider
await cognitoIdentityServiceProvider
.setUserMFAPreference({
AccessToken,
SoftwareTokenMfaSettings: {
Expand Down Expand Up @@ -279,7 +280,7 @@ describe("SDK v2 integration - DEVICE_SRP_AUTH flow", () => {
if (!DeviceKey) throw Error("DeviceKey is undefined");
const { DeviceSecretVerifierConfig, DeviceRandomPassword } = createDeviceVerifier(DeviceKey, DeviceGroupKey);

const confirmDeviceRes = await cognitoIdentityServiceProvider
await cognitoIdentityServiceProvider
.confirmDevice({
AccessToken,
DeviceKey,
Expand All @@ -290,7 +291,7 @@ describe("SDK v2 integration - DEVICE_SRP_AUTH flow", () => {

// ---------- Remember the device (for easier logins) ----------

const updateDeviceStatusRes = await cognitoIdentityServiceProvider
await cognitoIdentityServiceProvider
.updateDeviceStatus({
AccessToken,
DeviceKey,
Expand Down Expand Up @@ -461,7 +462,7 @@ describe("SDK v2 integration - DEVICE_SRP_AUTH flow", () => {
if (!SecretCode) throw Error("SecretCode is undefined");
const { otp: otp1, expires } = TOTP.generate(SecretCode);

const verifySoftwareTokenRes = await cognitoIdentityServiceProvider
await cognitoIdentityServiceProvider
.verifySoftwareToken({
AccessToken,
UserCode: otp1,
Expand All @@ -470,7 +471,7 @@ describe("SDK v2 integration - DEVICE_SRP_AUTH flow", () => {

// ---------- Set MFA preference to TOTP ----------

const setUserMFAPreferenceRes = await cognitoIdentityServiceProvider
await cognitoIdentityServiceProvider
.adminSetUserMFAPreference({
UserPoolId: poolId,
Username: username,
Expand Down Expand Up @@ -554,7 +555,7 @@ describe("SDK v2 integration - DEVICE_SRP_AUTH flow", () => {
if (!DeviceKey) throw Error("DeviceKey is undefined");
const { DeviceSecretVerifierConfig, DeviceRandomPassword } = createDeviceVerifier(DeviceKey, DeviceGroupKey);

const confirmDeviceRes = await cognitoIdentityServiceProvider
await cognitoIdentityServiceProvider
.confirmDevice({
AccessToken,
DeviceKey,
Expand All @@ -565,7 +566,7 @@ describe("SDK v2 integration - DEVICE_SRP_AUTH flow", () => {

// ---------- Remember the device (for easier logins) ----------

const updateDeviceStatusRes = await cognitoIdentityServiceProvider
await cognitoIdentityServiceProvider
.adminUpdateDeviceStatus({
UserPoolId: poolId,
Username: USER_ID_FOR_SRP,
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/integration/sdk-v2-standard-flow.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { faker } from "@faker-js/faker";
import { CognitoIdentityServiceProvider } from "aws-sdk";
import dotenv from "dotenv";
import path from "path";
import RandExp from "randexp";

import {
createPasswordHash,
Expand All @@ -10,8 +12,7 @@ import {
wrapAuthChallenge,
wrapInitiateAuth,
} from "../../cognito-srp-helper";
import { faker } from "@faker-js/faker";
import RandExp from "randexp";

import { signupV2 } from "./helpers";

// Load in env variables from .env if it / they exist..
Expand Down
24 changes: 12 additions & 12 deletions src/__tests__/integration/sdk-v3-device-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
InitiateAuthCommand,
RespondToAuthChallengeCommand,
SetUserMFAPreferenceCommand,
SignUpCommand,
UpdateDeviceStatusCommand,
VerifySoftwareTokenCommand,
} from "@aws-sdk/client-cognito-identity-provider";
import { faker } from "@faker-js/faker";
import dotenv from "dotenv";
import path from "path";
import RandExp from "randexp";
import { TOTP } from "totp-generator";

import {
createDeviceVerifier,
Expand All @@ -26,9 +28,7 @@ import {
wrapAuthChallenge,
wrapInitiateAuth,
} from "../../cognito-srp-helper";
import { faker } from "@faker-js/faker";
import RandExp from "randexp";
import { TOTP } from "totp-generator";

import { signupV3 } from "./helpers";

// Load in env variables from .env if it / they exist..
Expand Down Expand Up @@ -196,7 +196,7 @@ describe("SDK v3 integration - DEVICE_SRP_AUTH flow", () => {
if (!SecretCode) throw Error("SecretCode is undefined");
const { otp: otp1, expires } = TOTP.generate(SecretCode);

const verifySoftwareTokenRes = await cognitoIdentityProviderClient.send(
await cognitoIdentityProviderClient.send(
new VerifySoftwareTokenCommand({
AccessToken,
UserCode: otp1,
Expand All @@ -205,7 +205,7 @@ describe("SDK v3 integration - DEVICE_SRP_AUTH flow", () => {

// ---------- Set MFA preference to TOTP ----------

const setUserMFAPreferenceRes = await cognitoIdentityProviderClient.send(
await cognitoIdentityProviderClient.send(
new AdminSetUserMFAPreferenceCommand({
UserPoolId: poolId,
Username: username,
Expand Down Expand Up @@ -286,7 +286,7 @@ describe("SDK v3 integration - DEVICE_SRP_AUTH flow", () => {
if (!DeviceKey) throw Error("DeviceKey is undefined");
const { DeviceSecretVerifierConfig, DeviceRandomPassword } = createDeviceVerifier(DeviceKey, DeviceGroupKey);

const confirmDeviceRes = await cognitoIdentityProviderClient.send(
await cognitoIdentityProviderClient.send(
new ConfirmDeviceCommand({
AccessToken,
DeviceKey,
Expand All @@ -297,7 +297,7 @@ describe("SDK v3 integration - DEVICE_SRP_AUTH flow", () => {

// ---------- Remember the device (for easier logins) ----------

const updateDeviceStatusRes = await cognitoIdentityProviderClient.send(
await cognitoIdentityProviderClient.send(
new UpdateDeviceStatusCommand({
AccessToken,
DeviceKey,
Expand Down Expand Up @@ -468,7 +468,7 @@ describe("SDK v3 integration - DEVICE_SRP_AUTH flow", () => {
if (!SecretCode) throw Error("SecretCode is undefined");
const { otp: otp1, expires } = TOTP.generate(SecretCode);

const verifySoftwareTokenRes = await cognitoIdentityProviderClient.send(
await cognitoIdentityProviderClient.send(
new VerifySoftwareTokenCommand({
AccessToken,
UserCode: otp1,
Expand All @@ -477,7 +477,7 @@ describe("SDK v3 integration - DEVICE_SRP_AUTH flow", () => {

// ---------- Set MFA preference to TOTP ----------

const setUserMFAPreferenceRes = await cognitoIdentityProviderClient.send(
await cognitoIdentityProviderClient.send(
new SetUserMFAPreferenceCommand({
AccessToken,
SoftwareTokenMfaSettings: {
Expand Down Expand Up @@ -560,7 +560,7 @@ describe("SDK v3 integration - DEVICE_SRP_AUTH flow", () => {
if (!DeviceKey) throw Error("DeviceKey is undefined");
const { DeviceSecretVerifierConfig, DeviceRandomPassword } = createDeviceVerifier(DeviceKey, DeviceGroupKey);

const confirmDeviceRes = await cognitoIdentityProviderClient.send(
await cognitoIdentityProviderClient.send(
new ConfirmDeviceCommand({
AccessToken,
DeviceKey,
Expand All @@ -571,7 +571,7 @@ describe("SDK v3 integration - DEVICE_SRP_AUTH flow", () => {

// ---------- Remember the device (for easier logins) ----------

const updateDeviceStatusRes = await cognitoIdentityProviderClient.send(
await cognitoIdentityProviderClient.send(
new AdminUpdateDeviceStatusCommand({
UserPoolId: poolId,
Username: USER_ID_FOR_SRP,
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/integration/sdk-v3-standard-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {
CognitoIdentityProviderClient,
InitiateAuthCommand,
RespondToAuthChallengeCommand,
SignUpCommand,
} from "@aws-sdk/client-cognito-identity-provider";
import { faker } from "@faker-js/faker";
import dotenv from "dotenv";
import path from "path";
import RandExp from "randexp";

import {
createPasswordHash,
Expand All @@ -17,8 +18,7 @@ import {
wrapAuthChallenge,
wrapInitiateAuth,
} from "../../cognito-srp-helper";
import { faker } from "@faker-js/faker";
import RandExp from "randexp";

import { signupV3 } from "./helpers";

// Load in env variables from .env if it / they exist..
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/test-cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export * from "./credentials";
export * from "./initiate-auth-request";
export * from "./initiate-auth-response";
export * from "./initiate-auth-response-with-new-device";
export * from "./respond-to-auth-challenge-response";
export * from "./respond-to-auth-challenge-request";
export * from "./respond-to-auth-challenge-response";
export * from "./srp-sessions";
export * from "./srp-sessions-signed";
export * from "./timestamps";
19 changes: 10 additions & 9 deletions src/__tests__/test-cases/respond-to-auth-challenge-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,53 +78,54 @@ export const positiveRespondToAuthChallengeResponses: Record<string, RespondToAu
deviceKeyRandom: mockRespondToAuthChallengeResponseFactory({
ChallengeParameters: {
...ChallengeParameters,
DEVICE_KEY: new RandExp(/^(us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)_$/).gen() + faker.datatype.uuid(),
DEVICE_KEY:
new RandExp(/^(us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)_$/).gen() + faker.datatype.uuid(),
},
}),
// USERNAME
usernameTypical: mockRespondToAuthChallengeResponseFactory({
ChallengeParameters: {
...ChallengeParameters,
USERNAME: faker.internet.userName(),
}
},
}),
usernameEmail: mockRespondToAuthChallengeResponseFactory({
ChallengeParameters: {
...ChallengeParameters,
USERNAME: faker.internet.email(),
}
},
}),
usernameEmailSpecialChars: mockRespondToAuthChallengeResponseFactory({
ChallengeParameters: {
...ChallengeParameters,
USERNAME: faker.internet.email("john", "doe", "example.fakerjs.dev", {
allowSpecialCharacters: true,
}),
}
},
}),
usernamePhone: mockRespondToAuthChallengeResponseFactory({
ChallengeParameters: {
...ChallengeParameters,
USERNAME: faker.phone.number(),
}
},
}),
usernameUuid: mockRespondToAuthChallengeResponseFactory({
ChallengeParameters: {
...ChallengeParameters,
USERNAME: faker.datatype.uuid(),
}
},
}),
usernameSymbols: mockRespondToAuthChallengeResponseFactory({
ChallengeParameters: {
...ChallengeParameters,
USERNAME: faker.datatype.string(),
}
},
}),
usernameEmpty: mockRespondToAuthChallengeResponseFactory({
ChallengeParameters: {
...ChallengeParameters,
USERNAME: "",
}
},
}),
};

Expand Down Expand Up @@ -158,4 +159,4 @@ export const negativeRespondToAuthChallengeResponses: Record<string, RespondToAu
...omit(ChallengeParameters, "DEVICE_KEY"),
},
}),
}
};

0 comments on commit 99956e4

Please sign in to comment.