File: 02access.t

package info (click to toggle)
librdf-acl-perl 0.104-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 216 kB
  • ctags: 28
  • sloc: perl: 359; makefile: 13
file content (57 lines) | stat: -rw-r--r-- 1,470 bytes parent folder | download | duplicates (2)
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
use Test::More tests => 8;
use RDF::ACL;

my $acl = RDF::ACL->new;

ok(!$acl->check(
		'http://example.com/joe#me',
		'http://example.com/private/document',
		'Read'),
	"by default, deny access"
	);

my $authid = $acl->allow(
	'webid' => ['http://example.com/joe#me'],
	'item'  => 'http://example.com/private/document',
	'level' => ['read']
	);

ok($acl->check(
		'http://example.com/joe#me',
		'http://example.com/private/document',
		'Read'),
	"allow and check seem to work"
	);

my $proper = <<CANON;
<$authid> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/auth/acl#Authorization> .
<$authid> <http://www.w3.org/ns/auth/acl#accessTo> <http://example.com/private/document> .
<$authid> <http://www.w3.org/ns/auth/acl#agent> <http://example.com/joe#me> .
<$authid> <http://www.w3.org/ns/auth/acl#mode> <http://www.w3.org/ns/auth/acl#Read> .
CANON
$proper =~ s/\r?\n/\r\n/g;

is($proper, $acl->save(RDF::Trine::Serializer::NTriples::Canonical->new), "graph generated by allow seems good");

my @reasons = $acl->why(
	'http://example.com/joe#me',
	'http://example.com/private/document',
	'Read'
	);

is(1, scalar @reasons, "why seems to work");

my $reason = $reasons[0];

is($authid, $reason, "why seems sane");

is(4, $acl->deny($reason), "deny seems to work");

is(0, $acl->model->count_statements, "deny removes triples");

ok(!$acl->check(
		'http://example.com/joe#me',
		'http://example.com/private/document',
		'Read'),
	"deny works"
	);