Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

test(sdk): check Snyk remote aliases before publication (#2076)

Michael D'Angeloe2e8c0cb193c
diff --git a/sdk/typescript/tests-ts/external-findings-publish.test.ts b/sdk/typescript/tests-ts/external-findings-publish.test.ts
index ba4ff139d..971954292 100644
--- a/sdk/typescript/tests-ts/external-findings-publish.test.ts
+++ b/sdk/typescript/tests-ts/external-findings-publish.test.ts
@@ -23,9 +23,11 @@ import {
prepareNormalizedExternalPublication,
type ExternalPublicationProgress,
} from "../src/external-findings-publish.js";
+import { snykRepositoryUrls } from "../src/snyk-findings.js";
import { readGitHubFindings } from "../src/github-findings.js";
import { readVendorFindings } from "../src/wiz-findings.js";
import {
+ cloudRepositoryUrlKey,
validateExternalEvidence,
validateImportRequest,
validateRepositories,
@@ -3231,78 +3233,42 @@ async function snykRepositoryEvidence(
};
}
+const gitHubProject = "https://github.com/example/project";
+const connectedProject = "https://git.example.test/example/project";
+const tenantProject = "https://tenant.ghe.com/example/project";
+
const snykRepositoryAliases: [string, string][] = [
- [
- "https://github.com/example/project.git",
- "https://github.com/example/project",
- ],
- ["[email protected]:example/project.git", "https://github.com/example/project"],
- [
- "ssh://[email protected]/example/project.git",
- "https://github.com/example/project",
- ],
- [
- "ssh://[email protected]:22/example/project.git",
- "https://github.com/example/project",
- ],
- [
- "ssh://[email protected]:443/example/project.git",
- "https://github.com/example/project",
- ],
- [
- "[email protected]:example/project.git",
- "https://git.example.test/example/project",
- ],
- [
- "ssh://[email protected]/example/project.git",
- "https://git.example.test/example/project",
- ],
- [
- "ssh://[email protected]:22/example/project.git",
- "https://git.example.test/example/project",
- ],
- [
- "[email protected]:example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://[email protected]/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://[email protected]:22/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
+ ["https://github.com/example/project.git", gitHubProject],
+ ["[email protected]:example/project.git", gitHubProject],
+ ["ssh://[email protected]/example/project.git", gitHubProject],
+ ["ssh://[email protected]:22/example/project.git", gitHubProject],
+ ["ssh://[email protected]:443/example/project.git", gitHubProject],
+ ["[email protected]:example/project.git", connectedProject],
+ ["ssh://[email protected]/example/project.git", connectedProject],
+ ["ssh://[email protected]:22/example/project.git", connectedProject],
+ ["[email protected]:example/project.git", tenantProject],
+ ["ssh://[email protected]/example/project.git", tenantProject],
+ ["ssh://[email protected]:22/example/project.git", tenantProject],
// Preserve the existing generic git-user aliases for connected catalog hosts.
- [
- "[email protected]:example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://[email protected]/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://[email protected]:22/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "[email protected]:example/project.git",
- "https://git.example.test/example/project",
- ],
- [
- "https://git.example.test/example/project.git",
- "https://git.example.test/example/project",
- ],
+ ["[email protected]:example/project.git", tenantProject],
+ ["ssh://[email protected]/example/project.git", tenantProject],
+ ["ssh://[email protected]:22/example/project.git", tenantProject],
+ ["[email protected]:example/project.git", connectedProject],
+ ["https://git.example.test/example/project.git", connectedProject],
];
test.each([
- ...snykRepositoryAliases.flatMap(([repository, destination]) =>
- (["plugin", "SARIF"] as const).map(
- (format) => [format, repository, destination] as const,
- ),
- ),
- ["plugin", "unknown", "https://github.com/example/project"] as const,
+ [
+ "plugin",
+ "ssh://[email protected]:22/example/project.git",
+ tenantProject,
+ ] as const,
+ [
+ "SARIF",
+ "ssh://[email protected]:443/example/project.git",
+ gitHubProject,
+ ] as const,
+ ["plugin", "unknown", gitHubProject] as const,
])(
"Snyk %s export imports and replays with repository remote %s",
async (format, repository, destination) => {
@@ -3336,95 +3302,50 @@ test.each([
const snykRepositoryMismatches: [string, string][] = [
...["\t", "\r", "\n"].flatMap((control): [string, string][] => [
- [
- `ssh://git@github.${control}com/example/project.git`,
- "https://github.com/example/project",
- ],
- [
- `ssh://[email protected]/example/pro${control}ject.git`,
- "https://github.com/example/project",
- ],
+ [`ssh://git@github.${control}com/example/project.git`, gitHubProject],
+ [`ssh://[email protected]/example/pro${control}ject.git`, gitHubProject],
[
`ssh://tenant@tenant.${control}ghe.com/example/project.git`,
- "https://tenant.ghe.com/example/project",
+ tenantProject,
],
[
`ssh://[email protected]/example/pro${control}ject.git`,
- "https://tenant.ghe.com/example/project",
+ tenantProject,
],
[
`ssh://[email protected].${control}com:443/example/project.git`,
- "https://github.com/example/project",
+ gitHubProject,
],
[
`ssh://[email protected]:443/example/pro${control}ject.git`,
- "https://github.com/example/project",
+ gitHubProject,
],
]),
[
"ssh://tenant@other:[email protected]/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://tenant@other:@tenant.ghe.com/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://git@other:[email protected]/example/project.git",
- "https://github.com/example/project",
- ],
- [
- "ssh://git@other:@github.com/example/project.git",
- "https://github.com/example/project",
- ],
- [
- "ssh://te\[email protected]/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://te\[email protected]/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://te\[email protected]/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://gi\[email protected]/example/project.git",
- "https://github.com/example/project",
- ],
- [
- "ssh://tenant@[email protected]/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "[email protected]:example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://[email protected]:22/example/project.git",
- "https://tenant.ghe.com/example/project",
+ tenantProject,
],
+ ["ssh://tenant@other:@tenant.ghe.com/example/project.git", tenantProject],
+ ["ssh://git@other:[email protected]/example/project.git", gitHubProject],
+ ["ssh://git@other:@github.com/example/project.git", gitHubProject],
+ ["ssh://te\[email protected]/example/project.git", tenantProject],
+ ["ssh://te\[email protected]/example/project.git", tenantProject],
+ ["ssh://te\[email protected]/example/project.git", tenantProject],
+ ["ssh://gi\[email protected]/example/project.git", gitHubProject],
+ ["ssh://tenant@[email protected]/example/project.git", tenantProject],
+ ["[email protected]:example/project.git", tenantProject],
+ ["ssh://[email protected]:22/example/project.git", tenantProject],
[
"[email protected]:example/project.git",
"https://other.ghe.com/example/project",
],
- [
- "ssh://[email protected]/example/project.git",
- "https://git.example.test/example/project",
- ],
+ ["ssh://[email protected]/example/project.git", connectedProject],
[
"ssh://[email protected]/example/project.git",
"https://api.tenant.ghe.com/example/project",
],
- [
- "ssh://tenant:[email protected]/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://tenant:@tenant.ghe.com/example/project.git",
- "https://tenant.ghe.com/example/project",
- ],
+ ["ssh://tenant:[email protected]/example/project.git", tenantProject],
+ ["ssh://tenant:@tenant.ghe.com/example/project.git", tenantProject],
[
"ssh://[email protected]:443/example/project.git",
"https://tenant.ghe.com:443/example/project",
@@ -3433,31 +3354,16 @@ const snykRepositoryMismatches: [string, string][] = [
"ssh://[email protected]:22/example/project.git",
"https://tenant.ghe.com:443/example/project",
],
- [
- "[email protected]:other/project.git",
- "https://tenant.ghe.com/example/project",
- ],
- [
- "ssh://[email protected]:443/example/project.git",
- "https://github.com/example/project",
- ],
+ ["[email protected]:other/project.git", tenantProject],
+ ["ssh://[email protected]:443/example/project.git", gitHubProject],
[
"[email protected]:example/project.git",
"http://tenant.ghe.com/example/project",
],
- ["[email protected]:other/project.git", "https://github.com/example/project"],
- [
- "ssh://[email protected]:2222/example/project.git",
- "https://github.com/example/project",
- ],
- [
- "ssh://[email protected]:2222/example/project.git",
- "https://github.com/example/project",
- ],
- [
- "ssh://[email protected]:443/example/project.git",
- "https://github.com/example/project",
- ],
+ ["[email protected]:other/project.git", gitHubProject],
+ ["ssh://[email protected]:2222/example/project.git", gitHubProject],
+ ["ssh://[email protected]:2222/example/project.git", gitHubProject],
+ ["ssh://[email protected]:443/example/project.git", gitHubProject],
[
"ssh://[email protected]:2222/example/project.git",
"https://git.example.test:2222/example/project",
@@ -3482,14 +3388,8 @@ const snykRepositoryMismatches: [string, string][] = [
"ssh://[email protected]:2222/example/project.git",
"https://ssh.github.com:2222/example/project",
],
- [
- "[email protected]:example/project.git",
- "https://git.example.test/example/project",
- ],
- [
- "[email protected]:other/project.git",
- "https://git.example.test/example/project",
- ],
+ ["[email protected]:example/project.git", connectedProject],
+ ["[email protected]:other/project.git", connectedProject],
[
"[email protected]:example/project.git",
"https://git.example.test:443/example/project",
@@ -3504,13 +3404,47 @@ const snykRepositoryMismatches: [string, string][] = [
],
];
+// Check the URL matrix before involving the filesystem, catalog, or publication state.
+for (const [cases, matches] of [
+ [snykRepositoryAliases, true],
+ [snykRepositoryMismatches, false],
+] as const) {
+ test.each(cases)(
+ `Snyk repository %j against %j (matches=${matches})`,
+ async (repository, destination) => {
+ for (const format of ["plugin", "SARIF"] as const) {
+ const { normalized, original } = await snykRepositoryEvidence(
+ format,
+ repository,
+ );
+ const source = normalized.findings[0]!.evidence.source_data;
+ const urls = snykRepositoryUrls(source, {
+ cloudRepositoryUrl: destination,
+ });
+ expect(urls, format).toHaveLength(1);
+ expect(
+ cloudRepositoryUrlKey(urls[0]!) ===
+ cloudRepositoryUrlKey(destination),
+ format,
+ ).toBe(matches);
+ expect(source, format).toMatchObject(original);
+ }
+ },
+ );
+}
+
test.each([
- ...snykRepositoryMismatches.flatMap(([repository, destination]) =>
- (["plugin", "SARIF"] as const).map(
- (format) => [format, repository, destination] as const,
- ),
- ),
- ["SARIF", "unknown", "https://github.com/example/project"] as const,
+ [
+ "plugin",
+ "ssh://git@github.\tcom/example/project.git",
+ gitHubProject,
+ ] as const,
+ [
+ "SARIF",
+ "ssh://[email protected]:2222/example/project.git",
+ gitHubProject,
+ ] as const,
+ ["SARIF", "unknown", gitHubProject] as const,
])(
"Snyk %s repository claim %s cannot target %s",
async (format, repository, destination) => {