Skip to content

Commit 53f5b42

Browse files
Revert "SB Fix sonarqube warnings - introduce URL objects rather than strings."
This reverts commit 881b096.
1 parent 881b096 commit 53f5b42

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

src/middleware.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,40 @@ jest.mock("@src/utils/config");
1717
const middlewareRegex = new RegExp(config.matcher[0]);
1818
const otherExcludedPaths = ["/favicon.ico", "/assets", "/js", "/css", "/_next"];
1919

20-
function getMockRequest(testUrl: URL) {
20+
function getMockRequest(testUrl: string) {
2121
return {
2222
nextUrl: {
23-
origin: testUrl.origin,
24-
pathname: testUrl.pathname,
23+
origin: new URL(testUrl).origin,
24+
pathname: new URL(testUrl).pathname,
2525
},
26-
url: testUrl.href,
26+
url: testUrl,
2727
};
2828
}
2929

3030
describe("middleware", () => {
3131
beforeEach(() => {
3232
(configProvider as jest.Mock).mockImplementation(
3333
(): Partial<AppConfig> => ({
34-
NHS_APP_REDIRECT_LOGIN_URL: new URL("https://nhs-app-redirect-login-url"),
34+
NHS_APP_REDIRECT_LOGIN_URL: "https://nhs-app-redirect-login-url",
3535
}),
3636
);
3737
jest.clearAllMocks();
3838
});
3939

4040
it("redirects users without active session to session-logout page", async () => {
41-
const testUrl = new URL("https://nhs-app-redirect-login-url/");
41+
const testUrl = "https://nhs-app-redirect-login-url/";
4242
const mockRequest = getMockRequest(testUrl);
4343

4444
(auth as jest.Mock).mockResolvedValue(null); // No authenticated session
4545

4646
const result = await middleware(mockRequest as NextRequest);
4747

4848
expect(result.status).toBe(307);
49-
expect(result.headers.get("Location")).toEqual(testUrl.href);
49+
expect(result.headers.get("Location")).toEqual(testUrl);
5050
});
5151

5252
it("pass through for users with active session", async () => {
53-
const testUrl = new URL("https://testurl/abc");
53+
const testUrl = "https://testurl/abc";
5454
const mockRequest = getMockRequest(testUrl);
5555

5656
(auth as jest.Mock).mockResolvedValue({ user: "test" });

src/utils/config.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe("configProvider", () => {
1717
process.env.SSM_PREFIX = prefix;
1818
process.env.CONTENT_API_ENDPOINT = "https://api-endpoint";
1919
process.env.ELIGIBILITY_API_ENDPOINT = "https://elid-endpoint";
20-
process.env.NHS_APP_REDIRECT_LOGIN_URL = "https://app-redirect-login-endpoint";
2120
const mockGetSSMParam = (getSSMParam as jest.Mock).mockResolvedValue("api-key");
2221

2322
const config: AppConfig = await configProvider();

src/utils/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type AppConfig = {
1313
NBS_URL: string;
1414
NBS_BOOKING_PATH: string;
1515
MAX_SESSION_AGE_MINUTES: number;
16-
NHS_APP_REDIRECT_LOGIN_URL: URL;
16+
NHS_APP_REDIRECT_LOGIN_URL: string;
1717
};
1818

1919
const configProvider = async (): Promise<AppConfig> => {
@@ -25,7 +25,7 @@ const configProvider = async (): Promise<AppConfig> => {
2525
ELIGIBILITY_API_KEY: await getFromEnvironmentOrSSM(SSM_PREFIX, "ELIGIBILITY_API_KEY"),
2626
CONTENT_CACHE_PATH: await getFromEnvironmentOrSSM(SSM_PREFIX, "CONTENT_CACHE_PATH"),
2727
NHS_LOGIN_URL: await getFromEnvironmentOrSSM(SSM_PREFIX, "NHS_LOGIN_URL"),
28-
NHS_APP_REDIRECT_LOGIN_URL: await getUrlFromEnvironmentOrSSM(SSM_PREFIX, "NHS_APP_REDIRECT_LOGIN_URL"),
28+
NHS_APP_REDIRECT_LOGIN_URL: await getFromEnvironmentOrSSM(SSM_PREFIX, "NHS_APP_REDIRECT_LOGIN_URL"),
2929
NHS_LOGIN_CLIENT_ID: await getFromEnvironmentOrSSM(SSM_PREFIX, "NHS_LOGIN_CLIENT_ID"),
3030
NHS_LOGIN_SCOPE: await getFromEnvironmentOrSSM(SSM_PREFIX, "NHS_LOGIN_SCOPE"),
3131
NHS_LOGIN_PRIVATE_KEY: await getFromEnvironmentOrSSM(SSM_PREFIX, "NHS_LOGIN_PRIVATE_KEY"),

test-data/config/builders.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function appConfigBuilder() {
1414
NHS_LOGIN_PRIVATE_KEY: randomString(10),
1515
NBS_URL: randomString(10),
1616
NBS_BOOKING_PATH: randomString(10),
17-
NHS_APP_REDIRECT_LOGIN_URL: randomURL(),
17+
NHS_APP_REDIRECT_LOGIN_URL: randomString(10),
1818
MAX_SESSION_AGE_MINUTES: randomInteger(1, 999),
1919
});
2020
}

0 commit comments

Comments
 (0)