74 lines
10 KiB
JavaScript
74 lines
10 KiB
JavaScript
"use strict";
|
|
require("typings-test");
|
|
require("should");
|
|
var smartssh = require("../dist/index");
|
|
var path = require("path");
|
|
describe("smartssh", function () {
|
|
var testSshInstance;
|
|
var testSshKey;
|
|
describe(".SshKey", function () {
|
|
it("'new' keyword should create a valid SshKey object", function () {
|
|
testSshKey = new smartssh.SshKey({
|
|
host: "example.com",
|
|
private: "someExamplePrivateKey",
|
|
public: "someExamplePublicKey"
|
|
});
|
|
testSshKey.should.be.instanceof(smartssh.SshKey);
|
|
});
|
|
it(".type should be a valid type", function () {
|
|
testSshKey.type.should.equal("duplex");
|
|
});
|
|
it(".publicKey should be public key", function () {
|
|
testSshKey.pubKey.should.equal("someExamplePublicKey");
|
|
});
|
|
it(".privateKey should be private key", function () {
|
|
testSshKey.privKey.should.equal("someExamplePrivateKey");
|
|
});
|
|
it(".publicKeyBase64 should be public key base 64 encoded", function () {
|
|
testSshKey.pubKeyBase64;
|
|
});
|
|
it(".store() should store the file to disk", function () {
|
|
testSshKey.store(path.join(process.cwd(), "test/temp"));
|
|
});
|
|
});
|
|
describe(".SshInstance", function () {
|
|
it("'new' keyword should create a new SshInstance object from class", function () {
|
|
testSshInstance = new smartssh.SshInstance();
|
|
testSshInstance.should.be.instanceof(smartssh.SshInstance);
|
|
});
|
|
it(".addKey() should accept a new SshKey object", function () {
|
|
testSshInstance.addKey(new smartssh.SshKey({
|
|
public: "somePublicKey",
|
|
private: "somePrivateKey",
|
|
host: "gitlab.com"
|
|
}));
|
|
testSshInstance.addKey(new smartssh.SshKey({
|
|
public: "somePublicKey",
|
|
private: "somePrivateKey",
|
|
host: "bitbucket.org"
|
|
}));
|
|
testSshInstance.addKey(new smartssh.SshKey({
|
|
public: "someGitHubPublicKey",
|
|
private: "someGitHubPrivateKey",
|
|
host: "github.com"
|
|
}));
|
|
});
|
|
it(".sshKeys should point to an array of sshKeys", function () {
|
|
var 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").pubKey.should.equal("someGitHubPublicKey");
|
|
});
|
|
it(".removeKey() should remove a key", function () {
|
|
testSshInstance.removeKey(testSshInstance.getKey("bitbucket.org"));
|
|
testSshInstance.sshKeys[1].host.should.equal("github.com");
|
|
});
|
|
});
|
|
});
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FDUCxDQUFDLENBRG9CO0FBQ3JCLFFBQU8sUUFBUSxDQUFDLENBQUE7QUFDaEIsSUFBTyxRQUFRLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDM0MsSUFBTyxJQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDOUIsUUFBUSxDQUFDLFVBQVUsRUFBQztJQUNoQixJQUFJLGVBQW9DLENBQUM7SUFDekMsSUFBSSxVQUEwQixDQUFDO0lBQy9CLFFBQVEsQ0FBQyxTQUFTLEVBQUM7UUFDZixFQUFFLENBQUMsbURBQW1ELEVBQUM7WUFDbkQsVUFBVSxHQUFHLElBQUksUUFBUSxDQUFDLE1BQU0sQ0FBQztnQkFDN0IsSUFBSSxFQUFDLGFBQWE7Z0JBQ2xCLE9BQU8sRUFBQyx1QkFBdUI7Z0JBQy9CLE1BQU0sRUFBQyxzQkFBc0I7YUFDaEMsQ0FBQyxDQUFDO1lBQ0gsVUFBVSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUMsQ0FBQztRQUNyRCxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQ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