This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-thali-callback.js
93 lines (81 loc) · 2.65 KB
/
test-thali-callback.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
'use strict';
var request = require('supertest'),
express = require('express'),
fspath = require('path'),
colors = require('colors'),
assert = require('assert');
var lib = require(fspath.join(__dirname, '../lib/index'));
var dbName = 'foobar';
var pathPrefix = '/' + dbName + '/_local/thali__ID_';
var validId = 'zz-xx--bb';
function verifyThaliUser(idToCheck) {
console.log(colors.green('checking ID: %s'), idToCheck);
return validId === idToCheck;
}
function genericHandlers(router, path) {
var handlers = require('./handlers2');
router.get(path, handlers.get);
router.post(path, handlers.post);
router.put(path, handlers.put);
router.head(path, handlers.head);
router.options(path, handlers.options);
router.delete(path, handlers.options);
return router;
}
describe('We are validating requests that look like /db/_local/thali_:ID', function() {
describe('if the request is ../thali_ and nothing', function(done) {
var app, router; app = express(); router = express.Router();
var rootPath = '/' + dbName + '/_local/thali_';
var pathWithId = rootPath + validId;
before(function() {
//mocker..
router.all('*', function(req, res, next) {
req.connection.pskRole = 'repl';
next();
})
//Norml middleware usage..0
var acl = require('./acl-block.1.js');
router.all('*', lib('foobar', acl, verifyThaliUser));
//mock handlers
app.use('/', genericHandlers(router, pathWithId));
})
/** mapped paths mix of verbs */
it('GET should be OK - we are using ' + validId, function(done) {
request(app)
.get(pathWithId)
.set('Accept', 'application/json')
.expect(200, done);
})
it('PUT should be OK - we are using ' + validId, function(done) {
request(app)
.put(pathWithId)
.set('Accept', 'application/json')
.expect(200, done);
})
it('DELETE should be OK - we are using ' + validId, function(done) {
request(app)
.delete(pathWithId)
.set('Accept', 'application/json')
.expect(200, done);
})
it('POST should fail no acl for verb - we are using ' + validId, function(done) {
request(app)
.post(pathWithId)
.set('Accept', 'application/json')
.expect(401, done);
})
/** unmapped paths */
it('should fail with a 401 as not valid', function(done) {
request(app)
.get(rootPath)
.set('Accept', 'application/json')
.expect(401, done);
})
it('should OK as full path', function(done) {
request(app)
.get(pathWithId)
.set('Accept', 'application/json')
.expect(200, done);
})
})
})