-
Notifications
You must be signed in to change notification settings - Fork 13
support for manage access dialog #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,138 @@ | ||
| import { beforeAll, describe, expect, it } from 'vitest' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { Fetcher, Store, sym, UpdateManager } from 'rdflib' | ||
| import { createAclLogic } from '../src/acl/aclLogic' | ||
|
|
||
| describe('setACLUserPublic', () => { | ||
| let aclLogic: any | ||
| let store: Store | ||
| beforeAll(() => { | ||
| const options = { fetch: fetch } | ||
| store = new Store() | ||
| store.fetcher = new Fetcher(store, options) | ||
| store.updater = new UpdateManager(store) | ||
| aclLogic = createAclLogic(store) | ||
| }) | ||
| it('exists', () => { | ||
| expect(aclLogic.setACLUserPublic).toBeInstanceOf(Function) | ||
| }) | ||
| it.skip('runs', async () => { | ||
| expect(await aclLogic.setACLUserPublic( | ||
| 'https://test.test#', | ||
| sym('https://test.test#'), | ||
| {} | ||
| )).toEqual({}) | ||
| }) | ||
| import { applyPlan, findEffectiveACL, planGrant, planPublicRead, planRevoke } from '@dokieli/web-access-control' | ||
| import { ACL_LINK, createAclLogic } from '../src/acl/aclLogic' | ||
|
|
||
| vi.mock('@dokieli/web-access-control', () => ({ | ||
| findEffectiveACL: vi.fn(), | ||
| planGrant: vi.fn(), | ||
| planPublicRead: vi.fn(), | ||
| planRevoke: vi.fn(), | ||
| applyPlan: vi.fn(), | ||
| Authenticated: Symbol('Authenticated'), | ||
| Public: Symbol('Public'), | ||
| planOwnerControl: vi.fn() | ||
| })) | ||
|
|
||
| describe('createAclLogic', () => { | ||
| let store: Store & { | ||
| fetcher: Fetcher & { | ||
| _fetch: ReturnType<typeof vi.fn> | ||
| load: ReturnType<typeof vi.fn> | ||
| webOperation: ReturnType<typeof vi.fn> | ||
| } | ||
| any: ReturnType<typeof vi.fn> | ||
| } | ||
| let aclLogic: ReturnType<typeof createAclLogic> | ||
|
|
||
| beforeEach(() => { | ||
| const fetcher = { | ||
| _fetch: vi.fn(), | ||
| load: vi.fn(), | ||
| webOperation: vi.fn(), | ||
| unload: vi.fn() | ||
| } as unknown as Fetcher & { | ||
| _fetch: ReturnType<typeof vi.fn> | ||
| load: ReturnType<typeof vi.fn> | ||
| webOperation: ReturnType<typeof vi.fn> | ||
| unload: ReturnType<typeof vi.fn> | ||
| } | ||
|
|
||
| store = { | ||
| fetcher, | ||
| updater: new UpdateManager(new Store()), | ||
| any: vi.fn() | ||
| } as unknown as Store & { | ||
| fetcher: typeof fetcher | ||
| any: ReturnType<typeof vi.fn> | ||
| } | ||
|
|
||
| aclLogic = createAclLogic(store) | ||
| }) | ||
|
|
||
| it('exports the ACL link relation constant', () => { | ||
| expect(ACL_LINK.value).toBe('http://www.iana.org/assignments/link-relations/acl') | ||
| }) | ||
|
|
||
| it('finds the ACL document URL from the discovered link', async () => { | ||
| const resource = sym('https://example.com/resource.ttl') | ||
| const aclDoc = sym('https://example.com/resource.ttl.acl') | ||
| const loadResult = { ok: true } | ||
|
|
||
| store.fetcher.load.mockResolvedValue(loadResult) | ||
| store.any.mockReturnValue(aclDoc) | ||
|
|
||
| await expect(aclLogic.findAclDocUrl(resource)).resolves.toBe(aclDoc.value) | ||
| expect(store.fetcher.load).toHaveBeenCalledWith(resource) | ||
| expect(store.any).toHaveBeenCalledWith(resource, ACL_LINK) | ||
| }) | ||
|
|
||
| it('returns the authorizations from the effective ACL context', async () => { | ||
| const resource = sym('https://example.com/resource.ttl') | ||
| const context = { authorizations: [{ id: 'a1' }] } | ||
|
|
||
| vi.mocked(findEffectiveACL).mockResolvedValue(context as any) | ||
| store.fetcher._fetch.mockResolvedValue(new Response('', { status: 200 })) | ||
|
|
||
| await expect(aclLogic.findAccessGrants(resource)).resolves.toEqual(context.authorizations) | ||
| expect(findEffectiveACL).toHaveBeenCalledWith(resource.value, expect.objectContaining({ fetch: expect.any(Function) })) | ||
| }) | ||
|
|
||
| it('delegates planGrant through the effective ACL context', async () => { | ||
| const resource = sym('https://example.com/resource.ttl') | ||
| const subject = { type: 'agent', value: 'https://example.com/profile/card#me' } | ||
| const plan = { updates: [] } | ||
|
|
||
| vi.mocked(findEffectiveACL).mockResolvedValue({ authorizations: [] } as any) | ||
| vi.mocked(planGrant).mockReturnValue(plan as any) | ||
| store.fetcher._fetch.mockResolvedValue(new Response('', { status: 200 })) | ||
|
|
||
| await expect(aclLogic.planGrant(resource, subject as any, ['Read'])).resolves.toBe(plan) | ||
| expect(planGrant).toHaveBeenCalledWith(expect.objectContaining({ authorizations: [] }), subject, ['Read']) | ||
| }) | ||
|
|
||
| it('delegates planPublicRead through the effective ACL context', async () => { | ||
| const resource = sym('https://example.com/resource.ttl') | ||
| const plan = { updates: [] } | ||
|
|
||
| vi.mocked(findEffectiveACL).mockResolvedValue({ authorizations: [] } as any) | ||
| vi.mocked(planPublicRead).mockReturnValue(plan as any) | ||
| store.fetcher._fetch.mockResolvedValue(new Response('', { status: 200 })) | ||
|
|
||
| await expect(aclLogic.planPublicRead(resource, true)).resolves.toBe(plan) | ||
| expect(planPublicRead).toHaveBeenCalledWith(expect.objectContaining({ authorizations: [] }), true) | ||
| }) | ||
|
|
||
| it('delegates planRevoke through the effective ACL context', async () => { | ||
| const resource = sym('https://example.com/resource.ttl') | ||
| const subject = { type: 'agent', iri: 'https://example.com/profile/card#me' } | ||
| const plan = { target: 'https://example.com/resource.ttl.acl', deletes: [], inserts: [] } | ||
|
|
||
| vi.mocked(findEffectiveACL).mockResolvedValue({ authorizations: [] } as any) | ||
| vi.mocked(planRevoke).mockReturnValue(plan as any) | ||
| store.fetcher._fetch.mockResolvedValue(new Response('', { status: 200 })) | ||
|
|
||
| await expect(aclLogic.planRevoke(resource, subject as any)).resolves.toBe(plan) | ||
| expect(planRevoke).toHaveBeenCalledWith(expect.objectContaining({ authorizations: [] }), subject) | ||
| }) | ||
|
|
||
| it('applies a patch plan with the store fetcher', async () => { | ||
| const plan = { target: 'https://example.com/resource.ttl.acl', deletes: [], inserts: [] } | ||
| const response = new Response('ok', { status: 200 }) | ||
|
|
||
| store.fetcher._fetch.mockResolvedValue(new Response('', { status: 200 })) | ||
| vi.mocked(applyPlan).mockResolvedValue(response) | ||
|
|
||
| await expect(aclLogic.applyPlan(plan as any)).resolves.toBe(response) | ||
| expect(applyPlan).toHaveBeenCalledWith(plan, expect.objectContaining({ fetch: expect.any(Function) })) | ||
| }) | ||
|
|
||
| it('throws when the store cannot supply a fetch function', async () => { | ||
| const resource = sym('https://example.com/resource.ttl') | ||
| store.fetcher = { _fetch: vi.fn(), load: vi.fn(), webOperation: vi.fn(), unload: vi.fn() } as any | ||
| delete (store.fetcher as any).fetch | ||
| delete (store.fetcher as any)._fetch | ||
|
|
||
| await expect(aclLogic.findEffectiveAcl(resource)).rejects.toThrow('Cannot find effective ACL, store has no fetcher') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,12 @@ describe('resourceLogic', () => { | |||||
| store = makeStore() | ||||||
| aclLogic = { | ||||||
| findAclDocUrl: vi.fn().mockResolvedValue(undefined), | ||||||
| findEffectiveAcl: vi.fn().mockResolvedValue({ authorizations: [] }), | ||||||
| findAccessGrants: vi.fn().mockResolvedValue([]), | ||||||
| planGrant: vi.fn(), | ||||||
| planRevoke: vi.fn(), | ||||||
| planPublicRead: vi.fn(), | ||||||
| applyPlan: vi.fn(), | ||||||
| setACLUserPublic: vi.fn(), | ||||||
| genACLText: vi.fn() | ||||||
| } | ||||||
|
|
@@ -103,4 +109,12 @@ describe('resourceLogic', () => { | |||||
| await expect(resourceLogic.recursiveDelete(resource)).resolves.toBeUndefined() | ||||||
| expect(store.removeDocument).toHaveBeenCalledWith(resource) | ||||||
| }) | ||||||
|
|
||||||
| it('recognizes only profile-card.ttl WebIDs', () => { | ||||||
| const resourceLogic = createResourceLogic(store, aclLogic, containerLogic, typeIndexLogic) | ||||||
|
|
||||||
| expect(resourceLogic.isWebId(sym('https://alice.example.com/profile/card.ttl#me'))).toBe(true) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this https://alice.example/profile/card.ttl#me a right WebID?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the recommendation came because of this solid-logic/test/helpers/dataSetup.ts Line 4 in b0a3882
solid-logic/test/profileLogic.test.ts Line 346 in b0a3882
I can remove it. I'm thinking that's probably the way to go as there isn't any other code like this. What are your thoughts?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets keep it |
||||||
| expect(resourceLogic.isWebId(sym('https://alice.example.com/profile/card#me'))).toBe(false) | ||||||
| expect(resourceLogic.isWebId(sym('https://alice.example.com/profile/card.jsonld#me'))).toBe(false) | ||||||
| }) | ||||||
| }) | ||||||
Uh oh!
There was an error while loading. Please reload this page.