Skip to content

Commit

Permalink
specify context-type of policy retrieval query
Browse files Browse the repository at this point in the history
When using policy via http-api, default context-type will be `:string`, and expanding/parsing this query will fail if we don't specify the context-type. This ensures the policy query will succeed regardless of the default context-type.
  • Loading branch information
mpoffald committed Apr 6, 2023
1 parent 2a5843f commit 56e770d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/fluree/db/json_ld/policy.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
{:rdf/type [:_id]}
{:f/allow [:* {:f/targetRole [:_id]}]}
{:f/property [:* {:f/allow [:* {:f/targetRole [:_id]}]}]}]}
:where [['?s :rdf/type :f/Policy]]}))))
:where [['?s :rdf/type :f/Policy]]
:opts {:context-type :keyword}}))))



(defn policies-for-roles*
Expand Down
27 changes: 25 additions & 2 deletions test/fluree/db/policy/parsing_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,31 @@
:roles #{sid-userRole}}
policy-alice)
"Policies for only :ex/userRole should return")))


(testing "Root policy contains {:root? true} for each applicable :f/action"
(let [policy-root (-> @(fluree/promise-wrap (policy/policy-map db root-did :ex/rootRole nil))
replace-policy-fns)
sid-root-did @(fluree/internal-id db root-did)
sid-rootRole @(fluree/internal-id db :ex/rootRole)]
(is (= {:f/modify {:root? true}
:f/view {:root? true}
:ident sid-root-did
:roles #{sid-rootRole}}
policy-root))))))
(testing "Testing query policy with strings"
(let [conn (test-utils/create-conn)
ledger @(fluree/create conn "policy-parse/a" {:defaultContext ["" {"ex" "http://example.org/ns/"}]
:context-type :string})
root-did (:id (did/private->did-map "8ce4eca704d653dec594703c81a84c403c39f262e54ed014ed857438933a2e1c"))
db @(fluree/stage
(fluree/db ledger)
[{"id" root-did
"f:role" {"id" "ex:rootRole"}}
{"id" "ex:rootPolicy",
"type" ["f:Policy"],
"f:targetNode" {"id" "f:allNodes"}
"f:allow" [{"id" "ex:rootAccessAllow"
"f:targetRole" {"id" "ex:rootRole"}
"f:action" [{"id" "f:view"} {"id" "f:modify"}]}]}])]
(testing "Root policy contains {:root? true} for each applicable :f/action"
(let [policy-root (-> @(fluree/promise-wrap (policy/policy-map db root-did :ex/rootRole nil))
replace-policy-fns)
Expand Down

0 comments on commit 56e770d

Please sign in to comment.