Skip to content

Commit

Permalink
fix(api): respondToAuthChallenge throws if missing ChallengeResponses
Browse files Browse the repository at this point in the history
Correctly throws an InvalidParameterError instead of an UnsupportedError when ChallengeResponses is missing
  • Loading branch information
jagregory committed Nov 25, 2021
1 parent 6703ea9 commit 5e5aa36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/targets/respondToAuthChallenge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import jwt from "jsonwebtoken";
import { ClockFake } from "../__tests__/clockFake";
import { MockUserPoolClient } from "../__tests__/mockUserPoolClient";
import { UUID } from "../__tests__/patterns";
import { CodeMismatchError, NotAuthorizedError } from "../errors";
import {
CodeMismatchError,
InvalidParameterError,
NotAuthorizedError,
} from "../errors";
import PublicKey from "../keys/cognitoLocal.public.json";
import { CognitoClient } from "../services";
import {
Expand Down Expand Up @@ -48,6 +52,19 @@ describe("RespondToAuthChallenge target", () => {
).rejects.toBeInstanceOf(NotAuthorizedError);
});

it("throws if ChallengeResponses missing", async () => {
await expect(
respondToAuthChallenge({
ClientId: "clientId",
ChallengeName: "SMS_MFA",
})
).rejects.toEqual(
new InvalidParameterError(
"Missing required parameter challenge responses"
)
);
});

describe("when code matches", () => {
it("generates tokens", async () => {
MockUserPoolClient.getUserByUsername.mockResolvedValue({
Expand Down
5 changes: 3 additions & 2 deletions src/targets/respondToAuthChallenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from "aws-sdk/clients/cognitoidentityserviceprovider";
import {
CodeMismatchError,
InvalidParameterError,
NotAuthorizedError,
UnsupportedError,
} from "../errors";
Expand All @@ -22,8 +23,8 @@ export const RespondToAuthChallenge = ({
"cognitoClient" | "clock"
>): RespondToAuthChallengeTarget => async (req) => {
if (!req.ChallengeResponses) {
throw new UnsupportedError(
"RespondToAuthChallenge without ChallengeResponses"
throw new InvalidParameterError(
"Missing required parameter challenge responses"
);
}

Expand Down

0 comments on commit 5e5aa36

Please sign in to comment.