Skip to content

Commit

Permalink
fix(setup): ensure --pname arg is sanitized
Browse files Browse the repository at this point in the history
closes #576
- the url was getting sanitized (e.g. swapping out `.` with `-`), but if --pname was passed it wasn't getting the same treatment. This fixes that issue.
  • Loading branch information
acburdine committed Jan 7, 2018
1 parent dd5d224 commit 229953b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/commands/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class SetupCommand extends Command {
title: 'Setting up instance',
task: (ctx) => {
ctx.instance = this.system.getInstance();
ctx.instance.name = argv.pname || url.parse(ctx.instance.config.get('url')).hostname.replace(/\./g, '-');
ctx.instance.name = (argv.pname || url.parse(ctx.instance.config.get('url')).hostname).replace(/\./g, '-');
this.system.addInstance(ctx.instance);
}
}];
Expand Down
46 changes: 46 additions & 0 deletions test/unit/commands/setup-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,52 @@ describe('Unit: Commands > Setup', function () {
});
});

it('Initial stage is setup properly, sanitizes pname argument', function () {
const listr = sinon.stub().resolves();
const aIstub = sinon.stub();
const system = {
getInstance: () => {
return {
checkEnvironment: () => true,
apples: true,
config: {get: () => 'https://ghost.org'}
};
},
addInstance: aIstub,
hook: () => Promise.resolve()
};
const ui = {
run: () => Promise.resolve(),
listr: listr,
confirm: () => Promise.resolve({yes: false})
};
const argv = {
prompt: true,
'setup-linux-user': false,
migrate: false,
pname: 'example.com'
};

const setup = new SetupCommand(ui, system);
return setup.run(argv).then(() => {
expect(listr.calledOnce).to.be.true;
const tasks = listr.getCall(0).args[0];
expect(tasks[0].title).to.equal('Setting up instance');
tasks.forEach(function (task) {
expect(task.title).to.not.match(/database migrations/);
});

const ctx = {};
tasks[0].task(ctx);

expect(ctx.instance).to.be.ok;
expect(ctx.instance.apples).to.be.true;
expect(ctx.instance.name).to.equal('example-com');
expect(aIstub.calledOnce).to.be.true;
expect(aIstub.getCall(0).args[0]).to.deep.equal(ctx.instance);
});
});

describe('task dependency checks', function () {
let stubs, ui, system;

Expand Down

0 comments on commit 229953b

Please sign in to comment.