Skip to content

Commit 8a1ed77

Browse files
authored
Merge pull request SolidOS#195 from solid/acl-cleanup
Small ACL cleanup
2 parents ae5ede8 + bc7629e commit 8a1ed77

12 files changed

Lines changed: 311 additions & 97 deletions

__mocks__/rdflib.ts

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,76 @@ export function variable () {
4141
}
4242

4343
export function graph() {
44-
return {
45-
any: () => {
46-
return sym()
47-
},
48-
each: () => {
49-
return []
50-
},
51-
match: () => {
52-
return []
53-
},
54-
query: () => {
55-
return []
56-
},
57-
fetcher: {
58-
load: () => {},
59-
nowOrWhenFetched: () => Promise.resolve()
60-
},
61-
findTypeURIs: () => {
62-
return []
63-
},
64-
findSuperClassesNT: () => {
65-
return []
66-
},
67-
bottomTypeURIs: () => {
68-
return []
69-
},
70-
statementsMatching: () => {
71-
return []
72-
},
73-
sym
44+
return new Graph()
45+
}
46+
class Graph {
47+
mockStatements
48+
fetcher
49+
constructor() {
50+
this.mockStatements = []
51+
this.fetcher = new Fetcher()
52+
}
53+
any () {
54+
return sym()
55+
}
56+
// see https://linkeddata.github.io/rdflib.js/doc/classes/indexedformula.html#each
57+
each (s, p, o, g) {
58+
console.log('each', s, p, o, g, this.mockStatements)
59+
if (s === undefined) {
60+
console.log('getting subjects')
61+
return this.mockStatements
62+
.filter(statement => p.uri === statement.p.uri)
63+
.filter(statement => o.uri === statement.o.uri)
64+
.filter(statement => g.uri === statement.g.uri)
65+
.map(statement => statement.s)
66+
}
67+
if (p === undefined) {
68+
return this.mockStatements
69+
.filter(statement => s.uri === statement.s.uri)
70+
.filter(statement => o.uri === statement.o.uri)
71+
.filter(statement => g.uri === statement.g.uri)
72+
.map(statement => statement.p)
73+
}
74+
if (o === undefined) {
75+
return this.mockStatements
76+
.filter(statement => s.uri === statement.s.uri)
77+
.filter(statement => p.uri === statement.p.uri)
78+
.filter(statement => g.uri === statement.g.uri)
79+
.map(statement => statement.o)
80+
}
81+
if (g === undefined) {
82+
return this.mockStatements
83+
.filter(statement => s.uri === statement.s.uri)
84+
.filter(statement => p.uri === statement.p.uri)
85+
.filter(statement => o.uri === statement.o.uri)
86+
.map(statement => statement.g)
87+
}
88+
}
89+
match () {
90+
return []
91+
}
92+
query () {
93+
return []
94+
}
95+
findTypeURIs () {
96+
return []
97+
}
98+
findSuperClassesNT () {
99+
return []
100+
}
101+
bottomTypeURIs () {
102+
return []
103+
}
104+
statementsMatching () {
105+
return []
106+
}
107+
sym () {
108+
return sym()
74109
}
75110
}
111+
76112
export function fetcher() {
77-
return {}
113+
return new Fetcher()
78114
}
79115
export class Fetcher {
80116
requested: any
@@ -83,9 +119,14 @@ export class Fetcher {
83119
}
84120
load () {
85121
}
122+
nowOrWhenFetched () {
123+
return Promise.resolve()
124+
}
86125
}
87-
export function namedNode() {
88-
return {}
126+
export function namedNode(str: string) {
127+
return {
128+
uri: str
129+
}
89130
}
90131
export function NamedNode() {
91132
}
@@ -94,4 +135,5 @@ export function Namespace() {
94135
}
95136
export class UpdateManager {
96137
editable() {}
138+
update() {}
97139
}

src/acl/acl.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { AgentMapMap, ComboList } from './types'
99
// //////////////////////////////////// Solid ACL non-UI functions
1010
//
1111

12-
// Take the "defaltForNew" ACL and convert it into the equivlent ACL
13-
// which the resource would have had. Return it as a new separate store.
12+
// Take the "defaultForNew" ACL and convert it into the equivlent ACL
13+
// which the resource would have had. Return it as a new separate store.
1414

1515
export function adoptACLDefault (
1616
doc: $rdf.NamedNode,
@@ -25,8 +25,10 @@ export function adoptACLDefault (
2525
.concat(
2626
kb.each(undefined, ACL('defaultForNew'), defaultResource, defaultACLdoc)
2727
)
28+
console.log(defaults)
2829
let proposed: Array<$rdf.Statement> = []
2930
defaults.map(function (da) {
31+
console.log('got da!', da)
3032
proposed = proposed
3133
.concat(kb.statementsMatching(da, ACL('agent'), undefined, defaultACLdoc))
3234
.concat(kb.statementsMatching(da, ACL('agentClass'), undefined, defaultACLdoc))
@@ -248,7 +250,7 @@ export function makeACLGraphbyCombo (
248250
}
249251
}
250252

251-
// Debugguing short strings for dumping ACL
253+
// Debugging short strings for dumping ACL
252254
// and who knows maybe in the UI
253255
//
254256
export function ACLToString (ac: AgentMapMap): string {

test/unit/acl/access-controller.test.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,6 @@
1-
import * as RdfLib from 'rdflib'
2-
import { JSDOM } from 'jsdom'
1+
import { instantiateAccessController } from '../helpers/instantiateAccessController'
32
import { AccessController } from '../../../src/acl/access-controller'
4-
import { DataBrowserContext } from 'pane-registry'
53

6-
jest.mock('rdflib')
7-
jest.mock('solid-auth-client')
8-
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window.document
9-
10-
export function instantiateAccessController () {
11-
const subject = RdfLib.sym('')
12-
const noun = ''
13-
const context = {} as DataBrowserContext
14-
const statusElement = dom.createElement('div')
15-
const classes = {}
16-
const targetIsProtected = false
17-
const targetDoc = RdfLib.sym('')
18-
const targetACLDoc = RdfLib.sym('')
19-
const defaultHolder = RdfLib.sym('')
20-
const defaultACLDoc = RdfLib.sym('')
21-
const prospectiveDefaultHolder = RdfLib.sym('')
22-
const store = {}
23-
return new AccessController(
24-
subject,
25-
noun,
26-
context,
27-
statusElement,
28-
classes,
29-
targetIsProtected,
30-
targetDoc,
31-
targetACLDoc,
32-
defaultHolder,
33-
defaultACLDoc,
34-
prospectiveDefaultHolder,
35-
store,
36-
dom
37-
)
38-
}
394
describe('AccessController', () => {
405
it('exists', () => {
416
// FIXME: how can we test that it's actually a constructor?

test/unit/acl/access-groups.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import { AccessGroups, AccessGroupsOptions } from '../../../src/acl/access-groups'
22
import { NamedNode, IndexedFormula, graph } from 'rdflib'
3-
import { instantiateAccessController } from './access-controller.test'
3+
import { instantiateAccessGroups } from '../helpers/instantiateAccessGroups'
44

55
jest.mock('rdflib')
66
jest.mock('solid-auth-client')
77

8-
function instantiateAccessGroups () {
9-
return new AccessGroups(
10-
{} as NamedNode,
11-
{} as NamedNode,
12-
instantiateAccessController(),
13-
graph() as IndexedFormula,
14-
{} as AccessGroupsOptions)
15-
}
168
describe('AccessGroups', () => {
179
it('exists', () => {
1810
expect(AccessGroups).toBeInstanceOf(Function)

test/unit/acl/acl.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
} from '../../../src/acl/acl'
2222
import { AgentMapMap, ComboList } from '../../../src/acl/types'
2323
import * as RdfLib from 'rdflib'
24+
import kb from '../../../src/store'
25+
import ns from '../../../src/ns'
2426

2527
jest.mock('rdflib')
2628
jest.mock('solid-auth-client')
@@ -56,13 +58,23 @@ describe('adoptACLDefault', () => {
5658
it('exists', () => {
5759
expect(adoptACLDefault).toBeInstanceOf(Function)
5860
})
59-
it('exists', () => {
61+
it('runs', () => {
6062
expect(adoptACLDefault(
6163
RdfLib.sym(''),
6264
RdfLib.sym(''),
6365
RdfLib.sym(''),
6466
RdfLib.sym(''))).toBeInstanceOf(Object)
6567
})
68+
it.skip('returns default ACL values', () => {
69+
;(kb as any).mockStatements = [
70+
{ s: 'some', p: ns.acl('default'), o: RdfLib.sym('defaultResource'), g: RdfLib.sym('defaultACLDoc') }
71+
]
72+
expect(adoptACLDefault(
73+
RdfLib.sym('doc'),
74+
RdfLib.sym('aclDoc'),
75+
RdfLib.sym('defaultResource'),
76+
RdfLib.sym('defaultACLDoc'))).toBeInstanceOf(Object)
77+
})
6678
})
6779

6880
describe('comboToString', () => {

0 commit comments

Comments
 (0)