Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions sdk/typescript/src/multiscan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { execFile as execFileCallback } from "node:child_process";
import { randomUUID } from "node:crypto";
import { realpathSync } from "node:fs";
import {
lstat,
mkdir,
Expand Down Expand Up @@ -367,8 +368,18 @@ async function ensureOutputDirectory(path: string): Promise<string> {
if (metadata?.isSymbolicLink()) {
throw new Error("Multiscan output directories must not be symbolic links.");
}
await mkdir(path, { recursive: true, mode: 0o700 });
const canonical = await realpath(path);
if (metadata !== undefined && !metadata.isDirectory()) {
throw new Error("Multiscan output paths must be directories.");
}
let prepared = path;
if (metadata === undefined) {
prepared =
process.platform === "win32"
? await canonicalWindowsCreationPath(path)
: path;
await mkdir(prepared, { recursive: true, mode: 0o700 });
}
const canonical = await realpath(prepared);
const directory = await lstat(canonical);
if (
metadata !== undefined &&
Expand All @@ -391,6 +402,20 @@ async function ensureOutputDirectory(path: string): Promise<string> {
return canonical;
}

async function canonicalWindowsCreationPath(path: string): Promise<string> {
let ancestor = dirname(path);
for (;;) {
try {
return resolve(await realpath(ancestor), relative(ancestor, path));
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
const parent = dirname(ancestor);
if (parent === ancestor) throw error;
ancestor = parent;
}
Comment thread
faizan-oai marked this conversation as resolved.
}
}

async function appendReceipt(path: string, receipt: string): Promise<void> {
const file = await open(path, "a", 0o600);
try {
Expand Down Expand Up @@ -762,7 +787,15 @@ function normalizeRepository(repository: string, directory: string): string {
);
}
if (/^[^@\s/:]+@[^:\s/]+:.+$/u.test(repository)) return repository;
if (!repository.includes("://")) return resolve(directory, repository);
if (!repository.includes("://")) {
const path = resolve(directory, repository);
if (process.platform !== "win32") return path;
try {
return realpathSync.native(path);
} catch {
return path;
}
}
let url: URL;
try {
url = new URL(repository);
Expand Down
25 changes: 25 additions & 0 deletions sdk/typescript/tests-ts/multiscan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,31 @@ describe("multiscan", () => {
expect(calls).toBe(2);
});

test.skipIf(process.platform !== "win32")(
"resumes campaigns across Windows repository path aliases",
async () => {
const paths = await fixture();
const source = await repository(paths.root, "resume-alias");
const inventory = (repositoryPath: string) =>
`id,repository,revision\nresume,${repositoryPath},${source.revision}\n`;
let calls = 0;
const security = client(async (_repository, scanOptions = {}) => {
calls += 1;
return await completedScan(scanOptions.outputDir!);
});

await writeFile(paths.input, inventory(source.path));
await runMultiscan(options(paths, security));
await writeFile(paths.input, inventory(source.path.toUpperCase()));

expect(await runMultiscan(options(paths, security))).toMatchObject({
completed: 1,
skipped: 1,
});
expect(calls).toBe(1);
},
);

test("ignores repository-local Git shims while preserving credential configuration", async () => {
const paths = await fixture();
const source = await repository(paths.root, "private");
Expand Down
Loading