Skip to content

Commit

Permalink
Merge pull request #57 from alphagov/add-tld-redirect-tests
Browse files Browse the repository at this point in the history
Enable tld redirect tests for staging and integration
  • Loading branch information
theseanything authored Oct 21, 2024
2 parents c0797d4 + ccaa3b8 commit 167143f
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions tests/cdn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,33 @@ test.describe("CDN", { tag: ["@domain-www"] }, () => {
expect(parseInt(response.headers()["x-cache-hits"])).toBeGreaterThan(0);
});

test("https upgrade for apex domain", { tag: ["@production"] }, async ({ page }) => {
const response = await page.request.get("http://gov.uk", { maxRedirects: 0 });
test("https upgrade for apex domain", async ({ page }) => {
const url = `http://${process.env.PUBLIC_DOMAIN.replace("www.", "")}/`;
const expectedURL = url.replace("http://", "https://");

const response = await page.request.get(url, { maxRedirects: 0 });
expect(response.status()).toBe(301);
expect(response.headers()["location"]).toBe("https://gov.uk/");
expect(response.headers()["location"]).toBe(expectedURL);
});

test("redirect apex domain to www domain", { tag: ["@production"] }, async ({ page }) => {
const response = await page.request.get("https://gov.uk", { maxRedirects: 0 });
test("redirect apex domain to www domain", async ({ page }) => {
const expectedURL = `https://${process.env.PUBLIC_DOMAIN}/`;
const url = expectedURL.replace("www.", "");

const response = await page.request.get(url, { maxRedirects: 0 });
expect(response.status()).toBe(301);
expect(response.headers()["location"]).toBe("https://www.gov.uk/");
expect(response.headers()["location"]).toBe(expectedURL);
expect(response.headers()["strict-transport-security"]).toBe("max-age=63072000; preload");
});

test("https upgrade for www domain", { tag: ["@production"] }, async ({ page }) => {
const response = await page.request.get("http://www.gov.uk", { maxRedirects: 0 });
test("https upgrade for www domain", async ({ page }) => {
const url = `http://${process.env.PUBLIC_DOMAIN}/`;
const expectedURL = url.replace("http://", "https://");
console.log(url, expectedURL);

const response = await page.request.get(url, { maxRedirects: 0 });
expect(response.status()).toBe(301);
expect(response.headers()["location"]).toBe("https://www.gov.uk/");
expect(response.headers()["location"]).toBe(expectedURL);
});

test("redirect service domain to www domain", { tag: ["@production"] }, async ({ page }) => {
Expand Down

0 comments on commit 167143f

Please sign in to comment.