|
1 | 1 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
2 | 2 | import { Fetcher, Store, sym, UpdateManager } from 'rdflib' |
3 | | -import { findEffectiveACL, planGrant, planPublicRead } from '@dokieli/web-access-control' |
| 3 | +import { applyPlan, findEffectiveACL, planGrant, planPublicRead, planRevoke } from '@dokieli/web-access-control' |
4 | 4 | import { ACL_LINK, createAclLogic } from '../src/acl/aclLogic' |
5 | 5 |
|
6 | 6 | vi.mock('@dokieli/web-access-control', () => ({ |
7 | 7 | findEffectiveACL: vi.fn(), |
8 | 8 | planGrant: vi.fn(), |
9 | 9 | planPublicRead: vi.fn(), |
| 10 | + planRevoke: vi.fn(), |
| 11 | + applyPlan: vi.fn(), |
10 | 12 | Authenticated: Symbol('Authenticated'), |
11 | 13 | Public: Symbol('Public'), |
12 | | - planOwnerControl: vi.fn(), |
13 | | - planRevoke: vi.fn() |
| 14 | + planOwnerControl: vi.fn() |
14 | 15 | })) |
15 | 16 |
|
16 | 17 | describe('createAclLogic', () => { |
@@ -102,6 +103,30 @@ describe('createAclLogic', () => { |
102 | 103 | expect(planPublicRead).toHaveBeenCalledWith(expect.objectContaining({ authorizations: [] }), true) |
103 | 104 | }) |
104 | 105 |
|
| 106 | + it('delegates planRevoke through the effective ACL context', async () => { |
| 107 | + const resource = sym('https://example.com/resource.ttl') |
| 108 | + const subject = { type: 'agent', iri: 'https://example.com/profile/card#me' } |
| 109 | + const plan = { target: 'https://example.com/resource.ttl.acl', deletes: [], inserts: [] } |
| 110 | + |
| 111 | + vi.mocked(findEffectiveACL).mockResolvedValue({ authorizations: [] } as any) |
| 112 | + vi.mocked(planRevoke).mockReturnValue(plan as any) |
| 113 | + store.fetcher._fetch.mockResolvedValue(new Response('', { status: 200 })) |
| 114 | + |
| 115 | + await expect(aclLogic.planRevoke(resource, subject as any)).resolves.toBe(plan) |
| 116 | + expect(planRevoke).toHaveBeenCalledWith(expect.objectContaining({ authorizations: [] }), subject) |
| 117 | + }) |
| 118 | + |
| 119 | + it('applies a patch plan with the store fetcher', async () => { |
| 120 | + const plan = { target: 'https://example.com/resource.ttl.acl', deletes: [], inserts: [] } |
| 121 | + const response = new Response('ok', { status: 200 }) |
| 122 | + |
| 123 | + store.fetcher._fetch.mockResolvedValue(new Response('', { status: 200 })) |
| 124 | + vi.mocked(applyPlan).mockResolvedValue(response) |
| 125 | + |
| 126 | + await expect(aclLogic.applyPlan(plan as any)).resolves.toBe(response) |
| 127 | + expect(applyPlan).toHaveBeenCalledWith(plan, expect.objectContaining({ fetch: expect.any(Function) })) |
| 128 | + }) |
| 129 | + |
105 | 130 | it('throws when the store cannot supply a fetch function', async () => { |
106 | 131 | const resource = sym('https://example.com/resource.ttl') |
107 | 132 | store.fetcher = { _fetch: vi.fn(), load: vi.fn(), webOperation: vi.fn(), unload: vi.fn() } as any |
|
0 commit comments