Buckets:
localhost1978/localhost / LOCALHOST1978 /SSK_DocGen /Tests /SSK_DocGenTests /ACPRequestContextTests.swift
| import Darwin | |
| import Foundation | |
| import Testing | |
| @testable import SSK_DocGen | |
| ("ACP approved paths") | |
| struct ACPRequestContextTests { | |
| ("Canonical workspace paths remain inside the selected workspace") | |
| func canonicalWorkspacePathsAreAllowed() throws { | |
| let root = try makeTemporaryDirectory() | |
| defer { try? FileManager.default.removeItem(at: root) } | |
| let workspace = root.appendingPathComponent("workspace", isDirectory: true) | |
| let sourceDirectory = workspace.appendingPathComponent("Modules/Example", isDirectory: true) | |
| try FileManager.default.createDirectory(at: sourceDirectory, withIntermediateDirectories: true) | |
| let sourceURL = sourceDirectory.appendingPathComponent("Example.swift") | |
| try "struct Example {}".write(to: sourceURL, atomically: true, encoding: .utf8) | |
| let context = try ACPRequestContext(workspaceURL: workspace) | |
| #expect(try context.paths.workspacePath(for: sourceURL) == sourceURL.standardizedFileURL) | |
| } | |
| ("Symbolic links cannot escape the selected workspace") | |
| func symbolicLinkEscapeIsRejected() throws { | |
| let root = try makeTemporaryDirectory() | |
| defer { try? FileManager.default.removeItem(at: root) } | |
| let workspace = root.appendingPathComponent("workspace", isDirectory: true) | |
| let outside = root.appendingPathComponent("outside", isDirectory: true) | |
| try FileManager.default.createDirectory(at: workspace, withIntermediateDirectories: true) | |
| try FileManager.default.createDirectory(at: outside, withIntermediateDirectories: true) | |
| let escapedSource = outside.appendingPathComponent("Escape.swift") | |
| try "struct Escape {}".write(to: escapedSource, atomically: true, encoding: .utf8) | |
| let linkURL = workspace.appendingPathComponent("Escape.swift") | |
| try FileManager.default.createSymbolicLink(at: linkURL, withDestinationURL: escapedSource) | |
| let context = try ACPRequestContext(workspaceURL: workspace) | |
| #expect(throws: ApprovedPathValidationError.self) { | |
| try context.paths.workspacePath(for: linkURL) | |
| } | |
| } | |
| ("A vault path requires an approved vault") | |
| func vaultPathRequiresConfiguredVault() throws { | |
| let workspace = try makeTemporaryDirectory() | |
| defer { try? FileManager.default.removeItem(at: workspace) } | |
| let context = try ACPRequestContext(workspaceURL: workspace) | |
| #expect(throws: ApprovedPathValidationError.self) { | |
| try context.paths.vaultPath(for: workspace.appendingPathComponent("ledger")) | |
| } | |
| } | |
| ("Approved roots record stable device and inode identities") | |
| func approvedRootsRecordIdentities() throws { | |
| let root = try makeTemporaryDirectory() | |
| defer { try? FileManager.default.removeItem(at: root) } | |
| let workspace = root.appendingPathComponent("workspace", isDirectory: true) | |
| let vault = root.appendingPathComponent("vault", isDirectory: true) | |
| try FileManager.default.createDirectory(at: workspace, withIntermediateDirectories: true) | |
| try FileManager.default.createDirectory(at: vault, withIntermediateDirectories: true) | |
| let workspaceStatPath = workspace.path | |
| var workspaceStatBuf = stat() | |
| stat(workspaceStatPath, &workspaceStatBuf) | |
| let vaultStatPath = vault.path | |
| var vaultStatBuf = stat() | |
| stat(vaultStatPath, &vaultStatBuf) | |
| let context = try ACPRequestContext(workspaceURL: workspace, vaultURL: vault) | |
| #expect(context.paths.workspaceRootIdentity == ApprovedRootIdentity(metadata: workspaceStatBuf)) | |
| #expect(context.paths.vaultRootIdentity == ApprovedRootIdentity(metadata: vaultStatBuf)) | |
| } | |
| private func makeTemporaryDirectory() throws -> URL { | |
| let directory = FileManager.default.temporaryDirectory | |
| .appendingPathComponent("SSKDocGen-\(UUID().uuidString)", isDirectory: true) | |
| try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) | |
| return directory | |
| } | |
| } | |
Xet Storage Details
- Size:
- 4.08 kB
- Xet hash:
- e8e4bbba285565a4b98e86510fb28d358192afacfb5a2a29b776fa5ab4044227
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.