Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
32be720
fix: user should be looked up by email rather than name
kriswest Mar 12, 2025
85f4b4e
fix: error in destructuring of action commit data
kriswest Mar 13, 2025
3c53683
fix: lookup users via email rather than user.name git client config
kriswest Mar 21, 2025
2b04db4
fix: typo in comment
kriswest Mar 27, 2025
1b4bd58
test: use unique emails for users in tests and remove afterwards
kriswest Apr 1, 2025
f5e952c
chore: prettier
kriswest Apr 8, 2025
16def58
fix: clean-up DB after CLI tests
kriswest Apr 11, 2025
5380e2f
test: tests for CLI set better user data and clean up afterwards
kriswest Apr 11, 2025
a7fc824
test: don't clean-up test-repo as cypress tests rely on it
kriswest Apr 11, 2025
96cab2d
test: coverage for checkUserPushPermission
kriswest Apr 15, 2025
7326a4c
test: basic db test coverage
kriswest Apr 15, 2025
fbc2406
test: coverage for push API calls
kriswest Apr 15, 2025
d0e651c
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Apr 16, 2025
f9aa184
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest May 7, 2025
411d27c
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest May 12, 2025
d3832ca
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest May 22, 2025
01d47b9
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jun 3, 2025
56a1947
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jun 5, 2025
3efe9fe
Merge branch '1049-fix-config-loader-tests' into 946-associate-commit…
kriswest Jun 10, 2025
e8d1fd2
test: fix test failures caused by conflicts with main
kriswest Jun 10, 2025
a9b5810
Merge remote-tracking branch 'github/946-associate-commits-by-email-r…
kriswest Jun 10, 2025
fff6932
Merge branch 'main' into 946-associate-commits-by-email-rebase
JamieSlome Jun 16, 2025
7e36e21
chore: prettier
kriswest Jun 16, 2025
ad7d43a
Merge remote-tracking branch 'upstream-prod/946-associate-commits-by-…
kriswest Jun 16, 2025
a0027c2
Merge remote-tracking branch 'upstream-prod/946-associate-commits-by-…
kriswest Jun 16, 2025
5be05b1
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jun 18, 2025
0063756
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 3, 2025
d8e5b3d
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 4, 2025
041b6c7
fix: typing issue in getCommitData
kriswest Jul 4, 2025
4274607
fix: rationalize parsePush.getCommitData in response to review
kriswest Jul 7, 2025
bbd7f49
test: enable pushParsing tests
kriswest Jul 7, 2025
47a23a7
fix: remove debug logs in parsePush
kriswest Jul 8, 2025
ba9aeb1
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 9, 2025
4707967
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 10, 2025
3fd998e
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 10, 2025
9cb8104
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 11, 2025
5fbe156
chore: minor dependency updates from npm audit fix
kriswest Jul 11, 2025
6044dec
Merge remote-tracking branch 'github/946-associate-commits-by-email-r…
kriswest Jul 11, 2025
ad5d083
Merge branch 'main' into 946-associate-commits-by-email-rebase
jescalada Jul 11, 2025
d2a17c9
Merge remote-tracking branch 'finos/main' into 946-associate-commits-…
kriswest Jul 14, 2025
ee7c446
Merge remote-tracking branch 'github/946-associate-commits-by-email-r…
kriswest Jul 14, 2025
f8f10e2
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 21, 2025
754bb3b
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 31, 2025
e5c89a9
test: fixing test failure post merging main
kriswest Jul 31, 2025
5d8c589
fix: fix type errors in getMissingData after merging main
kriswest Jul 31, 2025
645178a
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 31, 2025
33e6ccb
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Jul 31, 2025
f19691c
Merge remote-tracking branch 'github/946-associate-commits-by-email-r…
kriswest Jul 31, 2025
057e7b9
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Aug 5, 2025
39faa2b
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Aug 5, 2025
e264efb
Merge branch 'main' into 946-associate-commits-by-email-rebase
kriswest Aug 7, 2025
db3130e
Merge remote-tracking branch 'github/946-associate-commits-by-email-r…
kriswest Aug 7, 2025
5b9fe88
test: correcting test after merging main
kriswest Aug 7, 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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"source.fixAll.eslint": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
"editor.formatOnSave": true,
"cSpell.words": ["Deltafied"]
}
9 changes: 6 additions & 3 deletions packages/git-proxy-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ async function authoriseGitPush(id) {
if (error.response) {
switch (error.response.status) {
case 401:
errorMessage = 'Error: Authorise: Authentication required';
errorMessage =
'Error: Authorise: Authentication required (401): ' + error?.response?.data?.message;
process.exitCode = 3;
break;
case 404:
Expand Down Expand Up @@ -223,7 +224,8 @@ async function rejectGitPush(id) {
if (error.response) {
switch (error.response.status) {
case 401:
errorMessage = 'Error: Reject: Authentication required';
errorMessage =
'Error: Reject: Authentication required (401): ' + error?.response?.data?.message;
process.exitCode = 3;
break;
case 404:
Expand Down Expand Up @@ -270,7 +272,8 @@ async function cancelGitPush(id) {
if (error.response) {
switch (error.response.status) {
case 401:
errorMessage = 'Error: Cancel: Authentication required';
errorMessage =
'Error: Cancel: Authentication required (401): ' + error?.response?.data?.message;
process.exitCode = 3;
break;
case 404:
Expand Down
40 changes: 26 additions & 14 deletions packages/git-proxy-cli/test/testCli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const TEST_REPO_CONFIG = {
url: 'https://github.com/finos/git-proxy-test.git',
};
const TEST_REPO = 'finos/git-proxy-test.git';
// user for test cases
const TEST_USER = 'testuser';
const TEST_PASSWORD = 'testpassword';
const TEST_EMAIL = 'jane.doe@email.com';
const TEST_GIT_ACCOUNT = 'testGitAccount';

describe('test git-proxy-cli', function () {
// *** help ***
Expand Down Expand Up @@ -87,16 +92,12 @@ describe('test git-proxy-cli', function () {
// *** login ***

describe('test git-proxy-cli :: login', function () {
const testUser = 'testuser';
const testPassword = 'testpassword';
const testEmail = 'jane.doe@email.com';

before(async function () {
await helper.addUserToDb(testUser, testPassword, testEmail, 'testGitAccount');
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
});

after(async function () {
await helper.removeUserFromDb(testUser);
await helper.removeUserFromDb(TEST_USER);
});

it('login should fail when server is down', async function () {
Expand Down Expand Up @@ -140,9 +141,9 @@ describe('test git-proxy-cli', function () {
});

it('login shoud be successful with valid credentials (non-admin)', async function () {
const cli = `npx -- @finos/git-proxy-cli login --username ${testUser} --password ${testPassword}`;
const cli = `npx -- @finos/git-proxy-cli login --username ${TEST_USER} --password ${TEST_PASSWORD}`;
const expectedExitCode = 0;
const expectedMessages = [`Login "${testUser}" <${testEmail}>: OK`];
const expectedMessages = [`Login "${TEST_USER}" <${TEST_EMAIL}>: OK`];
const expectedErrorMessages = null;
try {
await helper.startServer(service);
Expand Down Expand Up @@ -219,11 +220,13 @@ describe('test git-proxy-cli', function () {

before(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addGitPushToDb(pushId, TEST_REPO);
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
await helper.addGitPushToDb(pushId, TEST_USER, TEST_EMAIL, TEST_REPO);
});

after(async function () {
await helper.removeGitPushFromDb(pushId);
await helper.removeUserFromDb(TEST_USER);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
});

Expand Down Expand Up @@ -294,11 +297,13 @@ describe('test git-proxy-cli', function () {

before(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addGitPushToDb(pushId, TEST_REPO);
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
await helper.addGitPushToDb(pushId, TEST_USER, TEST_EMAIL, TEST_REPO);
});

after(async function () {
await helper.removeGitPushFromDb(pushId);
await helper.removeUserFromDb(TEST_USER);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
});

Expand Down Expand Up @@ -415,11 +420,13 @@ describe('test git-proxy-cli', function () {

before(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addGitPushToDb(pushId, TEST_REPO);
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
await helper.addGitPushToDb(pushId, TEST_USER, TEST_EMAIL, TEST_REPO);
});

after(async function () {
await helper.removeGitPushFromDb(pushId);
await helper.removeUserFromDb(TEST_USER);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
});

Expand Down Expand Up @@ -487,12 +494,17 @@ describe('test git-proxy-cli', function () {

describe('test git-proxy-cli :: git push administration', function () {
const pushId = `0000000000000000000000000000000000000000__${Date.now()}`;
const gitAccount = 'testGitAccount1';

before(async function () {
await helper.addRepoToDb(TEST_REPO_CONFIG);
await helper.addUserToDb('testuser1', 'testpassword', 'test@email.com', gitAccount);
await helper.addGitPushToDb(pushId, TEST_REPO, gitAccount);
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
await helper.addGitPushToDb(pushId, TEST_REPO, TEST_USER, TEST_EMAIL);
});

after(async function () {
await helper.removeGitPushFromDb(pushId);
await helper.removeUserFromDb(TEST_USER);
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
});

after(async function () {
Expand Down
4 changes: 3 additions & 1 deletion packages/git-proxy-cli/test/testCliUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ async function removeRepoFromDb(repoName) {
* @param {string} id The ID of the git push.
* @param {string} repo The repository of the git push.
* @param {string} user The user who pushed the git push.
* @param {string} userEmail The email of the user who pushed the git push.
* @param {boolean} debug Flag to enable logging for debugging.
*/
async function addGitPushToDb(id, repo, user = null, debug = false) {
async function addGitPushToDb(id, repo, user = null, userEmail = null, debug = false) {
const action = new actions.Action(
id,
'push', // type
Expand All @@ -188,6 +189,7 @@ async function addGitPushToDb(id, repo, user = null, debug = false) {
repo,
);
action.user = user;
action.userEmail = userEmail;
const step = new steps.Step(
'authBlock', // stepName
false, // error
Expand Down
2 changes: 2 additions & 0 deletions src/proxy/actions/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Step } from './Step';
export interface Commit {
message: string;
committer: string;
committerEmail: string;
tree: string;
parent: string;
author: string;
Expand Down Expand Up @@ -45,6 +46,7 @@ class Action {
message?: string;
author?: string;
user?: string;
userEmail?: string;
attestation?: string;
lastStep?: Step;
proxyGitPath?: string;
Expand Down
46 changes: 28 additions & 18 deletions src/proxy/processors/push-action/checkUserPushPermission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ import { trimTrailingDotGit } from '../../../db/helper';
// Execute if the repo is approved
const exec = async (req: any, action: Action): Promise<Action> => {
const step = new Step('checkUserPushPermission');
const user = action.user;
const userEmail = action.userEmail;

if (!user) {
if (!userEmail) {
step.setError('Push blocked: User not found. Please contact an administrator for support.');
action.addStep(step);
step.error = true;
return action;
}

return await validateUser(user, action, step);
return await validateUser(userEmail, action, step);
};

/**
* Helper that validates the user's push permission.
* This can be used by other actions that need it.
* @param {string} user The user to validate
* @param {string} userEmail The user to validate
* @param {Action} action The action object
* @param {Step} step The step object
* @return {Promise<Action>} The action object
*/
const validateUser = async (user: string, action: Action, step: Step): Promise<Action> => {
const validateUser = async (userEmail: string, action: Action, step: Step): Promise<Action> => {
const repoSplit = trimTrailingDotGit(action.repo.toLowerCase()).split('/');

// we expect there to be exactly one / separating org/repoName
if (repoSplit.length != 2) {
step.setError('Server-side issue extracting repoName');
Expand All @@ -37,35 +38,44 @@ const validateUser = async (user: string, action: Action, step: Step): Promise<A
const repoName = repoSplit[1];
let isUserAllowed = false;

// Find the user associated with this Git Account
const list = await getUsers({ gitAccount: action.user });
// Find the user associated with this email address
const list = await getUsers({ email: userEmail });

console.log(`Users for this git account: ${JSON.stringify(list)}`);
if (list.length > 1) {
console.error(`Multiple users found with email address ${userEmail}, ending`);
step.error = true;
step.log(
`Multiple Users have email <${userEmail}> so we cannot uniquely identify the user, ending`,
);

if (list.length == 1) {
user = list[0].username;
isUserAllowed = await isUserPushAllowed(repoName, user);
step.setError(
`Your push has been blocked (there are multiple users with email ${action.userEmail})`,
);
action.addStep(step);
return action;
} else if (list.length == 0) {
console.error(`No user with email address ${userEmail} found`);
} else {
isUserAllowed = await isUserPushAllowed(repoName, list[0].username);
}

console.log(`User ${user} permission on Repo ${repoName} : ${isUserAllowed}`);
console.log(`User ${userEmail} permission on Repo ${repoName} : ${isUserAllowed}`);

if (!isUserAllowed) {
console.log('User not allowed to Push');
step.error = true;
step.log(`User ${user} is not allowed to push on repo ${action.repo}, ending`);

console.log('setting error');
step.log(`User ${userEmail} is not allowed to push on repo ${action.repo}, ending`);

step.setError(
`Rejecting push as user ${action.user} ` +
`Your push has been blocked (${action.userEmail} ` +
`is not allowed to push on repo ` +
`${action.repo}`,
`${action.repo})`,
);
action.addStep(step);
return action;
}

step.log(`User ${user} is allowed to push on repo ${action.repo}`);
step.log(`User ${userEmail} is allowed to push on repo ${action.repo}`);
action.addStep(step);
return action;
};
Expand Down
Loading
Loading