@@ -11,6 +11,7 @@ var api = require('./fixtures/api-control');
1111var dock = require ( './fixtures/dock' ) ;
1212var multi = require ( './fixtures/multi-factory' ) ;
1313var async = require ( 'async' ) ;
14+ var Url = require ( 'url' ) ;
1415var find = require ( '101/find' ) ;
1516var hasKeypaths = require ( '101/has-keypaths' ) ;
1617var RedisList = require ( 'redis-types' ) . List ;
@@ -52,8 +53,7 @@ describe('BDD - Create Build and Deploy Instance', function () {
5253 ] , function ( err , newBuild ) {
5354 if ( err ) { return done ( err ) ; }
5455 expect ( ctx . instance . build . _id ) . to . equal ( newBuild . _id ) ;
55- expectHipacheHostsForContainers ( ctx . instance ) ;
56- done ( ) ;
56+ expectHipacheHostsForContainers ( ctx . instance , done ) ;
5757 } ) ;
5858 function createVersion ( cb ) {
5959 var newVersion = ctx . context . createVersion ( {
@@ -125,8 +125,7 @@ describe('BDD - Create Build and Deploy Instance', function () {
125125 ] , function ( err , newBuild ) {
126126 if ( err ) { return done ( err ) ; }
127127 expect ( ctx . instance . build . _id ) . to . equal ( newBuild . _id ) ;
128- expectHipacheHostsForContainers ( ctx . instance ) ;
129- done ( ) ;
128+ expectHipacheHostsForContainers ( ctx . instance , done ) ;
130129 } ) ;
131130 function createVersion ( cb ) {
132131 var newVersion = ctx . context . createVersion ( {
@@ -199,8 +198,7 @@ describe('BDD - Create Build and Deploy Instance', function () {
199198 ] , function ( err , newBuild ) {
200199 if ( err ) { return done ( err ) ; }
201200 expect ( ctx . instance . build . _id ) . to . equal ( newBuild . _id ) ;
202- expectHipacheHostsForContainers ( ctx . instance ) ;
203- done ( ) ;
201+ expectHipacheHostsForContainers ( ctx . instance , done ) ;
204202 } ) ;
205203 function createVersion ( cb ) {
206204 var newVersion = ctx . context . createVersion ( {
@@ -288,8 +286,7 @@ describe('BDD - Create Build and Deploy Instance', function () {
288286 ] , function ( err , newBuild ) {
289287 if ( err ) { return done ( err ) ; }
290288 expect ( ctx . instance . build . _id ) . to . equal ( newBuild . _id ) ;
291- expectHipacheHostsForContainers ( ctx . instance ) ;
292- done ( ) ;
289+ expectHipacheHostsForContainers ( ctx . instance , done ) ;
293290 } ) ;
294291 function createVersion ( cb ) {
295292 var newVersion = ctx . context . createVersion ( {
@@ -365,28 +362,46 @@ describe('BDD - Create Build and Deploy Instance', function () {
365362 } ) ;
366363} ) ;
367364
368-
365+ // KEEP THIS UPDATED.
369366function expectHipacheHostsForContainers ( instance , cb ) {
370367 var containers = instance . containers ;
371368 var allUrls = [ ] ;
369+ var fail = false ;
372370 containers . forEach ( function ( container ) {
373- if ( container . ports ) {
374- Object . keys ( container . ports ) . forEach ( function ( port ) {
371+ var ports = container . json ( ) . ports ;
372+ if ( ports ) {
373+ Object . keys ( ports ) . forEach ( function ( port ) {
375374 var portNumber = port . split ( '/' ) [ 0 ] ;
376- allUrls . push ( [ instance . shortHash , '-' , portNumber , '.' , process . env . DOMAIN ] . join ( '' ) . toLowerCase ( ) ) ;
375+
376+ var instanceName = instance . attrs . lowerName ;
377+ var ownerUsername = instance . attrs . owner . username ;
378+ allUrls . push ( [ portNumber , '.' ,
379+ instanceName , '.' ,
380+ ownerUsername , '.' ,
381+ process . env . DOMAIN ] . join ( '' ) . toLowerCase ( ) ) ;
377382 } ) ;
383+ } else {
384+ fail = true ;
378385 }
379386 } ) ;
387+ if ( fail ) {
388+ return cb ( new Error ( 'all the containers _should_ have ports' ) ) ;
389+ }
380390 async . forEach ( allUrls , function ( url , cb ) {
391+ var exposedPort = url . split ( '.' ) [ 0 ] ;
381392 var hipacheEntry = new RedisList ( 'frontend:' + url ) ;
382393 hipacheEntry . lrange ( 0 , - 1 , function ( err , backends ) {
383394 if ( err ) {
384395 cb ( err ) ;
385396 }
386- else if ( backends . length !== 2 || backends [ 1 ] . toString ( ) . indexOf ( ':' ) === - 1 ) {
397+ else if ( backends . length !== 2 || ! / ^ h t t p s ? : \/ \/ [ ^ \: ] + : [ \d ] + $ / . test ( backends [ 1 ] . toString ( ) ) ) {
387398 cb ( new Error ( 'Backends invalid for ' + url ) ) ;
388399 }
389400 else {
401+ var u = Url . parse ( backends [ 1 ] . toString ( ) ) ;
402+ if ( exposedPort === '443' && u . protocol !== 'https:' ) {
403+ return cb ( new Error ( 'https is not on port 443 ' + backends [ 1 ] . toString ) ) ;
404+ }
390405 cb ( ) ;
391406 }
392407 } ) ;
0 commit comments