Skip to content

Commit

Permalink
Add bracket tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Dec 30, 2023
1 parent bcbb096 commit 3d42aec
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,70 @@ describe("follow-redirects", function () {
});
});

it("http.get to IPv4 address", function () {
app.get("/a", redirectsTo("/b"));
app.get("/b", redirectsTo("/c"));
app.get("/c", redirectsTo("/d"));
app.get("/d", redirectsTo("/e"));
app.get("/e", redirectsTo("/f"));
app.get("/f", sendsJson({ a: "b" }));

return server.start(app)
.then(asPromise(function (resolve, reject) {
http.get("http://127.0.0.1:3600/a", concatJson(resolve, reject)).on("error", reject);
}))
.then(function (res) {
assert.deepEqual(res.parsedJson, { a: "b" });
assert.deepEqual(res.responseUrl, "http://127.0.0.1:3600/f");
});
});

it("http.get to IPv6 address", function () {
app.get("/a", redirectsTo("/b"));
app.get("/b", redirectsTo("/c"));
app.get("/c", redirectsTo("/d"));
app.get("/d", redirectsTo("/e"));
app.get("/e", redirectsTo("/f"));
app.get("/f", sendsJson({ a: "b" }));

return server.start(app)
.then(asPromise(function (resolve, reject) {
http.get("http://[::1]:3600/a", concatJson(resolve, reject)).on("error", reject);
}))
.then(function (res) {
assert.deepEqual(res.parsedJson, { a: "b" });
assert.deepEqual(res.responseUrl, "http://[::1]:3600/f");
});
});

it("http.get redirecting to IPv4 address", function () {
app.get("/a", redirectsTo("http://127.0.0.1:3600/b"));
app.get("/b", sendsJson({ a: "b" }));

return server.start(app)
.then(asPromise(function (resolve, reject) {
http.get("http://localhost:3600/a", concatJson(resolve, reject)).on("error", reject);
}))
.then(function (res) {
assert.deepEqual(res.parsedJson, { a: "b" });
assert.deepEqual(res.responseUrl, "http://127.0.0.1:3600/b");
});
});

it("http.get redirecting to IPv6 address", function () {
app.get("/a", redirectsTo("http://[::1]:3600/b"));
app.get("/b", sendsJson({ a: "b" }));

return server.start(app)
.then(asPromise(function (resolve, reject) {
http.get("http://localhost:3600/a", concatJson(resolve, reject)).on("error", reject);
}))
.then(function (res) {
assert.deepEqual(res.parsedJson, { a: "b" });
assert.deepEqual(res.responseUrl, "http://[::1]:3600/b");
});
});

it("http.get with response event", function () {
app.get("/a", redirectsTo("/b"));
app.get("/b", redirectsTo("/c"));
Expand Down

0 comments on commit 3d42aec

Please sign in to comment.