11/*jslint node: true*/
22
3- var assert = require ( 'assert' ) ;
3+ var assert = require ( 'chai' ) . assert ;
44var fs = require ( 'fs' ) ;
55var request = require ( 'request' ) ;
66var S = require ( 'string' ) ;
@@ -10,24 +10,106 @@ process.chdir('./test', undefined);
1010process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ;
1111
1212var address = 'https://localhost:3456/test/' ;
13+ var aclDir = 'aclDir' ;
14+ var aclExtension = '.acl' ;
1315var server = supertest ( address ) ;
14- var cert = fs . readFileSync ( 'testfiles/client-cert.pem' ) ;
15- var key = fs . readFileSync ( 'testfiles/client-key.pem' ) ;
16- var agent = supertest . agent ( server , { ca : cert } ) ;
17-
18- var options = {
19- url : 'https://localhost:3456/test/hello.html' ,
20- agentOptions : {
21- key : key ,
22- cert : cert
16+ var userCredentials = {
17+ user1 : {
18+ cert : fs . readFileSync ( 'testfiles/user1-cert.pem' ) ,
19+ key : fs . readFileSync ( 'testfiles/user1-key.pem' )
20+ } ,
21+ user2 : {
22+ cert : fs . readFileSync ( 'testfiles/user2-cert.pem' ) ,
23+ key : fs . readFileSync ( 'testfiles/user2-key.pem' )
2324 }
2425} ;
2526
26- describe ( 'Hello World' , function ( ) {
27+ function createOptions ( path , user ) {
28+ var options = {
29+ url : address + path
30+ } ;
31+ if ( user ) {
32+ options . agentOptions = userCredentials [ user ] ;
33+ }
34+ return options ;
35+ }
36+
37+ describe ( 'Basic HTTPS Test' , function ( ) {
2738 it ( 'Should return "Hello, World!"' , function ( done ) {
39+ var options = createOptions ( 'hello.html' , 'user1' ) ;
2840 request ( options , function ( error , response , body ) {
29- assert ( response . statusCode , 200 ) ;
30- assert ( response . headers [ 'content-type' ] , / t e x t \/ h t m l / ) ;
41+ assert . equal ( response . statusCode , 200 ) ;
42+ assert . match ( response . headers [ 'content-type' ] , / t e x t \/ h t m l / ) ;
43+ done ( ) ;
44+ } ) ;
45+ } ) ;
46+ } ) ;
47+
48+ describe ( "Empty ACL Test" , function ( ) {
49+ it ( "Should create container" , function ( done ) {
50+ var options = createOptions ( '' , 'user1' ) ;
51+ options . headers = {
52+ link : '<http://www.w3.org/ns/ldp#BasicContainer>;' +
53+ ' rel="type"' ,
54+ slug : aclDir ,
55+ 'content-type' : 'text/turtle'
56+ } ;
57+ request . post ( options , function ( error , response , body ) {
58+ assert . equal ( response . statusCode , 201 ) ;
59+ assert . equal ( response . headers . location ,
60+ address + aclDir + '/' ) ;
61+ done ( ) ;
62+ } ) ;
63+ } ) ;
64+ it ( "Should create empty acl file" , function ( done ) {
65+ var aclFile = aclDir + '/' + aclExtension ;
66+ var options = createOptions ( aclFile , 'user1' ) ;
67+ options . headers = {
68+ 'content-type' : 'text/turtle'
69+ } ;
70+ options . body = '' ;
71+ request . put ( options , function ( error , response , body ) {
72+ assert . equal ( error , null ) ;
73+ assert . equal ( response . statusCode , 201 ) ;
74+ done ( ) ;
75+ } ) ;
76+ } ) ;
77+ it ( "Should create test file" , function ( done ) {
78+ var testFile = aclDir + '/abc' ;
79+ var options = createOptions ( testFile , 'user1' ) ;
80+ options . headers = {
81+ 'content-type' : 'text/turtle'
82+ } ;
83+ options . body = '<a> <b> <c> .' ;
84+ request . put ( options , function ( error , response , body ) {
85+ assert . equal ( error , null ) ;
86+ assert . equal ( response . statusCode , 201 ) ;
87+ done ( ) ;
88+ } ) ;
89+ } ) ;
90+ it ( "Should create test file's acl file" , function ( done ) {
91+ var aclFile = aclDir + '/abc.acl' ;
92+ var options = createOptions ( aclFile , 'user1' ) ;
93+ options . headers = {
94+ 'content-type' : 'text/turtle'
95+ } ;
96+ options . body = '' ;
97+ request . put ( options , function ( error , response , body ) {
98+ assert . equal ( error , null ) ;
99+ assert . equal ( response . statusCode , 201 ) ;
100+ done ( ) ;
101+ } ) ;
102+ } ) ;
103+ it ( "Should access test file's acl file" , function ( done ) {
104+ var aclFile = aclDir + '/abc.acl' ;
105+ var options = createOptions ( aclFile , 'user1' ) ;
106+ options . headers = {
107+ accept : 'text/turtle'
108+ } ;
109+ request . get ( options , function ( error , response , body ) {
110+ assert . equal ( error , null ) ;
111+ assert . equal ( response . statusCode , 200 ) ;
112+ assert . match ( response . headers [ 'content-type' ] , / t e x t \/ t u r t l e / ) ;
31113 done ( ) ;
32114 } ) ;
33115 } ) ;
0 commit comments