mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Don't rely on ssh-keygen output to prevent known errors
This commit is contained in:
@@ -24,7 +24,9 @@ var keygen = require("../../../../../../../red/runtime/storage/localfilesystem/p
|
||||
describe("localfilesystem/projects/ssh/keygen", function() {
|
||||
|
||||
afterEach(function() {
|
||||
child_process.spawn.restore();
|
||||
if (child_process.spawn.restore) {
|
||||
child_process.spawn.restore();
|
||||
}
|
||||
})
|
||||
|
||||
it("invokes sshkeygen", function(done) {
|
||||
@@ -47,7 +49,7 @@ describe("localfilesystem/projects/ssh/keygen", function() {
|
||||
});
|
||||
|
||||
keygen.generateKey({
|
||||
size: 123,
|
||||
size: 1024,
|
||||
location: 'location',
|
||||
comment: 'comment',
|
||||
password: 'password'
|
||||
@@ -63,66 +65,44 @@ describe("localfilesystem/projects/ssh/keygen", function() {
|
||||
var command;
|
||||
var args;
|
||||
var opts;
|
||||
sinon.stub(child_process,"spawn", function(_command,_args,_opts) {
|
||||
_command = command;
|
||||
_args = args;
|
||||
_opts = opts;
|
||||
|
||||
var e = new EventEmitter();
|
||||
e.stdout = new EventEmitter();
|
||||
e.stderr = new EventEmitter();
|
||||
setTimeout(function() {
|
||||
e.stdout.emit("data","result");
|
||||
e.stderr.emit("data","passphrase is too short");
|
||||
e.emit("close",1);
|
||||
},5)
|
||||
return e;
|
||||
});
|
||||
|
||||
keygen.generateKey({
|
||||
size: 123,
|
||||
location: 'location',
|
||||
comment: 'comment',
|
||||
password: 'password'
|
||||
}).then(function(output) {
|
||||
done(new Error("Error not thrown"));
|
||||
}).catch(function(err) {
|
||||
try {
|
||||
keygen.generateKey({
|
||||
size: 1024,
|
||||
location: 'location',
|
||||
comment: 'comment',
|
||||
password: '123'
|
||||
}).then(function(output) {
|
||||
done(new Error("Error not thrown"));
|
||||
}).catch(function(err) {
|
||||
done(new Error("Error not thrown"));
|
||||
})
|
||||
} catch(err) {
|
||||
err.should.have.property("code","key_passphrase_too_short");
|
||||
done();
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
it("reports key length too short", function(done) {
|
||||
var command;
|
||||
var args;
|
||||
var opts;
|
||||
sinon.stub(child_process,"spawn", function(_command,_args,_opts) {
|
||||
_command = command;
|
||||
_args = args;
|
||||
_opts = opts;
|
||||
|
||||
var e = new EventEmitter();
|
||||
e.stdout = new EventEmitter();
|
||||
e.stderr = new EventEmitter();
|
||||
setTimeout(function() {
|
||||
e.stdout.emit("data","result");
|
||||
e.stderr.emit("data","Key must at least be 1024 bits");
|
||||
e.emit("close",1);
|
||||
},50)
|
||||
return e;
|
||||
});
|
||||
|
||||
keygen.generateKey({
|
||||
size: 123,
|
||||
location: 'location',
|
||||
comment: 'comment',
|
||||
password: 'password'
|
||||
}).then(function(output) {
|
||||
done(new Error("Error not thrown"));
|
||||
}).catch(function(err) {
|
||||
try {
|
||||
keygen.generateKey({
|
||||
size: 123,
|
||||
location: 'location',
|
||||
comment: 'comment',
|
||||
password: 'password'
|
||||
}).then(function(output) {
|
||||
done(new Error("Error not thrown"));
|
||||
}).catch(function(err) {
|
||||
done(new Error("Error not thrown"));
|
||||
})
|
||||
} catch(err) {
|
||||
err.should.have.property("code","key_length_too_short");
|
||||
done();
|
||||
})
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user