@@ -8,6 +8,14 @@ var supertest = require('supertest');
88var ldnode = require ( '../index' ) ;
99var ACL = require ( '../acl' ) . ACL ;
1010
11+ function rm ( file ) {
12+ return fs . unlinkSync ( __dirname + '/resources/' + file ) ;
13+ }
14+
15+ function write ( text , file ) {
16+ return fs . writeFileSync ( __dirname + '/resources/' + file , text ) ;
17+ }
18+
1119describe ( 'ACL HTTP' , function ( ) {
1220 this . timeout ( 10000 ) ;
1321 process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ;
@@ -1000,12 +1008,105 @@ describe('ACL Class', function () {
10001008 var user1 = "https://user1.databox.me/profile/card#me" ;
10011009 var user2 = "https://user2.databox.me/profile/card#me" ;
10021010 var nicola = "https://nicola.databox.me/profile/card#me" ;
1011+ var address = 'https://server.tld/test' ;
10031012
10041013 describe ( 'readACL' , function ( ) {
1014+ it ( 'should report a 404 error if no acl is found' , function ( done ) {
1015+ var acl = new ACL ( {
1016+ ldp : ldp ,
1017+ origin : 'https://example.com' ,
1018+ session : {
1019+ userId : user1 ,
1020+ identified : true
1021+ } ,
1022+ uri : 'https://server.tld/test'
1023+ } ) ;
1024+
1025+ acl . readACL ( __dirname + '/resources/.acl' , 'https://server.tld/test' , function ( err , res ) {
1026+ assert . equal ( err . status , 404 ) ;
1027+ assert . notOk ( res ) ;
1028+ done ( ) ;
1029+ } ) ;
1030+ } ) ;
1031+
1032+ it ( 'should report a 404 error if .acl cannot be parsed' , function ( done ) {
1033+ var acl = new ACL ( {
1034+ ldp : ldp ,
1035+ origin : 'https://example.com' ,
1036+ session : {
1037+ userId : user1 ,
1038+ identified : true
1039+ } ,
1040+ uri : address
1041+ } ) ;
1042+ write (
1043+ "<#Owner>\n" +
1044+ " <http://www.w3.org/ns/auth/acl#accessTo> <" +
1045+ address + "/" + ">, <" + address + ">;\n" +
1046+ " XXXXXXXhttp://www.w3.org/ns/auth/acl#owner> <" + user1 + ">;\n" +
1047+ " <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Control> .\n" ,
1048+ '.acl' ) ;
1049+
1050+ acl . readACL ( __dirname + '/resources/.acl' , address , function ( err , res ) {
1051+ assert . equal ( err . status , 500 ) ;
1052+ assert . notOk ( res ) ;
1053+ rm ( '.acl' ) ;
1054+ done ( ) ;
1055+ } ) ;
1056+ } ) ;
1057+
1058+ it ( 'should return a parsed graph of the acl on success' , function ( done ) {
1059+ var acl = new ACL ( {
1060+ ldp : ldp ,
1061+ origin : 'https://example.com' ,
1062+ session : {
1063+ userId : user1 ,
1064+ identified : true
1065+ } ,
1066+ uri : address
1067+ } ) ;
1068+ write (
1069+ "<#Owner>\n" +
1070+ " <http://www.w3.org/ns/auth/acl#accessTo> <" +
1071+ address + "/" + ">, <" + address + ">;\n" +
1072+ " <http://www.w3.org/ns/auth/acl#owner> <" + user1 + ">;\n" +
1073+ " <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Control> .\n" ,
1074+ '.acl' ) ;
1075+
1076+ acl . readACL ( __dirname + '/resources/.acl' , address , function ( err , res ) {
1077+ assert . notOk ( err ) ;
1078+ assert . ok ( res ) ;
1079+ rm ( '.acl' ) ;
1080+ done ( ) ;
1081+ } ) ;
1082+ } ) ;
1083+
1084+ it ( 'should return a graph on empty ACL' , function ( done ) {
1085+ var acl = new ACL ( {
1086+ ldp : ldp ,
1087+ origin : 'https://example.com' ,
1088+ session : {
1089+ userId : user1 ,
1090+ identified : true
1091+ } ,
1092+ uri : address
1093+ } ) ;
1094+ write (
1095+ "\n" ,
1096+ '.acl' ) ;
1097+
1098+ acl . readACL ( __dirname + '/resources/.acl' , address , function ( err , res ) {
1099+ assert . notOk ( err ) ;
1100+ assert . ok ( res ) ;
1101+ rm ( '.acl' ) ;
1102+ done ( ) ;
1103+ } ) ;
1104+ } ) ;
1105+
10051106
10061107 } ) ;
10071108
1008- describe ( 'findACLinPath ' , function ( ) {
1109+ describe ( 'findACLInPath ' , function ( ) {
10091110
10101111 } ) ;
10111112
0 commit comments