forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp-copy-test.js
More file actions
96 lines (86 loc) · 2.96 KB
/
http-copy-test.js
File metadata and controls
96 lines (86 loc) · 2.96 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
var assert = require('chai').assert
var fs = require('fs')
var request = require('request')
var path = require('path')
// Helper functions for the FS
var rm = require('./../utils').rm
var solidServer = require('../../index')
describe('HTTP COPY API', function () {
var address = 'https://localhost:3456'
var ldpHttpsServer
var ldp = solidServer.createServer({
root: path.join(__dirname, '../resources/accounts/localhost/'),
sslKey: path.join(__dirname, '../keys/key.pem'),
sslCert: path.join(__dirname, '../keys/cert.pem'),
webid: false
})
before(function (done) {
ldpHttpsServer = ldp.listen(3456, done)
})
after(function () {
if (ldpHttpsServer) ldpHttpsServer.close()
// Clean up after COPY API tests
return Promise.all([
rm('/accounts/localhost/sampleUser1Container/nicola-copy.jpg')
])
})
var userCredentials = {
user1: {
cert: fs.readFileSync(path.join(__dirname, '../keys/user1-cert.pem')),
key: fs.readFileSync(path.join(__dirname, '../keys/user1-key.pem'))
},
user2: {
cert: fs.readFileSync(path.join(__dirname, '../keys/user2-cert.pem')),
key: fs.readFileSync(path.join(__dirname, '../keys/user2-key.pem'))
}
}
function createOptions (method, url, user) {
var options = {
method: method,
url: url,
headers: {}
}
if (user) {
options.agentOptions = userCredentials[user]
}
return options
}
it('should create the copied resource', function (done) {
var copyFrom = '/samplePublicContainer/nicola.jpg'
var copyTo = '/sampleUser1Container/nicola-copy.jpg'
var uri = address + copyTo
var options = createOptions('COPY', uri, 'user1')
options.headers[ 'Source' ] = copyFrom
request(uri, options, function (error, response) {
assert.equal(error, null)
assert.equal(response.statusCode, 201)
assert.equal(response.headers[ 'location' ], copyTo)
let destinationPath = path.join(__dirname, '../resources/accounts/localhost', copyTo)
assert.ok(fs.existsSync(destinationPath),
'Resource created via COPY should exist')
done()
})
})
it('should give a 404 if source document doesn\'t exist', function (done) {
var copyFrom = '/samplePublicContainer/invalid-resource'
var copyTo = '/sampleUser1Container/invalid-resource-copy'
var uri = address + copyTo
var options = createOptions('COPY', uri, 'user1')
options.headers[ 'Source' ] = copyFrom
request(uri, options, function (error, response) {
assert.equal(error, null)
assert.equal(response.statusCode, 404)
done()
})
})
it('should give a 400 if Source header is not supplied', function (done) {
var copyTo = '/sampleUser1Container/nicola-copy.jpg'
var uri = address + copyTo
var options = createOptions('COPY', uri, 'user1')
request(uri, options, function (error, response) {
assert.equal(error, null)
assert.equal(response.statusCode, 400)
done()
})
})
})