diff --git a/src/wac/Authorization.ts b/src/wac/Authorization.ts index fc481a6..a76be98 100644 --- a/src/wac/Authorization.ts +++ b/src/wac/Authorization.ts @@ -125,7 +125,7 @@ export class Authorization extends TermWrapper { return false } - if (this.accessTo === undefined || this.default === undefined) { + if (this.accessTo === undefined && this.default === undefined) { return false } diff --git a/test/unit/authorization.test.ts b/test/unit/authorization.test.ts new file mode 100644 index 0000000..053c66e --- /dev/null +++ b/test/unit/authorization.test.ts @@ -0,0 +1,50 @@ +import { DataFactory, Parser, Store } from "n3" +import assert from "node:assert" +import { describe, it } from "node:test" + +import { Authorization } from "@solid/object" + +describe("Authorization.conforms", () => { + const sampleRDF = ` +@prefix acl: . + + + a acl:Authorization ; + acl:accessTo ; + acl:mode acl:Read ; + acl:agent . + + + a acl:Authorization ; + acl:default ; + acl:mode acl:Read ; + acl:agent . + + + a acl:Authorization ; + acl:mode acl:Read ; + acl:agent . +` + + const store = new Store() + store.addQuads(new Parser().parse(sampleRDF)) + + const authorization = (fragment: string) => + new Authorization( + DataFactory.namedNode("https://pod.example/.acl#" + fragment), + store, + DataFactory + ) + + it("conforms when only acl:accessTo is present", () => { + assert.strictEqual(authorization("accessToOnly").conforms, true) + }) + + it("conforms when only acl:default is present", () => { + assert.strictEqual(authorization("defaultOnly").conforms, true) + }) + + it("does not conform when neither acl:accessTo nor acl:default is present", () => { + assert.strictEqual(authorization("neither").conforms, false) + }) +})