Skip to content

Commit 124d032

Browse files
committed
feat(tests): add tests for scoped grants to scenario
1 parent 81a0fda commit 124d032

2 files changed

Lines changed: 145 additions & 3 deletions

File tree

test/example-config.ttl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ example:examplePolicy a odrl:Set ;
1818
example:userUserDataRead ,
1919
example:userUserDataWrite ,
2020
example:publicPushUpdatesRead ,
21-
example:publicPushUpdatesWrite .
21+
example:publicPushUpdatesWrite ,
22+
example:scopeReadPermission ,
23+
example:scopeWritePermission .
2224

2325
example:publicParty a odrl:PartyCollection ;
2426
vcard:fn "public" .
@@ -139,3 +141,15 @@ example:publicPushUpdatesWrite a odrl:Permission ;
139141
odrl:action odrl:modify ;
140142
odrl:target example:pushUpdatesGraph ;
141143
odrl:assignee example:publicParty .
144+
145+
example:scopeReadPermission a odrl:Permission ;
146+
odrl:action odrl:read ;
147+
odrl:target example:publicGraph ;
148+
odrl:assignee example:publicParty ;
149+
ext:scope "http://services.semantic.works/admin-service" .
150+
151+
example:scopeWritePermission a odrl:Permission ;
152+
odrl:action odrl:modify ;
153+
odrl:target example:publicGraph ;
154+
odrl:assignee example:publicParty ;
155+
ext:scope "http://services.semantic.works/admin-service" .

test/scenario.lisp

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
:jane "http://mu.semte.ch/sessions/janeuuid"
2626
:joll "http://mu.semte.ch/sessions/adminuuid"))
2727

28+
;;;; Our services are :admin (read and write public-data), and :catalog (read public)
29+
(defparameter *known-service-scopes*
30+
(list
31+
:admin "http://services.semantic.works/admin-service"
32+
:catalog "http://services.semantic.works/catalog-service"))
33+
2834
(defun clean-up-graphs ()
2935
(client:query (coerce
3036
"DELETE {
@@ -175,6 +181,15 @@
175181
:to acl::push-updates
176182
:for "public")
177183

184+
(acl:grant (acl::read acl::write)
185+
:to-graph acl::public-data
186+
:for-allowed-group "public"
187+
:scopes '("http://services.semantic.works/admin-service"))
188+
189+
(acl:grant (acl::read)
190+
:to-graph acl::public-data
191+
:for-allowed-group "public"
192+
:scopes '("http://services.semantic.works/catalog-service"))
178193
,@body))
179194

180195
;; TODO: Copied and modified from `with-acl-config', could probably reduce the code duplication
@@ -222,6 +237,12 @@
222237
(:mu-session-id (getf *known-session-ids* ,user))
223238
,@body))
224239

240+
(defmacro with-scope-for (service &body body)
241+
"Impersonates SERVICE by setting its scope."
242+
`(server::with-call-context
243+
(:mu-call-scope (getf *known-service-scopes* ,service))
244+
,@body))
245+
225246
(defun store-initial-session-data ()
226247
"Stores the initial session data in the triplestore."
227248
(client:query (coerce
@@ -380,7 +401,7 @@ this point and likely a redpencil image too.")
380401
381402
ASK {
382403
favorites:me ext:hasFavoriteAuthor ?author.
383-
}")
404+
}")
384405
;; then let's describe the values
385406
(format t "~&Jack can describe favorite authors.~%")
386407
(server:execute-query-for-context
@@ -604,7 +625,114 @@ this point and likely a redpencil image too.")
604625
ext:myDisplay a ext:NoNameOrLabel;
605626
ext:score ?score;
606627
ext:level ?level.
607-
}")))
628+
}"))
629+
630+
(format t "~&Admin service can read and write~%")
631+
(with-scope-for :admin
632+
(format t "~&Can add authors.~%")
633+
(server:execute-query-for-context
634+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>
635+
PREFIX schema: <http://schema.org/>
636+
PREFIX authors: <http://example.com/authors/>
637+
638+
INSERT DATA {
639+
authors:david-graeber a foaf:Person;
640+
foaf:name \"David Graeber\".
641+
}")
642+
643+
(format t "~&Can add a book for an author.~%")
644+
(server:execute-query-for-context
645+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>
646+
PREFIX schema: <http://schema.org/>
647+
PREFIX authors: <http://example.com/authors/>
648+
PREFIX books: <http://example.com/books/>
649+
650+
INSERT DATA {
651+
books:dawn a schema:Book;
652+
schema:name \"The Dawn of Everything\";
653+
schema:creator authors:david-graeber .
654+
}")
655+
656+
(format t "~&Can add extra author to book.~%")
657+
(server:execute-query-for-context
658+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>
659+
PREFIX schema: <http://schema.org/>
660+
PREFIX authors: <http://example.com/authors/>
661+
PREFIX books: <http://example.com/books/>
662+
663+
INSERT DATA {
664+
authors:david-wengrow a foaf:Person ;
665+
schema:name \"David Wengrow\" .
666+
books:dawn schema:creator authors:david-wengrow .
667+
}")
668+
669+
(format t "~&Cannot add a favorite.~%")
670+
(handler-case
671+
(progn
672+
(server:execute-query-for-context
673+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>
674+
PREFIX schema: <http://schema.org/>
675+
PREFIX authors: <http://example.com/authors/>
676+
PREFIX books: <http://example.com/books/>
677+
PREFIX favorites: <http://mu.semte.ch/favorites/>
678+
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
679+
680+
INSERT DATA {
681+
favorites:me ext:hasBook books:gtd, books:fastAndSlow.
682+
}")
683+
(format t "~&ERROR: Oh noes, Admin service should not be able to add a favorite author!~%"))
684+
(error (e) (declare (ignore e)) t)))
685+
686+
(format t "~&Catalog service can only read~%")
687+
(with-scope-for :catalog
688+
(format t "~&Cannot add authors.")
689+
(handler-case
690+
(progn
691+
(server:execute-query-for-context
692+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>
693+
PREFIX schema: <http://schema.org/>
694+
PREFIX authors: <http://example.com/authors/>
695+
696+
INSERT DATA {
697+
authors:david-graeber a foaf:Person;
698+
foaf:name \"David Graeber\".
699+
}")
700+
(format t "~&ERROR: Oh noes, Catalog service should not be able to add an author!~%"))
701+
(error (e) (declare (ignore e)) t))
702+
703+
(format t "~&Cannot add book.~%")
704+
(handler-case
705+
(progn
706+
(server:execute-query-for-context
707+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>
708+
PREFIX schema: <http://schema.org/>
709+
PREFIX authors: <http://example.com/authors/>
710+
PREFIX books: <http://example.com/books/>
711+
712+
INSERT DATA {
713+
books:dawn a schema:Book;
714+
schema:name \"The Dawn of Everything\";
715+
schema:creator authors:david-graeber .
716+
}")
717+
(format t "~&ERROR: Oh noes, Catalog service should not be able to add a book!~%"))
718+
(error (e) (declare (ignore e)) t))
719+
720+
(format t "~&Cannot add a favorite.~%")
721+
(handler-case
722+
(progn
723+
(server:execute-query-for-context
724+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>
725+
PREFIX schema: <http://schema.org/>
726+
PREFIX authors: <http://example.com/authors/>
727+
PREFIX books: <http://example.com/books/>
728+
PREFIX favorites: <http://mu.semte.ch/favorites/>
729+
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
730+
731+
INSERT DATA {
732+
favorites:me ext:hasBook books:gtd, books:fastAndSlow.
733+
}")
734+
(format t "~&ERROR: Oh noes, Catalog service should not be able to add a favorite author!~%"))
735+
(error (e) (declare (ignore e)) t))))
608736

609737
(defun delta-only-assertion-tests ()
610738
(client:query (coerce

0 commit comments

Comments
 (0)