-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconstructor.js
112 lines (79 loc) · 2.86 KB
/
constructor.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { EventEmitter } from 'events';
import { expect } from 'chai';
import Connection from 'ssh2';
import Adit from '../index';
describe('Adit#constructor', () => {
const oldSock = process.env.SSH_AUTH_SOCK;
const oldHome = process.env.HOME;
let to;
beforeEach(() => {
to = {
host: 'to-host',
port: 2
};
});
afterEach(() => {
process.env.SSH_AUTH_SOCK = oldSock;
process.env.HOME = oldHome;
});
it('should define all needed properties with "settings" object', () => {
process.env.SSH_AUTH_SOCK = 'tmp';
const adit = new Adit(to);
expect(adit.portRange).to.equal(to.port);
expect(adit.port).to.equal(to.port);
expect(adit.username).to.equal(process.env.USER);
expect(adit.password).to.equal(null);
expect(adit.agent).to.equal('tmp');
expect(adit.key).to.equal(null);
expect(adit.password).to.equal(null);
expect(adit.defer).to.equal(undefined);
expect(adit.promise).to.have.property('then');
expect(adit.promise).to.not.have.property('resolve');
expect(adit.connection).to.be.an.instanceof(Connection);
expect(adit.events).to.be.an.instanceof(EventEmitter);
});
it('should define all needed properties with string argument', () => {
process.env.SSH_AUTH_SOCK = 'tmp';
const adit = new Adit('9999:localhost:3306 8.8.8.8');
expect(adit.portRange).to.equal(22);
expect(adit.port).to.equal(22);
expect(adit.username).to.equal(process.env.USER);
expect(adit.password).to.equal(null);
expect(adit.agent).to.equal('tmp');
expect(adit.key).to.equal(null);
expect(adit.password).to.equal(null);
expect(adit.defer).to.equal(undefined);
expect(adit.promise).to.have.property('then');
expect(adit.promise).to.not.have.property('resolve');
expect(adit.connection).to.be.an.instanceof(Connection);
expect(adit.events).to.be.an.instanceof(EventEmitter);
});
it('should set password to key or agent', () => {
delete process.env.SSH_AUTH_SOCK;
to.password = 'pass';
const adit = new Adit(to);
expect(adit.password).to.equal('pass');
expect(adit.agent).to.equal(null);
expect(adit.key).to.equal(null);
});
it('should define port with port range', () => {
to.port = [1, 5];
const adit = new Adit(to);
expect(adit.port).to.be.within(1, 5);
expect(adit.portRange).to.equal(to.port);
expect(to.port).to.not.equal(adit.port);
});
it('should custom username and password', () => {
to.username = 'me';
to.password = 'pass';
const adit = new Adit(to);
expect(adit.username).to.equal('me');
expect(adit.password).to.equal('pass');
});
it('should throw if there is not authorization strategy', () => {
delete process.env.SSH_AUTH_SOCK;
delete process.env.HOME;
const constructor = () => new Adit(to);
expect(constructor).to.throw(/SSH-agent is not enabled/);
});
});