Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs-component, e2e-tests): allow all CloudFront HTTP methods for default caching behavior #609

Merged
merged 1 commit into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/e2e-tests/next-app/cypress/integration/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ describe("Pages Tests", () => {

cy.visit(path);
});

["HEAD", "DELETE", "POST", "GET", "OPTIONS", "PUT", "PATCH"].forEach(
(method) => {
it(`allows HTTP method: ${method}`, () => {
cy.request({ url: path, method: method }).then((response) => {
expect(response.status).to.equal(200);
});
});
}
);
});
});

Expand All @@ -31,6 +41,16 @@ describe("Pages Tests", () => {

cy.visit(path);
});

["HEAD", "DELETE", "POST", "GET", "OPTIONS", "PUT", "PATCH"].forEach(
(method) => {
it(`allows HTTP method: ${method}`, () => {
cy.request({ url: path, method: method }).then((response) => {
expect(response.status).to.equal(200);
});
});
}
);
});
});

Expand All @@ -43,6 +63,27 @@ describe("Pages Tests", () => {
cy.ensureRouteCached(path);
cy.visit(path);
});

["HEAD", "GET"].forEach((method) => {
it(`allows HTTP method: ${method}`, () => {
cy.request({ url: path, method: method }).then((response) => {
expect(response.status).to.equal(200);
});
});
});

["DELETE", "POST", "OPTIONS", "PUT", "PATCH"].forEach((method) => {
it(`disallows HTTP method with 4xx error: ${method}`, () => {
cy.request({
url: path,
method: method,
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.be.at.least(400);
expect(response.status).to.be.lessThan(500);
});
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe("Caching Tests", () => {
describe("Static Files Tests", () => {
before(() => {
cy.ensureAllRoutesNotErrored();
});
Expand All @@ -17,7 +17,7 @@ describe("Caching Tests", () => {
});
});

describe("public files are cached", () => {
describe("public files", () => {
[{ path: "/app-store-badge.png" }].forEach(({ path }) => {
it(`serves and caches file ${path}`, () => {
// Request once to ensure cached
Expand All @@ -27,6 +27,27 @@ describe("Caching Tests", () => {
expect(response.headers["x-cache"]).to.equal("Hit from cloudfront");
});
});

["HEAD", "GET"].forEach((method) => {
it(`allows HTTP method: ${method}`, () => {
cy.request({ url: path, method: method }).then((response) => {
expect(response.status).to.equal(200);
});
});
});

["DELETE", "POST", "OPTIONS", "PUT", "PATCH"].forEach((method) => {
it(`disallows HTTP method with 4xx error: ${method}`, () => {
cy.request({
url: path,
method: method,
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.be.at.least(400);
expect(response.status).to.be.lessThan(500);
});
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,15 @@ describe("Custom inputs", () => {
minTTL: 0,
defaultTTL: 0,
maxTTL: 31536000,
allowedHttpMethods: ["HEAD", "GET"],
allowedHttpMethods: [
"HEAD",
"DELETE",
"POST",
"GET",
"OPTIONS",
"PUT",
"PATCH"
],
forward: {
cookies: "all",
queryString: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,15 @@ class NextjsComponent extends Component {
...cloudFrontDefaults.forward
},
// everything after here cant be overridden
allowedHttpMethods: ["HEAD", "GET"],
allowedHttpMethods: [
"HEAD",
"DELETE",
"POST",
"GET",
"OPTIONS",
"PUT",
"PATCH"
],
"lambda@edge": {
...defaultLambdaAtEdgeConfig,
"origin-request": `${defaultEdgeLambdaOutputs.arn}:${defaultEdgeLambdaPublishOutputs.version}`,
Expand Down