added more tests
This commit is contained in:
parent
09d96fd94c
commit
78aa36c2be
1
dist/smartssh.classes.helpers.d.ts
vendored
1
dist/smartssh.classes.helpers.d.ts
vendored
@ -1,4 +1,3 @@
|
||||
import "typings-global";
|
||||
import { SshKey } from "./smartssh.classes.sshkey";
|
||||
export declare let sshKeyArrayFromDir: (dirArg: string) => SshKey[];
|
||||
export declare let getKeyIndex: (hostArg: string) => number;
|
||||
|
5
dist/smartssh.classes.helpers.js
vendored
5
dist/smartssh.classes.helpers.js
vendored
@ -4,8 +4,5 @@ exports.sshKeyArrayFromDir = function (dirArg) {
|
||||
var sshKeyArray = []; //TODO
|
||||
return sshKeyArray;
|
||||
};
|
||||
exports.getKeyIndex = function (hostArg) {
|
||||
return 0; //TODO
|
||||
};
|
||||
|
||||
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3NoLmNsYXNzZXMuaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBSVosMEJBQWtCLEdBQUcsVUFBUyxNQUFhO0lBQ2xELElBQUksV0FBVyxHQUFHLEVBQUUsQ0FBQyxDQUFDLE1BQU07SUFDNUIsTUFBTSxDQUFDLFdBQVcsQ0FBQztBQUN2QixDQUFDLENBQUE7QUFFVSxtQkFBVyxHQUFHLFVBQVMsT0FBYztJQUM1QyxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUMsT0FBTztBQUNyQixDQUFDLENBQUEiLCJmaWxlIjoic21hcnRzc2guY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFwidHlwaW5ncy1nbG9iYWxcIlxyXG5pbXBvcnQgKiBhcyBwbHVnaW5zIGZyb20gXCIuL3NtYXJ0c3NoLnBsdWdpbnNcIjtcclxuaW1wb3J0IHtTc2hLZXl9IGZyb20gXCIuL3NtYXJ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IHNzaEtleUFycmF5O1xyXG59Il19
|
||||
|
2
dist/smartssh.classes.sshinstance.d.ts
vendored
2
dist/smartssh.classes.sshinstance.d.ts
vendored
@ -3,7 +3,7 @@ import { SshKey } from "./smartssh.classes.sshkey";
|
||||
export declare class SshInstance {
|
||||
private sshConfig;
|
||||
private sshDir;
|
||||
private sshKeysVar;
|
||||
private sshKeyArray;
|
||||
private sshSync;
|
||||
constructor(optionsArg?: {
|
||||
sshDirPath?: string;
|
||||
|
33
dist/smartssh.classes.sshinstance.js
vendored
33
dist/smartssh.classes.sshinstance.js
vendored
File diff suppressed because one or more lines are too long
4
dist/smartssh.classes.sshkey.js
vendored
4
dist/smartssh.classes.sshkey.js
vendored
File diff suppressed because one or more lines are too long
21
test/test.js
21
test/test.js
File diff suppressed because one or more lines are too long
19
test/test.ts
19
test/test.ts
@ -5,11 +5,11 @@ describe("smartssh",function(){
|
||||
let testSshInstance:smartssh.SshInstance;
|
||||
let testSshKey:smartssh.SshKey;
|
||||
describe("SshInstance",function(){
|
||||
it("should create a new SshInstance object from class",function(){
|
||||
it("'new' keyword should create a new SshInstance object from class",function(){
|
||||
testSshInstance = new smartssh.SshInstance();
|
||||
testSshInstance.should.be.instanceof(smartssh.SshInstance);
|
||||
});
|
||||
it("should accept a new SshKey object",function(){
|
||||
it(".addKey() should accept a new SshKey object",function(){
|
||||
testSshInstance.addKey(new smartssh.SshKey({
|
||||
public:"somePublicKey",
|
||||
private:"somePrivateKey",
|
||||
@ -21,15 +21,24 @@ describe("smartssh",function(){
|
||||
host:"bitbucket.org"
|
||||
}));
|
||||
testSshInstance.addKey(new smartssh.SshKey({
|
||||
public:"somePublicKey",
|
||||
private:"somePrivateKey",
|
||||
public:"someGitHubPublicKey",
|
||||
private:"someGitHubPrivateKey",
|
||||
host:"github.com"
|
||||
}));
|
||||
});
|
||||
it("should return an array of sshKeys",function(){
|
||||
it(".sshKeys should point to an array of sshKeys",function(){
|
||||
let sshKeyArray = testSshInstance.sshKeys;
|
||||
sshKeyArray.should.be.Array();
|
||||
sshKeyArray[0].host.should.equal("gitlab.com");
|
||||
sshKeyArray[1].host.should.equal("bitbucket.org");
|
||||
sshKeyArray[2].host.should.equal("github.com");
|
||||
});
|
||||
it(".getKey() should get a specific key selected by host",function(){
|
||||
testSshInstance.getKey("github.com").publicKey.should.equal("someGitHubPublicKey");
|
||||
})
|
||||
it(".removeKey() should remove a key",function(){
|
||||
testSshInstance.removeKey(testSshInstance.getKey("bitbucket.org"));
|
||||
testSshInstance.sshKeys[1].host.should.equal("github.com");
|
||||
})
|
||||
})
|
||||
})
|
@ -5,8 +5,4 @@ import {SshKey} from "./smartssh.classes.sshkey";
|
||||
export let sshKeyArrayFromDir = function(dirArg:string):SshKey[]{
|
||||
let sshKeyArray = []; //TODO
|
||||
return sshKeyArray;
|
||||
}
|
||||
|
||||
export let getKeyIndex = function(hostArg:string){
|
||||
return 0; //TODO
|
||||
}
|
@ -27,19 +27,23 @@ export class SshInstance {
|
||||
};
|
||||
removeKey(sshKeyArg:SshKey){
|
||||
this.sync("from");
|
||||
let keyIndex = helpers.getKeyIndex(sshKeyArg.host);
|
||||
this.sshKeyArray.splice(keyIndex,1);
|
||||
let filteredArray = this.sshKeyArray.filter((sshKeyArg2:SshKey) => {
|
||||
return (sshKeyArg != sshKeyArg2);
|
||||
});
|
||||
this.sshKeyArray = filteredArray;
|
||||
this.sync("to");
|
||||
};
|
||||
replaceKey(sshKeyOldArg:SshKey,sshKeyNewArg:SshKey){
|
||||
this.sync("from");
|
||||
let keyIndex = helpers.getKeyIndex(sshKeyOldArg.host);
|
||||
this.sshKeyArray.splice(keyIndex,1,sshKeyNewArg);
|
||||
let filteredArray = this.sshKeyArray.filter((sshKeyArg:SshKey) => {
|
||||
return (sshKeyArg.host == "some"); //TODO
|
||||
});
|
||||
this.sshKeyArray = filteredArray;
|
||||
this.sync("to");
|
||||
};
|
||||
|
||||
//
|
||||
getKey(hostArg:string){
|
||||
getKey(hostArg:string):SshKey{
|
||||
this.sync("from");
|
||||
let filteredArray = this.sshKeyArray.filter(function(keyArg){
|
||||
return (keyArg.host == hostArg);
|
||||
@ -56,9 +60,9 @@ export class SshInstance {
|
||||
sync(directionArg:string){
|
||||
if(this.sshSync && directionArg == "from"){
|
||||
this.sshDir.syncFromDir(); // call sync method of sshDir class;
|
||||
} else if (this.sshSync && directionArg == "to") {
|
||||
} else if(this.sshSync && directionArg == "to") {
|
||||
this.sshDir.syncToDir();
|
||||
} else {
|
||||
} else if(this.sshSync) {
|
||||
throw new Error("directionArg not recognised. Must be 'to' or 'from'");
|
||||
}
|
||||
};
|
||||
|
@ -23,7 +23,7 @@ export class SshKey {
|
||||
return plugins.base64.encode(this.privKey);
|
||||
}
|
||||
get publicKey(){
|
||||
return this.publicKey;
|
||||
return this.pubKey;
|
||||
}
|
||||
get publicKeyBase64(){
|
||||
return plugins.base64.encode(this.pubKey);
|
||||
|
Loading…
Reference in New Issue
Block a user