Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d323cac
refactor: add missing types for attestation, remove gitAccount from A…
jescalada Dec 5, 2025
fd0db0b
chore: add missing Express.Request types in action files
jescalada Dec 5, 2025
aff314e
chore: add missing db types
jescalada Dec 5, 2025
8c50807
refactor: extend Express.Request to include bodyRaw and customPipe fi…
jescalada Dec 5, 2025
e928368
fix: proxy hanging on push due to improper req.pipe override
jescalada Dec 6, 2025
528d214
refactor: improve UI component and service typing
jescalada Dec 7, 2025
292c846
refactor: add BASE_COMMIT_CONTENT object to remove any types in testP…
jescalada Dec 11, 2025
6ff457e
chore: remove any types in ConfigLoader test (private field access)
jescalada Dec 11, 2025
1edc320
refactor: improve typings in various test files
jescalada Dec 11, 2025
4535c5a
refactor: add SAMPLE_COMMIT and remove any types in getDiff
jescalada Dec 11, 2025
1b4c2ab
chore: remove any types in gitLeaks tests
jescalada Dec 11, 2025
73c9c0b
chore: use SAMPLE_COMMIT for commit data and remove any types in chec…
jescalada Dec 11, 2025
30b86e3
chore: add various missing test stub types
jescalada Dec 11, 2025
d5e21db
chore: use SAMPLE_COMMIT for commit data in checkAuthorEmails tests
jescalada Dec 11, 2025
82bd72c
chore: remove any types in UI
jescalada Dec 12, 2025
3320f3f
refactor: repo and push UI error handling, remove any error types
jescalada Dec 12, 2025
ac9cf2b
refactor: test file any removal (proxy, testDb, repo, forcePush, preR…
jescalada Dec 12, 2025
f29ddbb
chore: add unknown typing to error catch and process message (plugin,…
jescalada Dec 12, 2025
06dc08a
refactor: add SAMPLE_REPO, replace in tests to remove any, add types …
jescalada Dec 12, 2025
ca4d703
Merge branch '1174-remove-any-and-as-ts-wrapup' of https://github.com…
jescalada Dec 12, 2025
a301eaa
refactor: cli test any/as removal, extract SAMPLE_REPO to constant
jescalada Dec 14, 2025
d6664f1
chore: add missing types for auth files and plugin.ts
jescalada Dec 14, 2025
3cd816f
refactor: remove any types from remaining catch(error)
jescalada Dec 14, 2025
3e56231
chore: remove general any/as in tests (req casting, etc.)
jescalada Dec 14, 2025
1863ff8
chore: add missing types for auth-related tests (oidc, activeDirector…
jescalada Dec 14, 2025
ce58dcc
refactor: db & checkCommitMessages tests to use Action instead of pus…
jescalada Dec 14, 2025
3824d09
refactor: remaining any/as removal in tests, explicit unknown casting…
jescalada Dec 14, 2025
a1455ca
chore: add unknown type to error catch clauses, improve error visibility
jescalada Dec 15, 2025
1f15141
Merge branch 'main' into 1174-remove-any-and-as-ts-wrapup
jescalada Dec 15, 2025
62a7d84
chore: fix failing test after error refactors
jescalada Dec 17, 2025
4d203e6
chore: fix failing tests (revision range error)
jescalada Dec 17, 2025
596257c
Merge branch 'main' into 1174-remove-any-and-as-ts-wrapup
jescalada Dec 17, 2025
edcfe3c
chore: fix Proxy type errors
jescalada Dec 17, 2025
b7b803c
fix: user.admin errors and failing e2e tests
jescalada Dec 17, 2025
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
51 changes: 28 additions & 23 deletions packages/git-proxy-cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import axios from 'axios';
import axios, { isAxiosError } from 'axios';
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import fs from 'fs';
Expand Down Expand Up @@ -47,13 +47,16 @@ async function login(username: string, password: string) {
const user = `"${response.data.username}" <${response.data.email}>`;
const isAdmin = response.data.admin ? ' (admin)' : '';
console.log(`Login ${user}${isAdmin}: OK`);
} catch (error: any) {
if (error.response) {
} catch (error: unknown) {
if (isAxiosError(error) && error.response) {
console.error(`Error: Login '${username}': '${error.response.status}'`);
process.exitCode = 1;
} else {
} else if (error instanceof Error) {
console.error(`Error: Login '${username}': '${error.message}'`);
process.exitCode = 2;
} else {
console.error(`Error: Login '${username}': '${error}'`);
process.exitCode = 2;
}
}
}
Expand Down Expand Up @@ -165,8 +168,9 @@ async function getGitPushes(filters: Partial<PushQuery>) {
});

console.log(util.inspect(records, false, null, false));
} catch (error: any) {
console.error(`Error: List: '${error.message}'`);
} catch (error: unknown) {
const msg = error instanceof Error ? error.message : String(error);
console.error(`Error: List: '${msg}'`);
process.exitCode = 2;
}
}
Expand Down Expand Up @@ -207,12 +211,12 @@ async function authoriseGitPush(id: string) {
);

console.log(`Authorise: ID: '${id}': OK`);
} catch (error: any) {
} catch (error: unknown) {
// default error
let errorMessage = `Error: Authorise: '${error.message}'`;
let errorMessage = `Error: Authorise: '${error instanceof Error ? error.message : String(error)}'`;
process.exitCode = 2;

if (error.response) {
if (isAxiosError(error) && error.response) {
switch (error.response.status) {
case 401:
errorMessage = 'Error: Authorise: Authentication required';
Expand Down Expand Up @@ -254,12 +258,12 @@ async function rejectGitPush(id: string) {
);

console.log(`Reject: ID: '${id}': OK`);
} catch (error: any) {
} catch (error: unknown) {
// default error
let errorMessage = `Error: Reject: '${error.message}'`;
let errorMessage = `Error: Reject: '${error instanceof Error ? error.message : String(error)}'`;
process.exitCode = 2;

if (error.response) {
if (isAxiosError(error) && error.response) {
switch (error.response.status) {
case 401:
errorMessage = 'Error: Reject: Authentication required';
Expand Down Expand Up @@ -301,12 +305,12 @@ async function cancelGitPush(id: string) {
);

console.log(`Cancel: ID: '${id}': OK`);
} catch (error: any) {
} catch (error: unknown) {
// default error
let errorMessage = `Error: Cancel: '${error.message}'`;
let errorMessage = `Error: Cancel: '${error instanceof Error ? error.message : String(error)}'`;
process.exitCode = 2;

if (error.response) {
if (isAxiosError(error) && error.response) {
switch (error.response.status) {
case 401:
errorMessage = 'Error: Cancel: Authentication required';
Expand Down Expand Up @@ -338,8 +342,9 @@ async function logout() {
headers: { Cookie: cookies },
},
);
} catch (error: any) {
console.log(`Warning: Logout: '${error.message}'`);
} catch (error: unknown) {
const msg = error instanceof Error ? error.message : String(error);
console.log(`Warning: Logout: '${msg}'`);
}
}

Expand All @@ -362,10 +367,10 @@ async function reloadConfig() {
await axios.post(`${baseUrl}/api/v1/admin/reload-config`, {}, { headers: { Cookie: cookies } });

console.log('Configuration reloaded successfully');
} catch (error: any) {
const errorMessage = `Error: Reload config: '${error.message}'`;
} catch (error: unknown) {
const msg = error instanceof Error ? error.message : String(error);
console.error(`Error: Reload config: '${msg}'`);
process.exitCode = 2;
console.error(errorMessage);
}
}

Expand Down Expand Up @@ -408,11 +413,11 @@ async function createUser(
);

console.log(`User '${username}' created successfully`);
} catch (error: any) {
let errorMessage = `Error: Create User: '${error.message}'`;
} catch (error: unknown) {
let errorMessage = `Error: Create User: '${error instanceof Error ? error.message : String(error)}'`;
process.exitCode = 2;

if (error.response) {
if (isAxiosError(error) && error.response) {
switch (error.response.status) {
case 401:
errorMessage = 'Error: Create User: Authentication required';
Expand Down
22 changes: 12 additions & 10 deletions packages/git-proxy-cli/test/testCli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import path from 'path';
import { describe, it, beforeAll, afterAll } from 'vitest';

import { setConfigFile } from '../../../src/config/file';

import { Repo } from '../../../src/db/types';
import { SAMPLE_REPO } from '../../../src/proxy/processors/constants';

setConfigFile(path.join(process.cwd(), 'test', 'testCli.proxy.config.json'));

Expand All @@ -14,6 +13,7 @@ const GHOST_PUSH_ID =
'0000000000000000000000000000000000000000__79b4d8953cbc324bcc1eb53d6412ff89666c241f';
// repo for test cases
const TEST_REPO_CONFIG = {
...SAMPLE_REPO,
project: 'finos',
name: 'git-proxy-test',
url: 'https://github.com/finos/git-proxy-test.git',
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('test git-proxy-cli', function () {
const pushId = `auth000000000000000000000000000000000000__${Date.now()}`;

beforeAll(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG as Repo);
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, TEST_USER, TEST_EMAIL);
});
Expand Down Expand Up @@ -297,7 +297,7 @@ describe('test git-proxy-cli', function () {
const pushId = `cancel0000000000000000000000000000000000__${Date.now()}`;

beforeAll(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG as Repo);
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
await helper.addGitPushToDb(pushId, TEST_USER, TEST_EMAIL, TEST_REPO);
});
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('test git-proxy-cli', function () {
const pushId = `reject0000000000000000000000000000000000__${Date.now()}`;

beforeAll(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG as Repo);
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, TEST_USER, TEST_EMAIL);
});
Expand Down Expand Up @@ -582,8 +582,9 @@ describe('test git-proxy-cli', function () {
// Clean up the created user
try {
await helper.removeUserFromDb(uniqueUsername);
} catch (error: any) {
// Ignore cleanup errors
} catch (error: unknown) {
const msg = error instanceof Error ? error.message : String(error);
console.error(`Error cleaning up user: ${msg}`);
}
}
});
Expand Down Expand Up @@ -612,8 +613,9 @@ describe('test git-proxy-cli', function () {
// Clean up the created user
try {
await helper.removeUserFromDb(uniqueUsername);
} catch (error: any) {
console.error('Error cleaning up user', error);
} catch (error: unknown) {
const msg = error instanceof Error ? error.message : String(error);
console.error(`Error cleaning up user: ${msg}`);
}
}
});
Expand All @@ -625,7 +627,7 @@ describe('test git-proxy-cli', function () {
const pushId = `0000000000000000000000000000000000000000__${Date.now()}`;

beforeAll(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG as Repo);
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, TEST_USER, TEST_EMAIL);
});
Expand Down
59 changes: 37 additions & 22 deletions packages/git-proxy-cli/test/testCliUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import util from 'util';
import { exec } from 'child_process';
import { expect } from 'vitest';
import { Request } from 'express';

import Proxy from '../../../src/proxy';
import { Action } from '../../../src/proxy/actions/Action';
Expand All @@ -10,12 +11,24 @@ import { exec as execProcessor } from '../../../src/proxy/processors/push-action
import * as db from '../../../src/db';
import { Repo } from '../../../src/db/types';
import service from '../../../src/service';
import { CommitData } from '../../../src/proxy/processors/types';

const execAsync = util.promisify(exec);

// cookie file name
const GIT_PROXY_COOKIE_FILE = 'git-proxy-cookie';

/**
* Type guard to check if error is from child_process exec
*/
function isExecError(error: unknown): error is Error & {
code: number;
stdout: string;
stderr: string;
} {
return error instanceof Error && 'code' in error && 'stdout' in error && 'stderr' in error;
}

/**
* @async
* @param {string} cli - The CLI command to be executed.
Expand Down Expand Up @@ -54,28 +67,29 @@ async function runCli(
expect(stderr).toContain(expectedErrorMessage);
});
}
} catch (error: any) {
const exitCode = error.code;
if (!exitCode) {
// an AssertionError is thrown from failing some of the expectations
// in the 'try' block: forward it to Mocha to process
} catch (error: unknown) {
if (isExecError(error)) {
const exitCode = error.code;

if (debug) {
console.log(`error.stdout: ${error.stdout}`);
console.log(`error.stderr: ${error.stderr}`);
}
expect(exitCode).toEqual(expectedExitCode);
if (expectedMessages) {
expectedMessages.forEach((expectedMessage) => {
expect(error.stdout).toContain(expectedMessage);
});
}
if (expectedErrorMessages) {
expectedErrorMessages.forEach((expectedErrorMessage) => {
expect(error.stderr).toContain(expectedErrorMessage);
});
}
} else {
// Assertion error, forward to Vitest to process
throw error;
}
if (debug) {
console.log(`error.stdout: ${error.stdout}`);
console.log(`error.stderr: ${error.stderr}`);
}
expect(exitCode).toEqual(expectedExitCode);
if (expectedMessages) {
expectedMessages.forEach((expectedMessage) => {
expect(error.stdout).toContain(expectedMessage);
});
}
if (expectedErrorMessages) {
expectedErrorMessages.forEach((expectedErrorMessage) => {
expect(error.stderr).toContain(expectedErrorMessage);
});
}
} finally {
if (debug) {
console.log(`cli: '${cli}': done`);
Expand Down Expand Up @@ -214,7 +228,7 @@ async function addGitPushToDb(
`\n\n\nGitProxy has received your push:\n\nhttp://localhost:8080/requests/${id}\n\n\n`, // blockedMessage
null, // content
);
const commitData = [];
const commitData: CommitData[] = [];
commitData.push({
tree: 'tree test',
parent: 'parent',
Expand All @@ -223,10 +237,11 @@ async function addGitPushToDb(
message: 'message',
authorEmail: 'authorEmail',
committerEmail: 'committerEmail',
commitTimestamp: '1234567890',
});
action.commitData = commitData;
action.addStep(step);
const result = await execProcessor(null, action);
const result = await execProcessor({} as Request, action);
if (debug) {
console.log(`New git push added to DB: ${util.inspect(result)}`);
}
Expand Down
Loading
Loading