-
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
Open
SharonStrats
wants to merge
3
commits into
staging
Choose a base branch
from
feat/access
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.