Skip to content

Commit

Permalink
feat: support getUserPoolMfaConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jagregory committed May 30, 2022
1 parent 76d664b commit 416ea1d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ A _Good Enough_ offline emulator for [Amazon Cognito](https://aws.amazon.com/cog
| GetUICustomization ||
| GetUser ||
| GetUserAttributeVerificationCode ||
| GetUserPoolMfaConfig | |
| GetUserPoolMfaConfig | |
| GlobalSignOut ||
| InitiateAuth | 🕒 (partial support) |
| ListDevices ||
Expand Down
34 changes: 34 additions & 0 deletions integration-tests/aws-sdk/getUserPoolMfaConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { withCognitoSdk } from "./setup";

describe(
"CognitoIdentityServiceProvider.getUserPoolMfaConfig",
withCognitoSdk((Cognito) => {
it("gets the user pool MFA config", async () => {
const client = Cognito();

const up = await client
.createUserPool({
PoolName: "pool",
MfaConfiguration: "OPTIONAL",
SmsAuthenticationMessage: "hello, world!",
})
.promise();

const getResponse = await client
.getUserPoolMfaConfig({
UserPoolId: up.UserPool?.Id!,
})
.promise();

expect(getResponse).toEqual({
MfaConfiguration: "OPTIONAL",
SmsMfaConfiguration: {
SmsAuthenticationMessage: "hello, world!",
},
SoftwareTokenMfaConfiguration: {
Enabled: false,
},
});
});
})
);
52 changes: 52 additions & 0 deletions src/targets/getUserPoolMfaConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { newMockCognitoService } from "../__tests__/mockCognitoService";
import { newMockUserPoolService } from "../__tests__/mockUserPoolService";
import { TestContext } from "../__tests__/testContext";
import { UserPoolService } from "../services";
import * as TDB from "../__tests__/testDataBuilder";
import {
GetUserPoolMfaConfig,
GetUserPoolMfaConfigTarget,
} from "./getUserPoolMfaConfig";

describe("GetUserPoolMfaConfig target", () => {
let getUserPoolMfaConfig: GetUserPoolMfaConfigTarget;
let mockUserPoolService: jest.Mocked<UserPoolService>;

const userPool = TDB.userPool({
MfaConfiguration: "ON",
SmsAuthenticationMessage: "hello, world!",
SmsConfiguration: {
ExternalId: "abc",
SnsCallerArn: "arn",
SnsRegion: "region",
},
});

beforeEach(() => {
mockUserPoolService = newMockUserPoolService(userPool);
getUserPoolMfaConfig = GetUserPoolMfaConfig({
cognito: newMockCognitoService(mockUserPoolService),
});
});

it("returns the user pool's MFA config", async () => {
const output = await getUserPoolMfaConfig(TestContext, {
UserPoolId: "test",
});

expect(output).toEqual({
MfaConfiguration: "ON",
SmsMfaConfiguration: {
SmsAuthenticationMessage: "hello, world!",
SmsConfiguration: {
ExternalId: "abc",
SnsCallerArn: "arn",
SnsRegion: "region",
},
},
SoftwareTokenMfaConfiguration: {
Enabled: false,
},
});
});
});
30 changes: 30 additions & 0 deletions src/targets/getUserPoolMfaConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
GetUserPoolMfaConfigRequest,
GetUserPoolMfaConfigResponse,
} from "aws-sdk/clients/cognitoidentityserviceprovider";
import { Services } from "../services";
import { Target } from "./Target";

export type GetUserPoolMfaConfigTarget = Target<
GetUserPoolMfaConfigRequest,
GetUserPoolMfaConfigResponse
>;

type GetUserPoolMfaConfigServices = Pick<Services, "cognito">;

export const GetUserPoolMfaConfig =
({ cognito }: GetUserPoolMfaConfigServices): GetUserPoolMfaConfigTarget =>
async (ctx, req) => {
const userPool = await cognito.getUserPool(ctx, req.UserPoolId);

return {
MfaConfiguration: userPool.options.MfaConfiguration,
SmsMfaConfiguration: {
SmsAuthenticationMessage: userPool.options.SmsAuthenticationMessage,
SmsConfiguration: userPool.options.SmsConfiguration,
},
SoftwareTokenMfaConfiguration: {
Enabled: false,
},
};
};
2 changes: 2 additions & 0 deletions src/targets/targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ForgotPassword } from "./forgotPassword";
import { GetGroup } from "./getGroup";
import { GetUser } from "./getUser";
import { GetUserAttributeVerificationCode } from "./getUserAttributeVerificationCode";
import { GetUserPoolMfaConfig } from "./getUserPoolMfaConfig";
import { InitiateAuth } from "./initiateAuth";
import { ListGroups } from "./listGroups";
import { ListUserPoolClients } from "./listUserPoolClients";
Expand Down Expand Up @@ -75,6 +76,7 @@ export const Targets = {
GetGroup,
GetUser,
GetUserAttributeVerificationCode,
GetUserPoolMfaConfig,
InitiateAuth,
ListGroups,
ListUserPoolClients,
Expand Down

0 comments on commit 416ea1d

Please sign in to comment.