Move tests to reflect package structure

This commit is contained in:
Nick O'Leary
2018-08-19 11:28:03 +01:00
parent 974ba40f28
commit 998bf92ad4
118 changed files with 39 additions and 26 deletions

View File

@@ -0,0 +1,19 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
describe("storage/localfilesystem/projects/Project", function() {
it.skip("NEEDS TESTS WRITING",function() {});
})

View File

@@ -0,0 +1,63 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var should = require("should");
var defaultFileSet = require("../../../../../../red/runtime/storage/localfilesystem/projects/defaultFileSet");
describe('storage/localfilesystem/projects/defaultFileSet', function() {
var runtime = {
i18n: {
"_": function(name) {
return name;
}
}
};
it('generates package.json for a project', function() {
var generated = defaultFileSet["package.json"]({
name: "A TEST NAME",
summary: "A TEST SUMMARY",
files: {
flow: "MY FLOW FILE",
credentials: "MY CREDENTIALS FILE"
}
}, runtime);
var parsed = JSON.parse(generated);
parsed.should.have.property('name',"A TEST NAME");
parsed.should.have.property('description',"A TEST SUMMARY");
parsed.should.have.property('node-red');
parsed['node-red'].should.have.property('settings');
parsed['node-red'].settings.should.have.property('flowFile',"MY FLOW FILE");
parsed['node-red'].settings.should.have.property('credentialsFile',"MY CREDENTIALS FILE");
});
it('generates README.md for a project', function() {
var generated = defaultFileSet["README.md"]({
name: "A TEST NAME",
summary: "A TEST SUMMARY"
}, runtime);
generated.should.match(/A TEST NAME/);
generated.should.match(/A TEST SUMMARY/);
});
it('generates .gitignore for a project', function() {
var generated = defaultFileSet[".gitignore"]({
name: "A TEST NAME",
summary: "A TEST SUMMARY"
}, runtime);
generated.length.should.be.greaterThan(0);
});
});

View File

@@ -0,0 +1,83 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var should = require("should");
var sinon = require("sinon");
var authCache = require("../../../../../../../red/runtime/storage/localfilesystem/projects/git/authCache")
describe("localfilesystem/projects/git/authCache", function() {
beforeEach(function() {
authCache.init();
});
afterEach(function() {
authCache.init();
});
it('sets/clears auth details for a given project/remote/user', function() {
should.not.exist(authCache.get("project","remote1","user1"));
should.not.exist(authCache.get("project","remote1","user2"));
authCache.set("project","remote1","user1",{foo1:"bar1"});
authCache.set("project","remote1","user2",{foo2:"bar2"});
var result = authCache.get("project","remote1","user1");
result.should.have.property("foo1","bar1");
result = authCache.get("project","remote1","user2");
result.should.have.property("foo2","bar2");
authCache.clear("project","remote1","user1");
should.not.exist(authCache.get("project","remote1","user1"));
should.exist(authCache.get("project","remote1","user2"));
});
it('clears auth details for all users on a given project/remote', function() {
authCache.set("project","remote1","user1",{foo1:"bar1"});
authCache.set("project","remote1","user2",{foo2:"bar2"});
authCache.set("project","remote2","user1",{foo3:"bar3"});
should.exist(authCache.get("project","remote1","user1"));
should.exist(authCache.get("project","remote1","user2"));
should.exist(authCache.get("project","remote2","user1"));
authCache.clear("project","remote1");
should.not.exist(authCache.get("project","remote1","user1"));
should.not.exist(authCache.get("project","remote1","user2"));
should.exist(authCache.get("project","remote2","user1"));
});
it('clears auth details for all remotes/users on a given project', function() {
authCache.set("project1","remote1","user1",{foo1:"bar1"});
authCache.set("project1","remote1","user2",{foo2:"bar2"});
authCache.set("project2","remote2","user1",{foo3:"bar3"});
should.exist(authCache.get("project1","remote1","user1"));
should.exist(authCache.get("project1","remote1","user2"));
should.exist(authCache.get("project2","remote2","user1"));
authCache.clear("project2");
should.exist(authCache.get("project1","remote1","user1"));
should.exist(authCache.get("project1","remote1","user2"));
should.not.exist(authCache.get("project2","remote2","user1"));
});
});

View File

@@ -0,0 +1,81 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var net = require("net");
var path = require("path");
var os = require("os");
var should = require("should");
var sinon = require("sinon");
var child_process = require("child_process");
var fs = require("fs-extra");
var authServer = require("../../../../../../../red/runtime/storage/localfilesystem/projects/git/authServer");
var sendPrompt = function(localPath, prompt) {
return new Promise(function(resolve,reject) {
var response;
var socket = net.connect(localPath, function() {
socket.on('data', function(data) { response = data; socket.end() });
socket.on('end', function() {
resolve(response);
});
socket.on('error',reject);
socket.write(prompt+"\n", 'utf8');
});
socket.setEncoding('utf8');
});
}
describe("localfilesystem/projects/git/authServer", function() {
it("listens for user/pass prompts and returns provided auth", function(done) {
authServer.ResponseServer({username: "TEST_USER", password: "TEST_PASS"}).then(function(rs) {
sendPrompt(rs.path,"Username").then(function(response) {
response.should.eql("TEST_USER");
return sendPrompt(rs.path,"Password");
}).then(function(response) {
response.should.eql("TEST_PASS");
}).then(() => {
rs.close();
done();
}).catch(function(err) {
rs.close();
done(err);
})
})
});
it("listens for ssh prompts and returns provided auth", function(done) {
authServer.ResponseSSHServer({passphrase: "TEST_PASSPHRASE"}).then(function(rs) {
sendPrompt(rs.path,"The").then(function(response) {
// TODO:
response.should.eql("yes");
return sendPrompt(rs.path,"Enter");
}).then(function(response) {
response.should.eql("TEST_PASSPHRASE");
}).then(() => {
rs.close();
done();
}).catch(function(err) {
rs.close();
done(err);
})
})
})
});

View File

@@ -0,0 +1,81 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var net = require("net");
var path = require("path");
var os = require("os");
var should = require("should");
var sinon = require("sinon");
var child_process = require("child_process");
var fs = require("fs-extra");
var authWriter = "../../../../../../../red/runtime/storage/localfilesystem/projects/git/authWriter";
function getListenPath() {
var seed = (0x100000+Math.random()*0x999999).toString(16);
var fn = 'node-red-git-askpass-'+seed+'-sock';
var listenPath;
if (process.platform === 'win32') {
listenPath = '\\\\.\\pipe\\'+fn;
} else {
listenPath = path.join(process.env['XDG_RUNTIME_DIR'] || os.tmpdir(), fn);
}
// console.log(listenPath);
return listenPath;
}
describe("localfilesystem/projects/git/authWriter", function() {
it("connects to port and sends passphrase", function(done) {
var receivedData = "";
var server = net.createServer(function(connection) {
connection.setEncoding('utf8');
connection.on('data', function(data) {
receivedData += data;
var m = data.indexOf("\n");
if (m !== -1) {
connection.end();
}
});
});
var listenPath = getListenPath();
server.listen(listenPath, function(ready) {
child_process.exec('"'+process.execPath+'" "'+authWriter+'" "'+listenPath+'" TEST_PHRASE_FOO',{cwd:__dirname}, (error,stdout,stderr) => {
server.close();
try {
should.not.exist(error);
receivedData.should.eql("TEST_PHRASE_FOO\n");
done();
} catch(err) {
done(err);
}
});
});
server.on('close', function() {
// console.log("Closing response server");
fs.removeSync(listenPath);
});
server.on('error',function(err) {
console.log("ResponseServer unexpectedError:",err.toString());
server.close();
done(err);
});
})
});

View File

@@ -0,0 +1,19 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
describe("storage/localfilesystem/projects/git/index", function() {
it.skip("NEEDS TESTS WRITING",function() {});
})

View File

@@ -0,0 +1,19 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
describe("storage/localfilesystem/projects/index", function() {
it.skip("NEEDS TESTS WRITING",function() {});
})

View File

@@ -0,0 +1,432 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var should = require("should");
var fs = require('fs-extra');
var path = require('path');
var sshkeys = require("../../../../../../../red/runtime/storage/localfilesystem/projects/ssh");
describe("storage/localfilesystem/projects/ssh", function() {
var userDir = path.join(__dirname,".testSSHKeyUserHome");
var mockSettings = {
userDir: userDir
};
var mockRuntime = {
log:{
_:function() { return "placeholder message"},
info: function() { },
log: function() { },
trace: function() { }
}
};
var oldHOME;
beforeEach(function(done) {
oldHOME = process.env.HOME;
process.env.HOME = "/tmp/doesnt/exist";
fs.remove(userDir,function(err) {
fs.mkdir(userDir,done);
});
});
afterEach(function(done) {
process.env.HOME = oldHOME;
fs.remove(userDir,done);
});
it('should create sshkey directory when sshkey initializes', function(done) {
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
sshkeys.init(mockSettings, mockRuntime).then(function() {
var ret = fs.existsSync(sshkeyDirPath);
ret.should.be.true();
done();
}).catch(function(err) {
done(err);
});
});
it('should get sshkey empty list if there is no sshkey file', function(done) {
var username = 'test';
sshkeys.init(mockSettings, mockRuntime).then(function() {
sshkeys.listSSHKeys(username).then(function(retObj) {
retObj.should.be.instanceOf(Array).and.have.lengthOf(0);
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should get sshkey list', function(done) {
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var filenameList = ['test-key01', 'test-key02'];
sshkeys.init(mockSettings, mockRuntime).then(function() {
for(var filename of filenameList) {
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename),"","utf8");
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename+".pub"),"","utf8");
}
sshkeys.listSSHKeys(username).then(function(retObj) {
retObj.should.be.instanceOf(Array).and.have.lengthOf(filenameList.length);
for(var filename of filenameList) {
retObj.should.containEql({ name: filename });
}
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should not get sshkey file if there is only private key', function(done) {
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var filenameList = ['test-key01', 'test-key02'];
var onlyPrivateKeyFilenameList = ['test-key03', 'test-key04'];
sshkeys.init(mockSettings, mockRuntime).then(function() {
for(var filename of filenameList) {
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename),"","utf8");
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename+".pub"),"","utf8");
}
for(var filename of onlyPrivateKeyFilenameList) {
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename),"","utf8");
}
sshkeys.listSSHKeys(username).then(function(retObj) {
retObj.should.be.instanceOf(Array).and.have.lengthOf(filenameList.length);
for(var filename of filenameList) {
retObj.should.containEql({ name: filename });
}
for(var filename of onlyPrivateKeyFilenameList) {
retObj.should.not.containEql({ name: filename });
}
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should not get sshkey file if there is only public key', function(done) {
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var filenameList = ['test-key01', 'test-key02'];
var directoryList = ['test-key03', '.test-key04'];
sshkeys.init(mockSettings, mockRuntime).then(function() {
for(var filename of filenameList) {
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename),"","utf8");
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename+".pub"),"","utf8");
}
for(var filename of directoryList) {
fs.ensureDirSync(path.join(sshkeyDirPath,filename));
}
sshkeys.listSSHKeys(username).then(function(retObj) {
retObj.should.be.instanceOf(Array).and.have.lengthOf(filenameList.length);
for(var filename of filenameList) {
retObj.should.containEql({ name: filename });
}
for(var directoryname of directoryList) {
retObj.should.not.containEql({ name: directoryname });
}
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should get sshkey list that does not have directory', function(done) {
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var otherUsername = 'other';
var filenameList = ['test-key01', 'test-key02'];
var otherUserFilenameList = ['test-key03', 'test-key04'];
sshkeys.init(mockSettings, mockRuntime).then(function() {
for(var filename of filenameList) {
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename),"","utf8");
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename+".pub"),"","utf8");
}
for(var filename of otherUserFilenameList) {
fs.writeFileSync(path.join(sshkeyDirPath,otherUsername+"_"+filename),"","utf8");
fs.writeFileSync(path.join(sshkeyDirPath,otherUsername+"_"+filename+".pub"),"","utf8");
}
sshkeys.listSSHKeys(username).then(function(retObj) {
retObj.should.be.instanceOf(Array).and.have.lengthOf(filenameList.length);
for(var filename of filenameList) {
retObj.should.containEql({ name: filename });
}
for(var filename of otherUserFilenameList) {
retObj.should.not.containEql({ name: filename });
}
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should get sshkey list that have keys of specified user', function(done) {
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var otherUsername = 'other';
var filenameList = ['test-key01', 'test-key02'];
var otherUserFilenameList = ['test-key03', 'test-key04'];
sshkeys.init(mockSettings, mockRuntime).then(function() {
for(var filename of filenameList) {
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename),"","utf8");
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename+".pub"),"","utf8");
}
for(var filename of otherUserFilenameList) {
fs.writeFileSync(path.join(sshkeyDirPath,otherUsername+"_"+filename),"","utf8");
fs.writeFileSync(path.join(sshkeyDirPath,otherUsername+"_"+filename+".pub"),"","utf8");
}
sshkeys.listSSHKeys(username).then(function(retObj) {
retObj.should.be.instanceOf(Array).and.have.lengthOf(filenameList.length);
for(var filename of filenameList) {
retObj.should.containEql({ name: filename });
}
for(var filename of otherUserFilenameList) {
retObj.should.not.containEql({ name: filename });
}
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should generate sshkey file with empty data', function(done) {
this.timeout(10000);
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var options = {
name: 'test-key01'
};
sshkeys.init(mockSettings, mockRuntime).then(function() {
sshkeys.generateSSHKey(username, options).then(function(retObj) {
retObj.should.be.equal(options.name);
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should generate sshkey file with only comment data', function(done) {
this.timeout(10000);
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var options = {
comment: 'test@test.com',
name: 'test-key01'
};
sshkeys.init(mockSettings, mockRuntime).then(function() {
sshkeys.generateSSHKey(username, options).then(function(retObj) {
retObj.should.be.equal(options.name);
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should generate sshkey file with password data', function(done) {
this.timeout(10000);
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var options = {
comment: 'test@test.com',
name: 'test-key01',
password: 'testtest'
};
sshkeys.init(mockSettings, mockRuntime).then(function() {
sshkeys.generateSSHKey(username, options).then(function(retObj) {
retObj.should.be.equal(options.name);
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should generate sshkey file with size data', function(done) {
this.timeout(20000);
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var options = {
comment: 'test@test.com',
name: 'test-key01',
size: 4096
};
sshkeys.init(mockSettings, mockRuntime).then(function() {
sshkeys.generateSSHKey(username, options).then(function(retObj) {
retObj.should.be.equal(options.name);
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should generate sshkey file with password & size data', function(done) {
this.timeout(20000);
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var options = {
comment: 'test@test.com',
name: 'test-key01',
password: 'testtest',
size: 4096
};
sshkeys.init(mockSettings, mockRuntime).then(function() {
sshkeys.generateSSHKey(username, options).then(function(retObj) {
retObj.should.be.equal(options.name);
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name)).should.be.true();
fs.existsSync(path.join(sshkeyDirPath,username+'_'+options.name+'.pub')).should.be.true();
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should not generate sshkey file with illegal size data', function(done) {
this.timeout(10000);
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var options = {
comment: 'test@test.com',
name: 'test-key01',
size: 1023
};
sshkeys.init(mockSettings, mockRuntime).then(function() {
sshkeys.generateSSHKey(username, options).then(function(retObj) {
done(new Error('Does NOT throw error!'));
}).catch(function(err) {
try {
err.should.have.property('code', 'key_length_too_short');
done();
}
catch (error) {
done(error);
}
});
}).catch(function(err) {
done(err);
});
});
it('should not generate sshkey file with illegal password', function(done) {
this.timeout(10000);
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var options = {
comment: 'test@test.com',
name: 'test-key01',
password: 'aa'
};
sshkeys.init(mockSettings, mockRuntime).then(function() {
sshkeys.generateSSHKey(username, options).then(function(retObj) {
done(new Error('Does NOT throw error!'));
}).catch(function(err) {
try {
err.should.have.property('code', 'key_passphrase_too_short');
done();
}
catch (error) {
done(error);
}
});
}).catch(function(err) {
done(err);
});
});
it('should get sshkey file content', function(done) {
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var filename = 'test-key01';
var fileContent = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD3a+sgtgzSbbliWxmOq5p6+H/mE+0gjWfLWrkIVmHENd1mifV4uCmIHAR2NfuadUYMQ3+bQ90kpmmEKTMYPsyentsKpHQZxTzG7wOCAIpJnbPTHDMxEJhVTaAwEjbVyMSIzTTPfnhoavWIBu0+uMgKDDlBm+RjlgkFlyhXyCN6UwFrIUUMH6Gw+eQHLiooKIl8ce7uDxIlt+9b7hFCU+sQ3kvuse239DZluu6+8buMWqJvrEHgzS9adRFKku8nSPAEPYn85vDi7OgVAcLQufknNgs47KHBAx9h04LeSrFJ/P5J1b//ItRpMOIme+O9d1BR46puzhvUaCHLdvO9czj+OmW+dIm+QIk6lZIOOMnppG72kZxtLfeKT16ur+2FbwAdL9ItBp4BI/YTlBPoa5mLMxpuWfmX1qHntvtGc9wEwS1P7YFfmF3XiK5apxalzrn0Qlr5UmDNbVIqJb1OlbC0w03Z0oktti1xT+R2DGOLWM4lBbpXDHV1BhQ7oYOvbUD8Cnof55lTP0WHHsOHlQc/BGDti1XA9aBX/OzVyzBUYEf0pkimsD0RYo6aqt7QwehJYdlz9x1NBguBffT0s4NhNb9IWr+ASnFPvNl2sw4XH/8U0J0q8ZkMpKkbLM1Zdp1Fv00GF0f5UNRokai6uM3w/ccantJ3WvZ6GtctqytWrw== \n";
sshkeys.init(mockSettings, mockRuntime).then(function() {
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename),"","utf8");
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename+".pub"),fileContent,"utf8");
sshkeys.getSSHKey(username, filename).then(function(retObj) {
retObj.should.be.equal(fileContent);
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
it('should delete sshkey files', function(done) {
var sshkeyDirPath = path.join(userDir, 'projects', '.sshkeys');
var username = 'test';
var filename = 'test-key01';
var fileContent = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD3a+sgtgzSbbliWxmOq5p6+H/mE+0gjWfLWrkIVmHENd1mifV4uCmIHAR2NfuadUYMQ3+bQ90kpmmEKTMYPsyentsKpHQZxTzG7wOCAIpJnbPTHDMxEJhVTaAwEjbVyMSIzTTPfnhoavWIBu0+uMgKDDlBm+RjlgkFlyhXyCN6UwFrIUUMH6Gw+eQHLiooKIl8ce7uDxIlt+9b7hFCU+sQ3kvuse239DZluu6+8buMWqJvrEHgzS9adRFKku8nSPAEPYn85vDi7OgVAcLQufknNgs47KHBAx9h04LeSrFJ/P5J1b//ItRpMOIme+O9d1BR46puzhvUaCHLdvO9czj+OmW+dIm+QIk6lZIOOMnppG72kZxtLfeKT16ur+2FbwAdL9ItBp4BI/YTlBPoa5mLMxpuWfmX1qHntvtGc9wEwS1P7YFfmF3XiK5apxalzrn0Qlr5UmDNbVIqJb1OlbC0w03Z0oktti1xT+R2DGOLWM4lBbpXDHV1BhQ7oYOvbUD8Cnof55lTP0WHHsOHlQc/BGDti1XA9aBX/OzVyzBUYEf0pkimsD0RYo6aqt7QwehJYdlz9x1NBguBffT0s4NhNb9IWr+ASnFPvNl2sw4XH/8U0J0q8ZkMpKkbLM1Zdp1Fv00GF0f5UNRokai6uM3w/ccantJ3WvZ6GtctqytWrw== \n";
sshkeys.init(mockSettings, mockRuntime).then(function() {
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename),"","utf8");
fs.writeFileSync(path.join(sshkeyDirPath,username+"_"+filename+".pub"),fileContent,"utf8");
sshkeys.deleteSSHKey(username, filename).then(function() {
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename)).should.be.false();
fs.existsSync(path.join(sshkeyDirPath,username+'_'+filename+'.pub')).should.be.false();
done();
}).catch(function(err) {
done(err);
});
}).catch(function(err) {
done(err);
});
});
});

View File

@@ -0,0 +1,109 @@
/**
* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var should = require("should");
var sinon = require("sinon");
var child_process = require('child_process');
var EventEmitter = require("events");
var keygen = require("../../../../../../../red/runtime/storage/localfilesystem/projects/ssh/keygen")
describe("localfilesystem/projects/ssh/keygen", function() {
afterEach(function() {
if (child_process.spawn.restore) {
child_process.spawn.restore();
}
})
it("invokes sshkeygen", 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.emit("close",0);
},50)
return e;
});
keygen.generateKey({
size: 1024,
location: 'location',
comment: 'comment',
password: 'password'
}).then(function(output) {
output.should.equal("result");
done();
}).catch(function(err) {
done(err);
})
})
it("reports passphrase too short", function(done) {
var command;
var args;
var opts;
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;
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();
}
});
});