forked from jagregory/cognito-local
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); | ||
}); | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters