forked from nodejitsu/haibu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth-token-test.js
66 lines (61 loc) · 1.49 KB
/
auth-token-test.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
/*
* drone-api-test.js: Tests for the `drone` module's RESTful API.
*
* (C) 2010, Nodejitsu Inc.
*
*/
var assert = require('assert'),
exec = require('child_process').exec,
fs = require('fs'),
path = require('path'),
eyes = require('eyes'),
request = require('request'),
vows = require('vows'),
helpers = require('../helpers'),
data = require('../fixtures/apps'),
haibu = require('../../lib/haibu');
var ipAddress = '127.0.0.1',
port = 9000,
app = data.apps[0],
server;
app.user = 'marak';
haibu.config.set('authToken', 'haibu');
var auth = {
'X-Auth-Token': 'haibu'
},
noAuth = {
'X-Auth-Token': 'not-haibu'
};
vows.describe('haibu/drone/api').addBatch(
helpers.requireStart(port, function (_server) {
server = _server;
})
).addBatch({
"When using the drone server": {
"with incorrect auth token": {
"a request against /": helpers.requireResponse('/', noAuth, 403),
"a request against /version": helpers.requireResponse(
'/version',
noAuth,
403
)
},
"with correct auth token": {
"a request against /": helpers.requireResponse('/', auth, 400),
"a request against /version": helpers.requireResponse(
'/version',
auth,
200
)
}
}
}).addBatch({
"when the tests are over": {
topic: function () {
return false;
},
"the server should clean up": function () {
server.close();
}
}
}).export(module);