Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

strongloop / node-foreman / 224

2 May 2016 - 8:27 coverage: 88.78%. First build
224

Pull #117

travis-ci

8bd1dd86bbf8705a5a702b86a2f3a390?size=18&default=identiconrmg
improve Procfile parsing error messages
Pull Request #117: WIP: Upgrade all outdated dependencies

27 of 33 new or added lines in 5 files covered. (81.82%)

546 of 615 relevant lines covered (88.78%)

93.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/lib/proxy.js
1
var fs   = require('fs');
80×
2
var path = require('path');
80×
3
var prog = require('child_process');
80×
4
var util = require('util');
80×
5

6
var cons = require('./console').Console;
80×
7

8
function f(key, j, ports, proc, reqs, portargs, localhost, emitter, ssl) {
80×
9
  var port = parseInt(ports[j]);
10×
10
  var ssl_port = (port === 80 ? 443 : (port + 443));
10×
11

12
  if(port > 0 && port < 1024 && process.getuid() !== 0) {
10×
13
    return cons.Error('Cannot Bind to Privileged Port %s Without Permission - Try \'sudo\'',port);
!
14
  }
15

16
  if(isNaN(port)) {
10×
17
    return cons.Warn('No Downstream Port Defined for \'%s\' Proxy', key);
!
18
  }
19

20
  if(!(key in proc)) {
10×
21
    return cons.Warn('Proxy Not Started for Undefined Key \'%s\'', key);
!
22
  }
23

24
  var upstream_size = reqs[key];
10×
25
  var upstream_port = parseInt(portargs) + j * 100;
10×
26

27
  var proxy = prog.fork(require.resolve('../proxy'), [], {
10×
28
    env: {
29
      HOST: localhost,
30
      PORT: port,
31
      UPSTREAM_HOST: localhost,
32
      UPSTREAM_PORT: upstream_port,
33
      UPSTREAM_SIZE: upstream_size,
34
      SSL_CERT: ssl.cert,
35
      SSL_KEY: ssl.key,
36
      SSL_PORT: port ? ssl_port : 0
37
    }
38
  });
39

40
  var port_targets;
10×
41

42
  if(upstream_size === 1) {
10×
43
    port_targets = util.format('%d', upstream_port);
10×
44
  } else {
45
    port_targets = util.format('(%d-%d)', upstream_port, upstream_port + upstream_size - 1);
!
46
  }
47

48
  cons.Alert('Starting Proxy Server [%s] %s -> %s', key, port, port_targets);
10×
49
  if (ssl.cert && ssl.key) {
10×
50
    cons.Alert('Starting Secure Proxy Server [%s] %s -> %s', key, ssl_port, port_targets);
5×
51
  }
52

53
  proxy.on('message', function(msg) {
10×
54
    if ('http' in msg) {
15×
55
      emitter.emit('http', msg.http);
10×
56
    }
57
    if ('https' in msg) {
15×
58
      emitter.emit('https', msg.https);
5×
59
    }
60
  });
61

62
  emitter.once('killall', function(signal) {
10×
63
    cons.Done('Killing Proxy Server on Port %s', port);
10×
64
    try {
10×
65
      proxy.disconnect();
10×
66
      proxy.kill(signal);
10×
67
    } catch(_e) {
NEW
68
      cons.Warn('Proxy server already dead');
!
69
    }
70
  });
71

72
  proxy.on('exit', function(code, signal) {
10×
73
    emitter.emit('killall', 'SIGINT');
10×
74
  });
75

76
}
77

78
function startProxies(reqs, proc, command, emitter, portargs) {
80×
79

80
  if ('proxy' in command) {
30×
81

82
    var localhost = 'localhost';
10×
83

84
    var ports = command.proxy.split(',');
10×
85

86
    var ssl = {
10×
87
      cert: '',
88
      key:  ''
89
    };
90
    if ((command.sslKey && !command.sslCert) ||
10×
91
        (command.sslCert && !command.sslKey)) {
NEW
92
      cons.Warn('SSL key and cert must both be supplied for SSL support');
!
93
    }
94
    if (command.sslKey && command.sslCert) {
10×
95
      command.sslKey = path.resolve(command.sslKey);
5×
96
      command.sslCert = path.resolve(command.sslCert);
5×
97
      if (!fs.existsSync(command.sslKey)) {
5×
98
        cons.Warn('SSL key (%s) does not exist', command.sslKey);
!
99
      }
100
      else {
101
        ssl.key = command.sslKey;
5×
102
      }
103
      if (!fs.existsSync(command.sslCert)) {
5×
104
        cons.Warn('SSL cert (%s) does not exist', command.sslCert);
!
105
      }
106
      else {
107
        ssl.cert = command.sslCert;
5×
108
      }
109
    }
110

111
    Object.keys(reqs).forEach(function(key, i) {
10×
112
      f(key, i, ports, proc, reqs, portargs, localhost, emitter, ssl);
10×
113
    });
114
  }
115

116
}
117

118
module.exports.startProxies = startProxies;
80×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc