Permalink
Browse files

running stubs at http and https simulatneously

  • Loading branch information...
1 parent 577ee4d commit 0be5f25082f8a95c651fdddd2fa1e838de722554 @mrak committed Nov 5, 2012
Showing with 87 additions and 24 deletions.
  1. +5 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +25 −5 spec/cli.spec.coffee
  4. +13 −7 src/console/cli.coffee
  5. +11 −11 src/server.coffee
  6. +17 −0 tls/cert.pem
  7. +15 −0 tls/key.pem
View
@@ -1,5 +1,10 @@
# Changelog
+## 0.1.36 (in progress)
+
+* running stubs portal at both http and https by default
+* addition of `-t, --tls` option to specifying https port for stubs portal
+
## 0.1.35
* added `file` parameter to `request` object. When matching a request, if it has `file` specified it will load it's contents from the filesystem as the `post` value. If the `file` cannot be found, it falls back to `post`.
View
@@ -23,7 +23,7 @@
"email": "enmrak@gmail.com"
}
],
- "files": ["lib", "package.json", "bin"],
+ "files": ["lib", "package.json", "bin", "ssl"],
"scripts": {
"prepublish": "coffee -o lib -c src",
"start": "lib/server.js",
View
@@ -68,6 +68,25 @@ describe 'CLI', ->
expect(actual.stubs).toBe expected
+ describe '-t, --tls', ->
+ it 'should return default if no flag provided', ->
+ expected = 7443
+ actual = sut.getArgs []
+
+ expect(actual.tls).toBe expected
+
+ it 'should return supplied value when provided', ->
+ expected = 443
+ actual = sut.getArgs ['-t', expected]
+
+ expect(actual.tls).toBe expected
+
+ it 'should return supplied value when provided with full flag', ->
+ expected = 443
+ actual = sut.getArgs ['--tls', expected]
+
+ expect(actual.tls).toBe expected
+
describe '-l, --location', ->
it 'should return default if no flag provided', ->
expected = 'localhost'
@@ -166,7 +185,6 @@ describe 'CLI', ->
expect(actual).toBe expected
-
describe 'getArgs', ->
it 'should gather all arguments', ->
expected =
@@ -177,6 +195,7 @@ describe 'CLI', ->
key: 'a key'
cert: 'a certificate'
pfx: 'a pfx'
+ tls: 443
spyOn(sut, 'data').andReturn expected.data
spyOn(sut, 'key').andReturn expected.key
@@ -186,11 +205,12 @@ describe 'CLI', ->
actual = sut.getArgs [
'-s', expected.stubs
'-a', expected.admin
- '-d', 'anything'
+ '-d', 'mocked'
'-l', expected.location
- '-k', 'anything'
- '-c', 'anything'
- '-p', 'anything'
+ '-k', 'mocked'
+ '-c', 'mocked'
+ '-p', 'mocked'
+ '-t', expected.tls
]
expect(actual).toEqual expected
View
@@ -43,17 +43,22 @@ module.exports =
processed: true
description: 'Prevent stubby from printing to the console.'
,
- name: 'stubs'
- param: 'port'
- flag: 's'
- description: 'Port for stubs portal. Defaults to 8882.'
- ,
name: 'pfx'
flag: 'p'
param: 'file'
processed: true
description: 'PFX file. Ignored if used with --key/--cert'
,
+ name: 'stubs'
+ param: 'port'
+ flag: 's'
+ description: 'Port for stubs portal. Defaults to 8882.'
+ ,
+ name: 'tls'
+ param: 'port'
+ flag: 't'
+ description: 'Port for https stubs portal. Defaults to 7443.'
+ ,
name: 'version'
flag: 'v'
exit: true
@@ -63,10 +68,11 @@ module.exports =
defaults:
stubs: 8882
admin: 8889
+ tls: 7443
location: 'localhost'
data: null
- key: null
- cert: null
+ key: fs.readFileSync "#{process.cwd()}/tls/key.pem", 'utf8'
+ cert: fs.readFileSync "#{process.cwd()}/tls/cert.pem", 'utf8'
pfx: null
help: ->
View
@@ -28,10 +28,12 @@ onEndpointLoaded = (err, endpoint) -> out.notice "Loaded: #{endpoint.request.met
endpoints = new Endpoints(args.data, onEndpointLoaded)
stubServer = (new Stubs(endpoints)).server
-adminServer = (new Admin(endpoints)).server
+stubServer = http.createServer(stubServer)
+stubServer.on 'listening', -> onListening 'Stubs', args.stubs, 'http'
+stubServer.on 'error', (err) -> onError(err, args.stubs)
+stubServer.listen args.stubs, args.location
-httpsOptions = false
-protocol = 'http'
+httpsOptions = {}
if args.key and args.cert
httpsOptions =
key: args.key
@@ -40,15 +42,13 @@ else if args.pfx
httpsOptions =
pfx: args.pfx
-unless httpsOptions
- stubServer = http.createServer(stubServer)
-else
- protocol = 'https'
- stubServer = https.createServer(httpsOptions, stubServer)
-stubServer.on 'listening', -> onListening 'Stubs', args.stubs, protocol
-stubServer.on 'error', (err) -> onError(err, args.stubs)
-stubServer.listen args.stubs, args.location, protocol
+tlsServer = (new Stubs(endpoints)).server
+tlsServer = https.createServer(httpsOptions, tlsServer)
+tlsServer.on 'listening', -> onListening 'Stubs', args.tls, 'https'
+tlsServer.on 'error', (err) -> onError(err, args.tls)
+tlsServer.listen args.tls, args.location
+adminServer = (new Admin(endpoints)).server
adminServer = http.createServer(adminServer)
adminServer.on 'listening', -> onListening 'Admin', args.admin
adminServer.on 'error', (err) -> onError(err, args.admin)
View
@@ -0,0 +1,17 @@
+-----BEGIN CERTIFICATE-----
+MIICrTCCAhYCCQCCg8n//oQGxzANBgkqhkiG9w0BAQUFADCBmjELMAkGA1UEBhMC
+VVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28x
+DzANBgNVBAoTBlN0dWJieTEUMBIGA1UECxMLc3R1YmJ5NG5vZGUxFjAUBgNVBAMT
+DXN0dWIuYnkvNG5vZGUxHzAdBgkqhkiG9w0BCQEWEGVubXJha0BnbWFpbC5jb20w
+HhcNMTIxMTA1MDYyMjU5WhcNMjIxMTAzMDYyMjU5WjCBmjELMAkGA1UEBhMCVVMx
+EzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xDzAN
+BgNVBAoTBlN0dWJieTEUMBIGA1UECxMLc3R1YmJ5NG5vZGUxFjAUBgNVBAMTDXN0
+dWIuYnkvNG5vZGUxHzAdBgkqhkiG9w0BCQEWEGVubXJha0BnbWFpbC5jb20wgZ8w
+DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAL4gxx0AVFarh91SfpnHcJmwqxjHgf/i
+dhuW1/01IMrywAN4C0G7ld35aAm72NR5CuaYNSwstKOg9CKPjgJbbYBtaW5kiPkQ
+yuIhblIlBG18K1mqlxmiy0YU3JQmpdiJiELZbA89GCHSrHnBWnfQuLXtbF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E4
+k6+xXAid9fVuwtiJK+NoEhStxuisu6RS8+PRoRKcqd4C
+-----END RSA PRIVATE KEY-----

0 comments on commit 0be5f25

Please sign in to comment.