-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
de2733b
commit 2d49656
Showing
4 changed files
with
43 additions
and
53 deletions.
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
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 |
---|---|---|
|
@@ -184,31 +184,6 @@ describe("Integration::enter email (create account)", () => { | |
.expect(302, done); | ||
}); | ||
|
||
it("should redirect to /signed-out with login_required error when user fails re-auth", (done) => { | ||
process.env.SUPPORT_REAUTHENTICATION = "1"; | ||
|
||
nock(baseApi) | ||
.post(API_ENDPOINTS.CHECK_REAUTH_USER) | ||
.once() | ||
.reply(HTTP_STATUS_CODES.BAD_REQUEST, { | ||
code: ERROR_CODES.RE_AUTH_SIGN_IN_DETAILS_ENTERED_EXCEEDED, | ||
}); | ||
|
||
request(app) | ||
.post(PATH_NAMES.ENTER_EMAIL_SIGN_IN) | ||
.type("form") | ||
.set("Cookie", cookies) | ||
.send({ | ||
_csrf: token, | ||
email: "[email protected]", | ||
}) | ||
.expect( | ||
"Location", | ||
PATH_NAMES["SIGNED_OUT"].concat("?error=login_required") | ||
) | ||
.expect(302, done); | ||
}); | ||
|
||
it("should return internal server error when /user-exists API call response is 500", (done) => { | ||
nock(baseApi).post(API_ENDPOINTS.USER_EXISTS).once().reply(500, { | ||
message: "Internal Server error", | ||
|
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 |
---|---|---|
|
@@ -8,11 +8,8 @@ import { | |
HTTP_STATUS_CODES, | ||
PATH_NAMES, | ||
} from "../../../app.constants"; | ||
import { CheckReauthServiceInterface } from "../../check-reauth-users/types"; | ||
import { AxiosResponse } from "axios"; | ||
import { createApiResponse } from "../../../utils/http"; | ||
import { DefaultApiResponse } from "../../../types"; | ||
import nock = require("nock"); | ||
import { ERROR_CODES } from "../../common/constants"; | ||
|
||
describe("Integration::enter email", () => { | ||
let token: string | string[]; | ||
|
@@ -24,7 +21,6 @@ describe("Integration::enter email", () => { | |
decache("../../../app"); | ||
decache("../../../middleware/session-middleware"); | ||
const sessionMiddleware = require("../../../middleware/session-middleware"); | ||
const checkReauthUsersService = require("../../check-reauth-users/check-reauth-users-service"); | ||
|
||
sinon | ||
.stub(sessionMiddleware, "validateSessionMiddleware") | ||
|
@@ -42,26 +38,12 @@ describe("Integration::enter email", () => { | |
next(); | ||
}); | ||
|
||
sinon | ||
.stub(checkReauthUsersService, "checkReauthUsersService") | ||
.callsFake((): CheckReauthServiceInterface => { | ||
async function checkReauthUsers() { | ||
const fakeAxiosResponse: AxiosResponse = { | ||
status: HTTP_STATUS_CODES.OK, | ||
} as AxiosResponse; | ||
|
||
return createApiResponse<DefaultApiResponse>(fakeAxiosResponse); | ||
} | ||
|
||
return { checkReauthUsers }; | ||
}); | ||
|
||
app = await require("../../../app").createApp(); | ||
baseApi = process.env.FRONTEND_API_BASE_URL; | ||
|
||
request(app) | ||
await request(app) | ||
.get(PATH_NAMES.ENTER_EMAIL_SIGN_IN) | ||
.end((err, res) => { | ||
.then((res) => { | ||
const $ = cheerio.load(res.text); | ||
token = $("[name=_csrf]").val(); | ||
cookies = res.headers["set-cookie"]; | ||
|
@@ -247,4 +229,34 @@ describe("Integration::enter email", () => { | |
.expect("Location", PATH_NAMES.ENTER_PASSWORD) | ||
.expect(302, done); | ||
}); | ||
|
||
it("should redirect to /signed-out with login_required error when user fails re-auth", async () => { | ||
process.env.SUPPORT_REAUTHENTICATION = "1"; | ||
|
||
nock(baseApi) | ||
.post(API_ENDPOINTS.CHECK_REAUTH_USER) | ||
.once() | ||
.reply(HTTP_STATUS_CODES.BAD_REQUEST, { | ||
code: ERROR_CODES.RE_AUTH_SIGN_IN_DETAILS_ENTERED_EXCEEDED, | ||
}); | ||
|
||
nock(baseApi) | ||
.post(API_ENDPOINTS.USER_EXISTS) | ||
.once() | ||
.reply(HTTP_STATUS_CODES.OK, { | ||
email: "[email protected]", | ||
doesUserExist: true, | ||
}); | ||
|
||
await request(app) | ||
.post(PATH_NAMES.ENTER_EMAIL_SIGN_IN) | ||
.type("form") | ||
.set("Cookie", cookies) | ||
.send({ | ||
_csrf: token, | ||
email: "[email protected]", | ||
}) | ||
.expect("Location", PATH_NAMES.SIGNED_OUT.concat("?error=login_required")) | ||
.expect(302); | ||
}); | ||
}); |