it("GET /uuid (invalid) - returns an 'unauthorized' error", function () { return tinyhttptest({http2: true, url: "https://localhost:" + port + "/uuid"}) .cookies() .expectStatus(302) .expectHeader("location", login) .end(); });
it("PATCH /nothere.html (404 / 'Not Found')", function () { return tinyhttptest({url: "http://localhost:" + port + "/nothere.html", method: "patch"}) .expectStatus(404) .expectHeader("allow", undefined) .expectValue("error", http.STATUS_CODES[404]) .end(); });
it("GET /nothere.x_%22%3E%3Cimg%20src=x%20onerror=prompt(1)%3E.html (404 / 'Not Found')", function () { return tinyhttptest({url: "http://localhost:" + port + "/nothere.x_%22%3E%3Cimg%20src=x%20onerror=prompt(1)%3E.html"}) .expectStatus(404) .expectHeader("allow", undefined) .expectValue("error", http.STATUS_CODES[404]) .end(); });
it("DELETE / (405 / 'Method Not Allowed')", function () { return tinyhttptest({url: "http://localhost:" + port + "/", method: "delete"}) .expectStatus(405) .expectHeader("allow", "GET, HEAD, OPTIONS") .expectValue("error", http.STATUS_CODES[405]) .end(); });
it("GET /././../README (404 / 'Not Found')", function () { return tinyhttptest({url: "http://localhost:" + port + "/././../README"}) .expectStatus(404) .expectHeader("allow", undefined) .expectValue("error", http.STATUS_CODES[404]) .end(); });
it("HEAD / (200 / empty)", function () { return tinyhttptest({url: "http://localhost:8001/", method: "head"}) .expectStatus(200) .expectHeader("allow", "GET, HEAD, OPTIONS") .expectHeader("content-length", /53|58/) // macOS & Windows size on disk .expectBody(/^$/) .end(); });
it("OPTIONS / (200 / empty)", function () { return tinyhttptest({url: "http://localhost:8001/", method: "options"}) .expectStatus(200) .expectHeader("allow", "GET, HEAD, OPTIONS") .expectHeader("content-length", 0) .expectBody(/^$/) .end(); });
it("HEAD / (200 / empty)", function () { return tinyhttptest({url: "http://localhost:" + port + "/", method: "head"}) .expectStatus(200) .expectHeader("allow", "GET, HEAD, OPTIONS") .expectHeader("content-length", 320) .expectBody(/^$/) .end(); });
it("GET / (206 / 'Partial response - bytes=-5')", function () { return tinyhttptest({url: "http://localhost:" + port + "/", headers: {range: "bytes=-5"}}) .expectStatus(206) .expectHeader("content-range", /^bytes 285-290\/290$/) .expectHeader("content-length", undefined) .expectBody(/^:200}$/) .end(); });
it("GET /uuid - returns a uuid (authorized)", function () { return tinyhttptest({http2: true, url: "https://*****:*****@localhost:" + port + "/uuid"}) .expectJson() .expectStatus(200) .expectValue("links", [{uri: "/", rel: "collection"}]) .expectValue("error", null) .expectValue("status", 200) .end(); });
it("GET / (200 / 'Hello World!' - deflate)", function () { return tinyhttptest({url: "http://localhost:8001/", headers: {"accept-encoding": "deflate"}}) .expectStatus(200) .expectHeader("content-encoding", "deflate") .expectHeader("allow", "GET, HEAD, OPTIONS") .expectHeader("transfer-encoding", "chunked") .expectHeader("content-length", undefined) .end(); });
it("GET /invalid - returns a 'not found' error", function () { return tinyhttptest({http2: true, url: "https://localhost:" + port + "/invalid"}) .expectJson() .expectStatus(404) .expectValue("data", null) .expectValue("error", "Not Found") .expectValue("status", 404) .end(); });
it("GET / (206 / 'Partial response - offset')", function () { return tinyhttptest({url: "http://localhost:8001/", headers: {range: "2-4"}}) .expectStatus(206) .expectHeader("transfer-encoding", "chunked") .expectHeader("content-range", /^bytes 2-4\/5(3|8)$/) .expectHeader("content-length", undefined) .expectBody(/^tml$/) .end(); });
it("GET / (304 / empty & validation)", function () { return tinyhttptest({url: "http://localhost:8001/", headers: {"If-None-Match": etagValue}}) .expectStatus(304) .expectHeader("Age", /\d+/) .expectHeader("Content-Length", void 0) .expectHeader("ETag", etagValue) .expectBody(/^$/) .end(); });
it("PATCH / - returns a 'method not allowed' error", function () { return tinyhttptest({http2: true, url: "https://localhost:" + port, method: "patch"}) .expectJson() .expectStatus(405) .expectValue("data", null) .expectValue("error", "Method Not Allowed") .expectValue("status", 405) .end(); });
it("GET /null (200 / 'null')", function () { return tinyhttptest({url: "http://localhost:" + port + "/null"}) .expectStatus(200) .expectHeader("allow", "GET, HEAD, OPTIONS") .expectValue("data", null) .expectValue("error", null) .expectValue("status", 200) .end(); });
it("GET / (304 / empty - ETag reuse)", function () { return tinyhttptest({url: "http://localhost:" + port + "/"}) .etags() .expectStatus(304) .expectHeader("allow", "GET, HEAD, OPTIONS") .expectHeader("content-length", undefined) .expectBody(/^$/) .end(); });
it("HEAD /no-cache (200 / 'Success' / No Etag)", function () { return tinyhttptest({url: "http://localhost:8001/no-cache", method: "head"}) .expectStatus(200) .expectHeader("Allow", "GET, HEAD, OPTIONS") .expectHeader("Cache-Control", "no-cache") .expectHeader("Content-Type", "text/plain") .expectHeader("ETag", void 0) .expectBody(/^$/) .end(); });
it("POST /auth/login (invalid / no CSRF token) - returns an 'unauthorized' error", function () { return tinyhttptest({http2: true, url: "https://localhost:" + port + login, method: "post"}) .cookies() .json({username: "******", password: invalid}) .expectStatus(403) .expectValue("data", null) .expectValue("error", "CSRF token missing") .expectValue("status", 403) .end(); });
it("POST /auth/login - redirects to a predetermined URI", function () { return tinyhttptest({http2: true, url: "https://localhost:" + port + login, method: "post"}) .cookies() .reuseHeader(csrf) .json({username: "******", password: valid}) .expectStatus(302) .expectHeader("content-type", undefined) .expectHeader("location", "/") .end(); });
it("GET / (200 / 'Hello World!')", function () { return tinyhttptest({url: "http://localhost:8001/"}) .etags() .expectStatus(200) .expectHeader("allow", "GET, HEAD, OPTIONS") .expectHeader("transfer-encoding", "chunked") .expectHeader("content-length", undefined) .expectBody(/Hello world!/) .end(); });
it("GET / (200 / 'Success' / No Etag)", function () { return tinyhttptest({url: "http://localhost:8001/"}) .expectStatus(200) .expectHeader("Allow", "GET, HEAD, OPTIONS") .expectHeader("Cache-Control", "public") .expectHeader("Content-Type", "text/plain") .expectHeader("ETag", etagValue) .expectBody(/^Hello World!$/) .end(); });
it("GET /uuid (session) - returns a version 4 uuid", function () { return tinyhttptest({http2: true, url: "https://localhost:" + port + "/uuid"}) .cookies() .expectStatus(200) .expectJson() .expectValue("links", [{uri: "/", rel: "collection"}]) .expectValue("error", null) .expectValue("status", 200) .end(); });
it("OPTIONS / (200 / empty)", function () { return tinyhttptest({url: "http://localhost:" + port + "/", method: "options"}) .expectStatus(200) .expectHeader("allow", "GET, HEAD, OPTIONS") .expectHeader("content-length", 320) .expectValue("data", /\w/) .expectValue("error", null) .expectValue("status", 200) .end(); });
it("GET /auth/login - returns an authentication message", function () { return tinyhttptest({http2: true, url: "https://localhost:" + port + login}) .cookies() .captureHeader(csrf) .expectJson() .expectStatus(200) .expectValue("links", [{ "uri": "/auth", "rel": "collection" }]) .expectValue("data", {instruction: "POST 'username' & 'password' to authenticate"}) .expectValue("error", null) .expectValue("status", 200) .end(); });
it("GET / - returns links", function () { return tinyhttptest({http2: true, url: "https://localhost:" + port}) .expectJson() .expectStatus(200) .expectValue("links", [{uri: "/empty", rel: "item"}, {uri: "/items", rel: "item"}, {uri: "/somethings", rel: "item"}, {uri: "/test", rel: "item"}, {uri: "/things", rel: "item"}, {uri: "/?page=2&page_size=5", rel: "last"}]) .expectValue("data", ["empty", "items", "somethings", "test", "things"]) .expectValue("error", null) .expectValue("status", 200) .end(); });
it("GET / - returns an array of endpoints (authorized)", function () { return tinyhttptest({http2: true, url: "https://localhost:" + port, headers: {authorization: "Bearer abc-123"}}) .expectJson() .expectStatus(200) .expectValue("links", [{uri: "/empty", rel: "item"}, {uri: "/items", rel: "item"}, {uri: "/somethings", rel: "item"}, {uri: "/test", rel: "item"}, {uri: "/things", rel: "item"}, {uri: "/?page=2&page_size=5", rel: "last"}]) .expectValue("data", ["empty", "items", "somethings", "test", "things"]) .expectValue("error", null) .expectValue("status", 200) .end(); });
it("GET /sample/ (200 / HTML)", function () { return tinyhttptest({url: "http://localhost:" + port + "/sample/"}) .expectStatus(200) .expectHeader("allow", "GET, HEAD, OPTIONS") .end(); });
it("GET /sample (200 / redirect)", function () { return tinyhttptest({url: "http://localhost:" + port + "/sample"}) .expectStatus(301) .expectHeader("location", "/sample/") .end(); });
it("GET / (200 / 'Array' - ETag capture)", function () { return tinyhttptest({url: "http://localhost:" + port + "/"}) .etags() .expectStatus(200) .end(); });