mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test(static) auth: coverage
This commit is contained in:
parent
cd0fad79e8
commit
54a72bd714
1 changed files with 83 additions and 2 deletions
|
|
@ -5,14 +5,20 @@ const {promisify} = require('es6-promisify');
|
|||
const pullout = require('pullout');
|
||||
const request = require('request');
|
||||
|
||||
const configFn = require('../server/config');
|
||||
const before = require('./before');
|
||||
|
||||
const warp = (fn, ...a) => (...b) => fn(...b, ...a);
|
||||
|
||||
const _pullout = promisify(pullout);
|
||||
|
||||
const get = promisify((url, fn) => {
|
||||
fn(null, request(url));
|
||||
const get = promisify((url, options, fn) => {
|
||||
if (!fn) {
|
||||
fn = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
fn(null, request(url, options));
|
||||
});
|
||||
|
||||
test('cloudcmd: static', (t) => {
|
||||
|
|
@ -91,6 +97,81 @@ test('cloudcmd: /cloudcmd.js', (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /cloudcmd.js: auth: access denied', (t) => {
|
||||
const config = {
|
||||
auth: true
|
||||
};
|
||||
|
||||
before({config}, (port, after) => {
|
||||
const name = 'cloudcmd.js';
|
||||
|
||||
get(`http://localhost:${port}/${name}`)
|
||||
.then((res) => {
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return auth');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /cloudcmd.js: auth: no password', (t) => {
|
||||
const config = {
|
||||
auth: true
|
||||
};
|
||||
|
||||
const auth = {
|
||||
username: configFn('username'),
|
||||
};
|
||||
|
||||
before({config}, (port, after) => {
|
||||
const name = 'cloudcmd.js';
|
||||
|
||||
get(`http://localhost:${port}/${name}`, {auth})
|
||||
.then((res) => {
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return auth');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /cloudcmd.js: auth: access granted', (t) => {
|
||||
const config = {
|
||||
auth: true
|
||||
};
|
||||
|
||||
const auth = {
|
||||
username: configFn('username'),
|
||||
password: configFn('password'),
|
||||
};
|
||||
|
||||
before({config}, (port, after) => {
|
||||
const name = 'cloudcmd.js';
|
||||
|
||||
get(`http://localhost:${port}/${name}`, {auth})
|
||||
.then((res) => {
|
||||
res.on('response', ({statusCode}) => {
|
||||
t.equal(statusCode, 401, 'should return auth');
|
||||
});
|
||||
res.on('end', () => {
|
||||
t.end();
|
||||
after();
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
});
|
||||
});
|
||||
|
||||
test('cloudcmd: /logout', (t) => {
|
||||
before({}, (port, after) => {
|
||||
const name = 'logout';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue