-
Notifications
You must be signed in to change notification settings - Fork 696
Expand file tree
/
Copy pathcred.js
More file actions
73 lines (61 loc) · 2.16 KB
/
cred.js
File metadata and controls
73 lines (61 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var assert = require("assert");
var path = require("path");
var fs = require("fs");
var local = path.join.bind(path, __dirname);
describe("Cred", function() {
var NodeGit = require("../../");
var sshPublicKey = local("../id_rsa.pub");
var sshPrivateKey = local("../id_rsa");
it("can create default credentials", function() {
var defaultCreds = NodeGit.Credential.defaultNew();
assert.ok(defaultCreds instanceof NodeGit.Credential);
});
it("can create ssh credentials using passed keys", function() {
var cred = NodeGit.Credential.sshKeyNew(
"username",
sshPublicKey,
sshPrivateKey,
"");
assert.ok(cred instanceof NodeGit.Credential);
});
it("can create ssh credentials using passed keys in memory", function() {
var publicKeyContents = fs.readFileSync(sshPublicKey, {
encoding: "ascii"
});
var privateKeyContents = fs.readFileSync(sshPrivateKey, {
encoding: "ascii"
});
return NodeGit.Credential.sshKeyMemoryNew(
"username",
publicKeyContents,
privateKeyContents,
"").then(function(cred) {
assert.ok(cred instanceof NodeGit.Credential);
});
});
it("can create credentials using plaintext", function() {
var plaintextCreds = NodeGit.Credential.userpassPlaintextNew
("username", "password");
assert.ok(plaintextCreds instanceof NodeGit.Credential);
});
it("can create credentials using agent", function() {
var fromAgentCreds = NodeGit.Credential.sshKeyFromAgent
("username");
assert.ok(fromAgentCreds instanceof NodeGit.Credential);
});
it("can create credentials using username", function() {
return NodeGit.Credential.usernameNew
("username").then(function(cred) {
assert.ok(cred instanceof NodeGit.Credential);
});
});
it("can return 1 if a username exists", function() {
var plaintextCreds = NodeGit.Credential.userpassPlaintextNew
("username", "password");
assert.ok(plaintextCreds.hasUsername() === 1);
});
it("can return 0 if a username does not exist", function() {
var defaultCreds = NodeGit.Credential.defaultNew();
assert.ok(defaultCreds.hasUsername() === 0);
});
});