Skip to content

Commit

Permalink
feat(proxy): Allow https with non-https target - fixes #1175
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Sep 5, 2016
1 parent 5fcd12f commit 80c091d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 51 deletions.
6 changes: 0 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,6 @@ var utils = {
errors.push(messages["server+proxy"]);
}

if (options.get("https") && options.get("proxy")) {
if (options.getIn(["proxy", "url", "protocol"]) !== "https:") {
errors.push([messages["proxy+https"], options.getIn(["proxy", "target"])].join(" "));
}
}

return errors;
},
/**
Expand Down
104 changes: 59 additions & 45 deletions test/specs/e2e/proxy/e2e.proxy.secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ describe("E2E TLS proxy test", function () {

this.timeout(15000);

var bs, app;

before(function (done) {

it("Set's a HTTPS url", function (done) {
browserSync.reset();

app = testUtils.getApp(Immutable.Map({scheme: "https"}));
var app = testUtils.getApp(Immutable.Map({scheme: "https"}));

app.server.listen();

Expand All @@ -28,66 +25,83 @@ describe("E2E TLS proxy test", function () {
logLevel: "silent"
};

bs = browserSync.init(config, done).instance;
});
browserSync.init(config, function (err, bs) {
bs.cleanup();
app.server.close();

after(function () {
bs.cleanup();
app.server.close();
});
var local = bs.options.getIn(["urls", "local"]);
assert.equal("https://localhost:" + bs.options.get("port"), local);

it("Set's a HTTPS url", function () {
var local = bs.options.getIn(["urls", "local"]);
assert.equal("https://localhost:" + bs.options.get("port"), local);
done();
});
});

it("proxies over https and injects snippet", function (done) {
it("Set's a HTTPS url with none-https proxy target", function (done) {
browserSync.reset();

assert.isString(bs.options.get("snippet"));
var app = testUtils.getApp(Immutable.Map({scheme: "http"}));

var expected = app.html.replace("BS", bs.options.get("snippet") + "BS");
app.server.listen();

request(bs.options.getIn(["urls", "local"]))
.get("/index.html")
.set("accept", "text/html")
.expect(200, expected, done);
});
});
var config = {
proxy: "http://localhost:" + app.server.address().port,
open: false,
logLevel: "silent",
https: true
};

describe("E2E TLS proxy Options test", function () {
browserSync.init(config, function (err, bs) {

this.timeout(15000);
if (err) {
throw err;
}

var app;
var local = bs.options.getIn(["urls", "local"]);
var expected = app.html.replace("BS", bs.options.get("snippet") + "BS");

before(function () {
assert.equal("https://localhost:" + bs.options.get("port"), local);

request(bs.options.getIn(["urls", "local"]))
.get("/index.html")
.set("accept", "text/html")
.expect(200, function (err, res) {
assert.equal(res.text, expected);
bs.cleanup();
app.server.close();
done();
});
});
});

it("proxies over https and injects snippet", function (done) {

browserSync.reset();

app = testUtils.getApp(Immutable.Map({scheme: "https"}));
var app = testUtils.getApp(Immutable.Map({scheme: "https"}));

app.server.listen();
});

after(function () {
app.server.close();
});

it("Exits if https specified in options, but not in target", function (done) {
var utils = require("../../../../lib/utils");
var errors = require("../../../../lib/config").errors;
var sinon = require("sinon");
var config = {
proxy: "http://localhost:" + app.server.address().port,
https: true,
proxy: "https://localhost:" + app.server.address().port,
open: false,
logLevel: "silent"
};
var stub = sinon.stub(utils, "fail");
browserSync.init(config);
sinon.assert.called(stub);
assert.include(stub.getCall(0).args[1], errors["proxy+https"]);
utils.fail.restore();
done();

browserSync.init(config, function (err, bs) {

assert.isString(bs.options.get("snippet"));

var expected = app.html.replace("BS", bs.options.get("snippet") + "BS");

request(bs.options.getIn(["urls", "local"]))
.get("/index.html")
.set("accept", "text/html")
.expect(200, expected, function () {
bs.cleanup();
app.server.close();
done();
});
});

});
});

0 comments on commit 80c091d

Please sign in to comment.