fix(artifacts): stabilize extraction approval
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { PermissionAuthority } from "./PermissionAuthority.js";
|
||||
import { artifactExtractionPermissionRequest } from "./ArtifactExtractionDestination.js";
|
||||
import { createPermissionPolicy } from "../domain/permissionPolicy.js";
|
||||
|
||||
describe("artifact extraction permission", () => {
|
||||
it("authorizes the REA-selected temporary destination with one stable grant", async () => {
|
||||
const request = artifactExtractionPermissionRequest();
|
||||
const { operation_identity: operationIdentity, ...scope } = request;
|
||||
const authority = new PermissionAuthority(
|
||||
createPermissionPolicy(
|
||||
[scope],
|
||||
[
|
||||
{
|
||||
...scope,
|
||||
grant_id: "artifact-extraction-once",
|
||||
lifetime: "once",
|
||||
operation_identity: operationIdentity,
|
||||
expires_at: null,
|
||||
},
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
await expect(authority.authorize(request, "write")).resolves.toMatchObject({
|
||||
ok: true,
|
||||
});
|
||||
await expect(authority.authorize(request, "write")).resolves.toMatchObject({
|
||||
ok: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,22 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import type { PermissionRequest } from "../domain/permissionPolicy.js";
|
||||
|
||||
/** Choose a fresh temporary destination for an artifact extraction. */
|
||||
export const createArtifactExtractionDestination = (): string =>
|
||||
join(tmpdir(), `rea-extracted-${randomUUID()}`);
|
||||
|
||||
/** Stable parent scope used to authorize REA-owned extraction destinations. */
|
||||
export const artifactExtractionPermissionRoot = (): string => tmpdir();
|
||||
|
||||
/** Stable filesystem scope for the destination selected internally by REA. */
|
||||
export const artifactExtractionPermissionRequest = (): PermissionRequest => ({
|
||||
capability: "artifact_extract",
|
||||
roots: [artifactExtractionPermissionRoot()],
|
||||
executables: [],
|
||||
environment_names: [],
|
||||
network: "none",
|
||||
mount: false,
|
||||
operation_identity: "extract_artifact:temporary_output",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user