Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wac/Authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
50 changes: 50 additions & 0 deletions test/unit/authorization.test.ts
Original file line number Diff line number Diff line change
@@ -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: <http://www.w3.org/ns/auth/acl#> .

<https://pod.example/.acl#accessToOnly>
a acl:Authorization ;
acl:accessTo <https://pod.example/note> ;
acl:mode acl:Read ;
acl:agent <https://alice.example/profile/card#me> .

<https://pod.example/.acl#defaultOnly>
a acl:Authorization ;
acl:default <https://pod.example/container/> ;
acl:mode acl:Read ;
acl:agent <https://alice.example/profile/card#me> .

<https://pod.example/.acl#neither>
a acl:Authorization ;
acl:mode acl:Read ;
acl:agent <https://alice.example/profile/card#me> .
`

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)
})
})