Skip to content

Commit 5538e6c

Browse files
committed
Merge branch 'develop', prepare 1.0.2
2 parents 5bf931e + 1c001c6 commit 5538e6c

File tree

6 files changed

+321
-94
lines changed

6 files changed

+321
-94
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
"scripts": {
1313
"test": "TZ=Greenland NODE_ENV=testing tap --cov --coverage-report=lcov --reporter=spec ./test/index.js",
1414
"coveralls": "cat ./coverage/lcov.info | coveralls",
15-
"package": "pkg --targets node8.3.0-linux-x64,node8.3.0-win-x64,node8.3.0-macos-x64 -o exoframe index.js"
15+
"package": "pkg --targets node8.6.0-linux-x64,node8.6.0-win-x64,node8.6.0-macos-x64 -o exoframe index.js"
1616
},
1717
"dependencies": {
1818
"boxen": "^1.2.2",
1919
"chalk": "^2.3.0",
2020
"cli-table": "^0.3.1",
21-
"got": "^7.1.0",
21+
"got": "^8.0.0",
2222
"highland": "^2.11.1",
2323
"ignore": "^3.3.7",
24-
"inquirer": "^3.3.0",
24+
"inquirer": "^4.0.1",
2525
"js-yaml": "^3.10.0",
2626
"jsonwebtoken": "^8.1.0",
2727
"lodash": "^4.17.4",
@@ -37,6 +37,6 @@
3737
"pkg": "^4.2.5",
3838
"proxyquire": "^1.8.0",
3939
"sinon": "^4.0.2",
40-
"tap": "^10.7.2"
40+
"tap": "^11.0.0"
4141
}
4242
}

src/commands/deploy.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ exports.handler = async (args = {}) => {
136136
spinner = ora('Deploying project to server...').start();
137137
}
138138

139-
// syntax-check config
139+
// syntax-check & validate config
140140
try {
141-
JSON.parse(fs.readFileSync(configPath));
141+
const config = JSON.parse(fs.readFileSync(configPath));
142+
// validate project name
143+
if (!config.name || !config.name.length) {
144+
throw new Error('Project should have a valid name in config!');
145+
}
142146
} catch (e) {
143147
spinner && spinner.fail('Your exoframe.json is not valid');
144148
console.log(chalk.red('Please, check your config and try again:'), e.toString());

test/deploy.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,33 @@ module.exports = () => {
392392
});
393393
});
394394

395+
// test
396+
tap.test('Should not deploy with config without project name', t => {
397+
// spy on console
398+
const consoleSpy = sinon.spy(console, 'log');
399+
400+
// corrupt config with string
401+
const cfg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'exoframe.json')));
402+
cfg.name = '';
403+
fs.writeFileSync(path.join(__dirname, '..', 'exoframe.json'), JSON.stringify(cfg));
404+
405+
// execute deploy
406+
deploy().then(() => {
407+
// check console output
408+
t.deepEqual(
409+
consoleSpy.args,
410+
[
411+
['Deploying current project to endpoint:', 'http://localhost:8080'],
412+
['Please, check your config and try again:', 'Error: Project should have a valid name in config!'],
413+
],
414+
'Correct log output'
415+
);
416+
// restore console
417+
console.log.restore();
418+
t.end();
419+
});
420+
});
421+
395422
// test
396423
tap.test('Should not deploy with broken config', t => {
397424
// spy on console

test/fixtures/id_rsa_keyphrase

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
Proc-Type: 4,ENCRYPTED
3+
DEK-Info: AES-128-CBC,E7426FE8EB7DBCBD6BB2650FE32CD7D5
4+
5+
R18BO71BfqhrikOKAWEf2oFhqfs2UYoV9XlrWI0ZrgKbvDP42kq19baETasEfCRQ
6+
JMWlfUy105uIsnc6oC+htfnaqcAO5WgxZKz0Tfz8jJXrRk2uLP8m9Lt95q1EbpAD
7+
NApJ8YNwOwdrF2KwfZPc6LaUVY5oS6xVgTZxmSxcw9LGhBneyPt1et9fgx/Qwq1h
8+
5JoKR68twACJmaoMLiqXcd9XcBRg31wjJ04ZEkTlyGJOlZd4qEaNCSyVeiWPV7eW
9+
pxDX5yAYomP4hvyYAmK/ywAQk6CpltlM0G+7BlvBqwMag3ib84Wz5sNLYNvZD+jj
10+
TZ9LISBqd1pXROLMP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rUZySK41ezJ3XULb0QL6j/7CVhh1/lGgE48zyvZrgJMfFUV5wAsMOIj/36/EILNv
27+
I0zwoGvihuXyN641/b12bRG5EkyuLynjTBm8dyyhlJAtfRyvOc7F2nzypu31cuXm
28+
9izYsTHqp0HMgBBeFgdKLWPawCvsSkMhzx/jKyvgC2mMnUAXJfw1PHQPXsbaY1Mv
29+
1eYxyl2YkDMhnicoNxHFDYJBlPbb9HQuO1HTHWT9iZYO75msNN/BFf9xuunperSt
30+
-----END RSA PRIVATE KEY-----

test/login.js

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,36 @@ module.exports = () => {
1616
const loginRequest = {phrase: 'test', uid: '123'};
1717
const privateKeyName = path.join(__dirname, 'fixtures', 'id_rsa');
1818
const privateKeyNameBroken = path.join(__dirname, 'fixtures', 'id_rsa_b');
19+
const privateKeyWithPassphrase = path.join(__dirname, 'fixtures', 'id_rsa_keyphrase');
1920
const cert = fs.readFileSync(privateKeyName);
21+
const certKey = fs.readFileSync(privateKeyWithPassphrase);
2022
const certBroken = fs.readFileSync(privateKeyNameBroken);
2123
const reqToken = jwt.sign(loginRequest.phrase, cert, {algorithm: 'RS256'});
24+
const reqTokenKey = jwt.sign(loginRequest.phrase, {key: certKey, passphrase: 'test123'}, {algorithm: 'RS256'});
2225
const reqTokenBroken = jwt.sign(loginRequest.phrase, certBroken, {algorithm: 'RS256'});
2326
const correctLogin = {user: {username: 'admin'}, token: reqToken, requestId: loginRequest.uid};
27+
const correctLoginWithPassphrase = {
28+
user: {username: 'admin'},
29+
token: reqTokenKey,
30+
requestId: loginRequest.uid,
31+
};
2432
const failedLogin = {user: {username: 'broken'}, token: reqTokenBroken, requestId: loginRequest.uid};
2533
const wrongUser = {username: 'wrong', privateKeyName: 'i am broken', password: ''};
2634

2735
// handle correct request
28-
nock('http://localhost:8080').get('/login').times(3).reply(200, loginRequest);
29-
const correctLoginSrv = nock('http://localhost:8080').post('/login', correctLogin).reply(200, {token});
30-
const failedLoginSrv = nock('http://localhost:8080').post('/login', failedLogin).reply(401);
36+
nock('http://localhost:8080')
37+
.get('/login')
38+
.times(4)
39+
.reply(200, loginRequest);
40+
const correctLoginSrv = nock('http://localhost:8080')
41+
.post('/login', correctLogin)
42+
.reply(200, {token});
43+
const correctLoginPassSrv = nock('http://localhost:8080')
44+
.post('/login', correctLoginWithPassphrase)
45+
.reply(200, {token});
46+
const failedLoginSrv = nock('http://localhost:8080')
47+
.post('/login', failedLogin)
48+
.reply(401);
3149

3250
// test login
3351
tap.test('Should login', t => {
@@ -59,6 +77,38 @@ module.exports = () => {
5977
});
6078
});
6179

80+
// test login
81+
tap.test('Should login using key with passphrase', t => {
82+
// stup inquirer answers
83+
sinon
84+
.stub(inquirer, 'prompt')
85+
.callsFake(() => Promise.resolve(Object.assign({}, correctLoginWithPassphrase.user, {password: 'test123'})));
86+
// spy on console
87+
const consoleSpy = sinon.spy(console, 'log');
88+
// execute login
89+
login({key: privateKeyWithPassphrase}).then(() => {
90+
// make sure log in was successful
91+
// check that server was called
92+
t.ok(correctLoginPassSrv.isDone());
93+
// first check console output
94+
t.deepEqual(
95+
consoleSpy.args,
96+
[['Logging in to:', 'http://localhost:8080'], ['Successfully logged in!']],
97+
'Correct log output'
98+
);
99+
// then check config changes
100+
const configPath = path.join(__dirname, 'fixtures', 'cli.config.yml');
101+
const cfg = yaml.safeLoad(fs.readFileSync(configPath, 'utf8'));
102+
t.equal(cfg.token, token, 'Correct token');
103+
t.equal(cfg.user.username, correctLoginWithPassphrase.user.username, 'Correct username');
104+
// restore inquirer
105+
inquirer.prompt.restore();
106+
// restore console
107+
console.log.restore();
108+
t.end();
109+
});
110+
});
111+
62112
// test wrong credentials
63113
tap.test('Should fail to login with broken private key', t => {
64114
// stup inquirer answers

0 commit comments

Comments
 (0)