fix(server): reject invalid explicit Bitbucket repositories (#15876)
This commit is contained in:
1 parent
4980ba282e
commit
9ae9f2ba1f
4 files changed
+248
-23
No files matched your search
@@ -6,16 +6,21 @@ import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { ChildProcessSpawner } from "effect/process";
|
||||
|
||||
import { GitCommandError, SourceControlProviderError } from "@t3tools/contracts";
|
||||
|
||||
import * as ServerConfig from "../config.ts";
|
||||
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
|
||||
import * as BitbucketApi from "./BitbucketApi.ts";
|
||||
import * as BitbucketSourceControlProvider from "./BitbucketSourceControlProvider.ts";
|
||||
import type * as SourceControlProvider from "./SourceControlProvider.ts";
|
||||
import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts";
|
||||
import * as SourceControlRepositoryService from "./SourceControlRepositoryService.ts";
|
||||
|
||||
const isSourceControlProviderError = Schema.is(SourceControlProviderError);
|
||||
|
||||
const CLONE_URLS = {
|
||||
nameWithOwner: "octocat/t3code",
|
||||
url: "https://github.com/octocat/t3code",
|
||||
@@ -152,6 +157,112 @@ it.effect("preserves provider failures without deriving the repository message f
|
||||
}).pipe(Effect.provide(layer({ provider })));
|
||||
});
|
||||
|
||||
it.effect(
|
||||
"reports the safe Bitbucket locator detail through repository lookup and publishing",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const locatorCause = new BitbucketApi.BitbucketRepositoryLocatorError({
|
||||
repository: "credential-token-abc123",
|
||||
});
|
||||
const provider = yield* BitbucketSourceControlProvider.make.pipe(
|
||||
Effect.provide(
|
||||
Layer.mock(BitbucketApi.BitbucketApi)({
|
||||
getRepositoryCloneUrls: () => Effect.fail(locatorCause),
|
||||
createRepository: () => Effect.fail(locatorCause),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
yield* Effect.gen(function* () {
|
||||
const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
|
||||
const input = {
|
||||
provider: "bitbucket" as const,
|
||||
repository: locatorCause.repository,
|
||||
cwd: "/workspace",
|
||||
};
|
||||
for (const operation of [
|
||||
service.lookupRepository(input).pipe(Effect.asVoid),
|
||||
service.publishRepository({ ...input, visibility: "private" }).pipe(Effect.asVoid),
|
||||
]) {
|
||||
const error = yield* Effect.flip(operation);
|
||||
|
||||
assert.strictEqual(error.provider, "bitbucket");
|
||||
assert.strictEqual(
|
||||
error.detail,
|
||||
"Bitbucket repositories must be specified as workspace/repository.",
|
||||
);
|
||||
assert.notInclude(error.message, locatorCause.repository);
|
||||
assert.instanceOf(error.cause, SourceControlProviderError);
|
||||
assert.strictEqual(
|
||||
isSourceControlProviderError(error.cause) ? error.cause.cause : null,
|
||||
locatorCause,
|
||||
);
|
||||
}
|
||||
}).pipe(Effect.provide(layer({ provider })));
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("keeps a plain Bitbucket locator lookalike out of the repository message", () => {
|
||||
const provider = makeProvider({
|
||||
kind: "bitbucket",
|
||||
getRepositoryCloneUrls: () =>
|
||||
Effect.fail(
|
||||
new SourceControlProviderError({
|
||||
provider: "bitbucket",
|
||||
operation: "getRepositoryCloneUrls",
|
||||
cwd: "/workspace",
|
||||
detail: "credential token abc123 was rejected",
|
||||
cause: {
|
||||
_tag: "BitbucketRepositoryLocatorError",
|
||||
repository: "t3code",
|
||||
detail: "credential token abc123 was rejected",
|
||||
},
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
|
||||
const error = yield* Effect.flip(
|
||||
service.lookupRepository({ provider: "bitbucket", repository: "t3code" }),
|
||||
);
|
||||
|
||||
assert.strictEqual(error.detail, "The source control operation could not be completed.");
|
||||
assert.notInclude(error.message, "abc123");
|
||||
}).pipe(Effect.provide(layer({ provider })));
|
||||
});
|
||||
|
||||
it.effect("keeps arbitrary Bitbucket request failures out of the repository message", () =>
|
||||
Effect.gen(function* () {
|
||||
const cause = new BitbucketApi.BitbucketRequestError({
|
||||
operation: "getRepository",
|
||||
cause: new Error("credential token abc123 was rejected"),
|
||||
});
|
||||
const provider = yield* BitbucketSourceControlProvider.make.pipe(
|
||||
Effect.provide(
|
||||
Layer.mock(BitbucketApi.BitbucketApi)({
|
||||
getRepositoryCloneUrls: () => Effect.fail(cause),
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
yield* Effect.gen(function* () {
|
||||
const service = yield* SourceControlRepositoryService.SourceControlRepositoryService;
|
||||
const error = yield* Effect.flip(
|
||||
service.lookupRepository({
|
||||
provider: "bitbucket",
|
||||
repository: "pingdotgg/t3code",
|
||||
cwd: "/workspace",
|
||||
}),
|
||||
);
|
||||
|
||||
assert.strictEqual(error.detail, "The source control operation could not be completed.");
|
||||
assert.notInclude(error.message, "abc123");
|
||||
assert.notInclude(error.message, cause.detail);
|
||||
}).pipe(Effect.provide(layer({ provider })));
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("clones a looked-up repository into the requested destination", () =>
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
|
||||
Reference in new issue
Block a user