Skip to content

Commit 7b65333

Browse files
VIA-757 AJ Fix test environment to not use NONCE
1 parent 973128b commit 7b65333

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/app/api/auth/[...nextauth]/provider.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import NHSLoginAuthProvider from "@src/app/api/auth/[...nextauth]/provider";
2+
import { DeployEnvironment } from "@src/types/environments";
23
import config from "@src/utils/config";
34
import { ConfigMock, configBuilder } from "@test-data/config/builders";
45

@@ -10,7 +11,10 @@ describe("provider", () => {
1011

1112
describe("not using fake NHS login", () => {
1213
beforeEach(() => {
13-
const defaultConfig = configBuilder().withNhsLoginUrl(new URL("https://abc")).build();
14+
const defaultConfig = configBuilder()
15+
.withNhsLoginUrl(new URL("https://abc"))
16+
.andDeployEnvironment(DeployEnvironment.preprod)
17+
.build();
1418
Object.assign(mockedConfig, defaultConfig);
1519
});
1620

@@ -24,12 +28,16 @@ describe("provider", () => {
2428
});
2529

2630
describe("using fake NHS login", () => {
27-
beforeEach(() => {
31+
it("should not use NONCE check when using fake login port", async () => {
2832
const defaultConfig = configBuilder().withNhsLoginUrl(new URL("https://abc:9123")).build();
2933
Object.assign(mockedConfig, defaultConfig);
34+
const provider = await NHSLoginAuthProvider();
35+
expect(provider.checks).toEqual(["state"]);
3036
});
3137

32-
it("should not use NONCE check", async () => {
38+
it("should not use NONCE check when in test environment", async () => {
39+
const defaultConfig = configBuilder().withDeployEnvironment(DeployEnvironment.test).build();
40+
Object.assign(mockedConfig, defaultConfig);
3341
const provider = await NHSLoginAuthProvider();
3442
expect(provider.checks).toEqual(["state"]);
3543
});

src/app/api/auth/[...nextauth]/provider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { OIDCConfig } from "@auth/core/providers";
2+
import { DeployEnvironment } from "@src/types/environments";
23
import pemToCryptoKey from "@src/utils/auth/pem-to-crypto-key";
34
import config from "@src/utils/config";
45
import { Profile } from "next-auth";
56

67
export const NHS_LOGIN_PROVIDER_ID = "nhs-login";
78

89
const NHSLoginAuthProvider = async (): Promise<OIDCConfig<Profile>> => {
9-
const usingFakeLogin: boolean = (await config.NHS_LOGIN_URL).port === "9123";
10+
const usingFakeLogin: boolean =
11+
(await config.DEPLOY_ENVIRONMENT) === DeployEnvironment.test || (await config.NHS_LOGIN_URL).port === "9123";
1012

1113
return {
1214
id: NHS_LOGIN_PROVIDER_ID,

0 commit comments

Comments
 (0)