Skip to content

Commit

Permalink
stand up a server on 127.0.0.1 for test
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Aug 9, 2019
1 parent 561ea02 commit 7fd6e17
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions packages/https-proxy/test/integration/proxy_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"

_ = require("lodash")
DebugProxy = require("@cypress/debugging-proxy")
fs = require("fs")
https = require("https")
net = require("net")
network = require("@packages/network")
path = require("path")
Expand All @@ -12,6 +14,8 @@ proxy = require("../helpers/proxy")
httpServer = require("../helpers/http_server")
httpsServer = require("../helpers/https_server")

fs = Promise.promisifyAll(fs)

describe "Proxy", ->
beforeEach ->
Promise.join(
Expand Down Expand Up @@ -157,22 +161,28 @@ describe "Proxy", ->
@sandbox.spy(@proxy, "_generateMissingCertificates")
@sandbox.spy(@proxy, "_getServerPortForIp")

request({
strictSSL: false
url: "https://1.1.1.1/"
proxy: "http://localhost:3333"
})
Promise.all([
httpsServer.start(8445),
fs.unlinkAsync(path.join(@proxy._ca.certsFolder, '127.0.0.1.pem')),
fs.unlinkAsync(path.join(@proxy._ca.keysFolder, '127.0.0.1.key')),
fs.unlinkAsync(path.join(@proxy._ca.keysFolder, '127.0.0.1.public.key'))
])
.then =>
proxy.reset()

request({
strictSSL: false
url: "https://127.0.0.1:8445/"
proxy: "http://localhost:3333"
})
.then =>
## this should not stand up its own https server
request({
strictSSL: false
url: "https://localhost:8443/"
proxy: "http://localhost:3333"
})
.then =>
expect(@proxy._generateMissingCertificates).to.be.calledOnce
expect(@proxy._getServerPortForIp).to.be.calledWith('1.1.1.1', sinon.match.any)
expect(@proxy._ipServers["127.0.0.1"]).to.be.an.instanceOf(https.Server)
expect(@proxy._getServerPortForIp).to.be.calledWith('127.0.0.1', sinon.match.any)

context "closing", ->
it "resets sslServers and can reopen", ->
Expand Down Expand Up @@ -278,7 +288,7 @@ describe "Proxy", ->
})
.then =>
throw new Error('should not succeed')
.catch { message: 'Error: socket hang up' }, =>
.catch { message: 'Error: socket hang upf' }, =>
expect(createProxyConn).to.not.be.called
expect(createSocket).to.be.calledWith({
port: @proxy._sniPort
Expand Down

0 comments on commit 7fd6e17

Please sign in to comment.