-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathapi-messages.js
More file actions
121 lines (115 loc) · 3.58 KB
/
api-messages.js
File metadata and controls
121 lines (115 loc) · 3.58 KB
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
113
114
115
116
117
118
119
120
121
const Solid = require('../')
const parallel = require('run-parallel')
const path = require('path')
const hippie = require('hippie')
const fs = require('fs')
// In this test we always assume that we are Alice
describe('Messages API', () => {
let aliceServer
const bobCert = {
cert: fs.readFileSync(path.join(__dirname, '/keys/user2-cert.pem')),
key: fs.readFileSync(path.join(__dirname, '/keys/user2-key.pem'))
}
const aliceCert = {
cert: fs.readFileSync(path.join(__dirname, '/keys/user1-cert.pem')),
key: fs.readFileSync(path.join(__dirname, '/keys/user1-key.pem'))
}
const alicePod = Solid.createServer({
root: path.join(__dirname, '/resources/messaging-scenario'),
sslKey: path.join(__dirname, '/keys/key.pem'),
sslCert: path.join(__dirname, '/keys/cert.pem'),
auth: 'tls',
dataBrowser: false,
fileBrowser: false,
webid: true,
idp: true
})
before(function (done) {
parallel([
(cb) => {
aliceServer = alicePod.listen(5000, cb)
}
], done)
})
after(function () {
if (aliceServer) aliceServer.close()
})
describe('endpoints', () => {
describe('/api/messages', () => {
it('should send 401 if user is not logged in', (done) => {
hippie()
.post('https://localhost:5000/api/messages')
.expectStatus(401)
.end(done)
})
it('should send 406 if message is missing', (done) => {
hippie()
// .json()
.use(function (options, next) {
options.agentOptions = bobCert
options.strictSSL = false
next(options)
})
.post('https://localhost:5000/api/messages')
.expectStatus(406)
.end(done)
})
it('should send 403 user is not of this IDP', (done) => {
hippie()
// .json()
.use(function (options, next) {
options.agentOptions = bobCert
options.strictSSL = false
next(options)
})
.form()
.send({message: 'thisisamessage', to: 'mailto:mail@email.com'})
.post('https://localhost:5000/api/messages')
.expectStatus(403)
.end(done)
})
it('should send 406 if not destination `to` is specified', (done) => {
hippie()
// .json()
.use(function (options, next) {
options.agentOptions = aliceCert
options.strictSSL = false
next(options)
})
.form()
.send({message: 'thisisamessage'})
.post('https://localhost:5000/api/messages')
.expectStatus(406)
.end(done)
})
it('should send 406 if not destination `to` is missing the protocol', (done) => {
hippie()
// .json()
.use(function (options, next) {
options.agentOptions = aliceCert
options.strictSSL = false
next(options)
})
.form()
.send({message: 'thisisamessage', to: 'mail@email.com'})
.post('https://localhost:5000/api/messages')
.expectStatus(406)
.end(done)
})
it('should send 406 if messaging protocol is not supported', (done) => {
hippie()
// .json()
.use(function (options, next) {
options.agentOptions = aliceCert
options.strictSSL = false
next(options)
})
.form()
.send({message: 'thisisamessage', to: 'email2:mail@email.com'})
.post('https://localhost:5000/api/messages')
.expectStatus(406)
.end(done)
})
})
})
})