Skip to content

Commit 37a6930

Browse files
author
Martin Martinez Rivera
committed
Added ACL origin tests.
1 parent 6b64b12 commit 37a6930

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

test/secure-test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ var address = 'https://localhost:3456/test/';
1313
var aclDir = 'aclDir';
1414
var aclExtension = '.acl';
1515
var server = supertest(address);
16+
17+
var user1 = "https://user1.databox.me/profile/card#me";
18+
var user2 = "https://user2.databox.me/profile/card#me";
1619
var userCredentials = {
1720
user1: {
1821
cert: fs.readFileSync('testfiles/user1-cert.pem'),
@@ -114,3 +117,65 @@ describe("Empty ACL Test", function() {
114117
});
115118
});
116119
});
120+
121+
describe("ACL Origin Test", function() {
122+
var origin1 = "http://example.org/";
123+
var origin2 = "http://example.com/";
124+
it("Should PUT new ACL file", function(done) {
125+
var aclFile = aclDir + '/' + aclExtension;
126+
var aclAddress = address + aclFile;
127+
var options = createOptions(aclFile, 'user1');
128+
options.headers = {
129+
'content-type': 'text/turtle'
130+
};
131+
options.body = "<#Owner>\n" +
132+
" <http://www.w3.org/ns/auth/acl#accessTo> <" + address + aclDir + "/" + ">, <" + aclAddress + ">;\n" +
133+
" <http://www.w3.org/ns/auth/acl#agent> <" + user1 + ">;\n" +
134+
" <http://www.w3.org/ns/auth/acl#origin> <" + origin1 + ">;\n" +
135+
" <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read>, <http://www.w3.org/ns/auth/acl#Write> .\n" +
136+
"<#Public>\n" +
137+
" <http://www.w3.org/ns/auth/acl#accessTo> <" + address + aclDir + "/" + ">;\n" +
138+
" <http://www.w3.org/ns/auth/acl#agentClass> <http://xmlns.com/foaf/0.1/Agent>;\n" +
139+
" <http://www.w3.org/ns/auth/acl#origin> <" + origin1 + ">;\n" +
140+
" <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read> .\n";
141+
request.put(options, function(error, response, body) {
142+
assert.equal(error, null);
143+
assert.equal(response.statusCode, 201);
144+
done();
145+
//TODO triple header
146+
//TODO user header
147+
});
148+
});
149+
it("Should be able to access test directory", function(done) {
150+
var options = createOptions(aclDir, 'user1');
151+
request.head(options, function(error, response, body) {
152+
assert.equal(error, null);
153+
assert.equal(response.statusCode, 200);
154+
done();
155+
});
156+
});
157+
it("Should be able to access to test directory when origin is valid",
158+
function(done) {
159+
var options = createOptions(aclDir, 'user1');
160+
options.headers = {
161+
origin: origin1
162+
};
163+
request.head(options, function(error, response, body) {
164+
assert.equal(error, null);
165+
assert.equal(response.statusCode, 200);
166+
done();
167+
});
168+
});
169+
it("Should be denied access to test directory when origin is invalid",
170+
function(done) {
171+
var options = createOptions(aclDir, 'user1');
172+
options.headers = {
173+
origin: origin2
174+
};
175+
request.head(options, function(error, response, body) {
176+
assert.equal(error, null);
177+
assert.equal(response.statusCode, 403);
178+
done();
179+
});
180+
});
181+
});

0 commit comments

Comments
 (0)