Skip to content

Commit

Permalink
fix(nginx): skip SSL setup if url is an IP address
Browse files Browse the repository at this point in the history
closes #301
- detect if the url is an IP address and skip if it is
  • Loading branch information
acburdine committed Nov 23, 2017
1 parent 0c3c974 commit 5ed1cfe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions extensions/nginx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs-extra');
const os = require('os');
const dns = require('dns');
const url = require('url');
const isIP = require('validator/lib/isIP');
const path = require('path');
const execa = require('execa');
const Promise = require('bluebird');
Expand Down Expand Up @@ -78,6 +79,11 @@ class NginxExtension extends cli.Extension {
const parsedUrl = url.parse(ctx.instance.config.get('url'));
const confFile = `${parsedUrl.hostname}-ssl.conf`;

if (isIP(parsedUrl.hostname)) {
this.ui.log('SSL certs cannot be generated for IP addresses, skipping', 'yellow');
return task.skip();
}

if (fs.existsSync(`/etc/nginx/sites-available/${confFile}`)) {
this.ui.log('SSL has already been set up, skipping', 'yellow');
return task.skip();
Expand Down
10 changes: 10 additions & 0 deletions extensions/nginx/test/extension-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ describe('Unit: Extensions > Nginx', function () {
ext = proxyNginx({'fs-extra': {existsSync: stubs.es}});
});

it('skips if the url is an IP address', function () {
ctx = {instance: {config: {get: () => 'http://10.0.0.1'}}};
ext.setupSSL({}, ctx, task);

expect(stubs.es.calledOnce).to.be.false;
expect(ext.ui.log.calledOnce).to.be.true;
expect(ext.ui.log.getCall(0).args[0]).to.match(/SSL certs cannot be generated for IP addresses/);
expect(stubs.skip.calledOnce).to.be.true;
});

it('Breaks if ssl config already exists', function () {
const sslFile = '/etc/nginx/sites-available/ghost.dev-ssl.conf';
const existsStub = sinon.stub().returns(true);
Expand Down

0 comments on commit 5ed1cfe

Please sign in to comment.