Skip to content

Commit

Permalink
Merge pull request #512 from tessel/jon-root-keypath
Browse files Browse the repository at this point in the history
Uses correct key path for root command
  • Loading branch information
rwaldron committed Jan 5, 2016
2 parents 1f7ce04 + 059afba commit b51e74d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ controller.root = function(opts) {
// Spawn a new SSH process
var child = cp.spawn('ssh', ['-i',
// Use the provided key path
opts.key,
Tessel.LOCAL_AUTH_KEY,
// Connect to the Tessel's IP Address
'root@' + tessel.lanConnection.ip
], {
Expand Down
4 changes: 4 additions & 0 deletions test/unit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@ exports['controller.root'] = {
return callback(tessel);
}.bind(this));

// Return our own local auth key (it won't be set because we have stubbed
// that functionality out of standardTesselCommand)
this.sandbox.stub(Tessel, 'LOCAL_AUTH_KEY', testKey);

controller.root({
key: testKey
})
Expand Down
93 changes: 93 additions & 0 deletions test/unit/root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
exports['tessel.root'] = {
setUp: function(done) {
var self = this;
this.sandbox = sinon.sandbox.create();
this.spawn = this.sandbox.stub(cp, 'spawn', function() {
var child = new Emitter();

setImmediate(() => {
child.emit('close');
});

return child;
});
this.standardTesselCommand = this.sandbox.spy(controller, 'standardTesselCommand');
this.logsWarn = this.sandbox.stub(logs, 'warn', function() {});
this.logsInfo = this.sandbox.stub(logs, 'info', function() {});

this.seeker = this.sandbox.stub(discover, 'TesselSeeker', function Seeker() {
this.start = function(options) {
self.activeSeeker = this;
setTimeout(this.stop.bind(this), options.timeout);
return this;
};
this.stop = function() {
this.emit('end');
return this;
};
});
util.inherits(this.seeker, Emitter);
done();
},

tearDown: function(done) {
this.sandbox.restore();
done();
},

spawnNotCalledNoTessels: function(test) {
test.expect(2);

// Root should call closeFailed Command if no Tessels were found
this.finishWithError = this.sandbox.stub(cli, 'closeFailedCommand', () => {
// We called standardTesselCommand to fetch the Tessel
test.equal(this.standardTesselCommand.callCount, 1);
// We did not spawn a root process because we did not have a Tessel
test.equal(this.spawn.callCount, 0);
test.done();
});

// Tell the CLI to start a root connection
cli(['root', '-t', '0.001']);
},

spawnCalledWithLANTessel: function(test) {
test.expect(3);

// Root should call closeFailed Command if no Tessels were found
this.finishWithSuccess = this.sandbox.stub(cli, 'closeSuccessfulCommand', () => {
// We called standardTesselCommand to fetch the Tessel
test.ok(this.standardTesselCommand.calledOnce);
// We did not spawn a root process because we did not have a Tessel
test.ok(this.spawn.calledOnce);
// Make sure the proper args were used
test.ok(this.spawn.calledWith(
// We are using the ssh command
'ssh',
// Passing in the appropriate key to the right IP Address
['-i', Tessel.LOCAL_AUTH_KEY, 'root@' + tessel.lanConnection.ip],
// We are piping std streams to the process
{
stdio: 'inherit'
}
));
test.done();
});

// Tell the CLI to start a root connection
cli(['root', '-t', '0.001']);

// Create a new Tessel
var tessel = new Tessel({
connectionType: 'LAN'
});
// Give it a name
tessel.name = 'Frank';
tessel.lanConnection.ip = '1.1.1.1';

// Emit the Tessel
setImmediate(() => {
this.activeSeeker.emit('tessel', tessel);
});
},
};

0 comments on commit b51e74d

Please sign in to comment.