Skip to content

Commit e5c89a9

Browse files
committed
test: fixing test failure post merging main
1 parent 754bb3b commit e5c89a9

File tree

8 files changed

+38
-37
lines changed

8 files changed

+38
-37
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"source.fixAll.eslint": "explicit"
99
},
1010
"editor.defaultFormatter": "esbenp.prettier-vscode",
11-
"editor.formatOnSave": true
11+
"editor.formatOnSave": true,
12+
"cSpell.words": ["Deltafied"]
1213
}

src/proxy/processors/push-action/checkUserPushPermission.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,30 @@ import { trimTrailingDotGit } from '../../../db/helper';
55
// Execute if the repo is approved
66
const exec = async (req: any, action: Action): Promise<Action> => {
77
const step = new Step('checkUserPushPermission');
8-
const user = action.user;
8+
const userEmail = action.userEmail;
99

10-
if (!user) {
11-
console.log('Action has no user set. This may be due to a fast-forward ref update. Deferring to getMissingData action.');
10+
if (!userEmail) {
11+
console.log(
12+
'Action has no userEmail set. This may be due to a fast-forward ref update. Deferring to getMissingData action.',
13+
);
1214
return action;
1315
}
1416

15-
return await validateUser(user, action, step);
17+
return await validateUser(userEmail, action, step);
1618
};
1719

1820
/**
1921
* Helper that validates the user's push permission.
2022
* This can be used by other actions that need it. For example, when the user is missing from the commit data,
2123
* validation is deferred to getMissingData, but the logic is the same.
22-
* @param {string} user The user to validate
24+
* @param {string} userEmail The user email to validate
2325
* @param {Action} action The action object
2426
* @param {Step} step The step object
2527
* @return {Promise<Action>} The action object
2628
*/
27-
const validateUser = async (user: string, action: Action, step: Step): Promise<Action> => {
29+
const validateUser = async (userEmail: string, action: Action, step: Step): Promise<Action> => {
2830
const repoSplit = trimTrailingDotGit(action.repo.toLowerCase()).split('/');
31+
2932
// we expect there to be exactly one / separating org/repoName
3033
if (repoSplit.length != 2) {
3134
step.setError('Server-side issue extracting repoName');
@@ -36,13 +39,8 @@ const validateUser = async (user: string, action: Action, step: Step): Promise<A
3639
const repoName = repoSplit[1];
3740
let isUserAllowed = false;
3841

39-
// n.b. action.user will be set to whatever the user had set in their user.name config in their git client.
40-
// it is not necessarily the GitHub username. GitHub looks users by email address as should we
41-
const userEmail = action.userEmail;
42-
let username = 'unknown';
43-
4442
// Find the user associated with this email address
45-
const list = await getUsers({ email: action.userEmail });
43+
const list = await getUsers({ email: userEmail });
4644

4745
if (list.length > 1) {
4846
console.error(`Multiple users found with email address ${userEmail}, ending`);
@@ -59,18 +57,15 @@ const validateUser = async (user: string, action: Action, step: Step): Promise<A
5957
} else if (list.length == 0) {
6058
console.error(`No user with email address ${userEmail} found`);
6159
} else {
62-
username = list[0].username;
63-
isUserAllowed = await isUserPushAllowed(repoName, username);
60+
isUserAllowed = await isUserPushAllowed(repoName, list[0].username);
6461
}
6562

66-
console.log(`User ${username} <${userEmail}> permission on Repo ${repoName} : ${isUserAllowed}`);
63+
console.log(`User ${userEmail} permission on Repo ${repoName} : ${isUserAllowed}`);
6764

6865
if (!isUserAllowed) {
6966
console.log('User not allowed to Push');
7067
step.error = true;
71-
step.log(
72-
`User ${username} <${userEmail}> is not allowed to push on repo ${action.repo}, ending`,
73-
);
68+
step.log(`User ${userEmail} is not allowed to push on repo ${action.repo}, ending`);
7469

7570
step.setError(
7671
`Your push has been blocked (${action.userEmail} ` +
@@ -81,7 +76,7 @@ const validateUser = async (user: string, action: Action, step: Step): Promise<A
8176
return action;
8277
}
8378

84-
step.log(`User ${username} <${userEmail}> is allowed to push on repo ${action.repo}`);
79+
step.log(`User ${userEmail} is allowed to push on repo ${action.repo}`);
8580
action.addStep(step);
8681
return action;
8782
};

src/proxy/processors/types.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,34 @@ export type CommitContent = {
1717
deflatedSize: number;
1818
objectRef: any;
1919
content: string;
20-
}
20+
};
2121

2222
export type PersonLine = {
2323
name: string;
2424
email: string;
2525
timestamp: string;
26-
}
26+
};
2727

2828
export type CommitHeader = {
2929
tree: string;
3030
parents: string[];
3131
author: PersonLine;
3232
committer: PersonLine;
33-
}
33+
};
3434

3535
export type CommitData = {
3636
tree: string;
3737
parent: string;
3838
author: string;
3939
committer: string;
4040
authorEmail: string;
41+
committerEmail: string;
4142
commitTimestamp: string;
4243
message: string;
43-
}
44+
};
4445

4546
export type PackMeta = {
4647
sig: string;
4748
version: number;
4849
entries: number;
49-
}
50+
};

src/ui/utils.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66
export const getCookie = (name: string): string | null => {
77
if (!document.cookie) return null;
8-
8+
99
const cookies = document.cookie
1010
.split(';')
1111
.map((c) => c.trim())
1212
.filter((c) => c.startsWith(name + '='));
13-
13+
1414
if (!cookies.length) return null;
15-
15+
1616
return decodeURIComponent(cookies[0].split('=')[1]);
17-
};
17+
};

test/processors/checkUserPushPermission.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ describe('checkUserPushPermission', () => {
5959
expect(result.steps).to.have.lengthOf(1);
6060
expect(result.steps[0].error).to.be.false;
6161
expect(stepSpy.lastCall.args[0]).to.equal(
62-
'User db-user <db-user@test.com> is allowed to push on repo test/repo.git',
62+
'User [email protected] is allowed to push on repo test/repo.git',
6363
);
6464
expect(logStub.lastCall.args[0]).to.equal(
65-
'User db-user <db-user@test.com> permission on Repo repo : true',
65+
'User [email protected] permission on Repo repo : true',
6666
);
6767
});
6868

test/processors/getDiff.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ describe('getDiff', () => {
7373

7474
const result = await exec({}, action);
7575
expect(result.steps[0].error).to.be.true;
76-
expect(result.steps[0].errorMessage).to.contain('Your push has been blocked because no commit data was found');
76+
expect(result.steps[0].errorMessage).to.contain(
77+
'Your push has been blocked because no commit data was found',
78+
);
7779
});
7880

7981
it('should throw an error if no commit data is provided', async () => {
@@ -86,7 +88,9 @@ describe('getDiff', () => {
8688

8789
const result = await exec({}, action);
8890
expect(result.steps[0].error).to.be.true;
89-
expect(result.steps[0].errorMessage).to.contain('Your push has been blocked because no commit data was found');
91+
expect(result.steps[0].errorMessage).to.contain(
92+
'Your push has been blocked because no commit data was found',
93+
);
9094
});
9195

9296
it('should handle empty commit hash in commitFrom', async () => {

test/testCheckUserPushPermission.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ describe('CheckUserPushPermissions...', async () => {
1818
before(async function () {
1919
await db.deleteRepo(TEST_REPO);
2020
await db.deleteUser(TEST_USERNAME_1);
21-
21+
await db.deleteUser(TEST_USERNAME_2);
2222
await db.createRepo({
2323
project: TEST_ORG,
2424
name: TEST_REPO,
2525
url: TEST_URL,
2626
});
2727
await db.createUser(TEST_USERNAME_1, 'abc', TEST_EMAIL_1, TEST_USERNAME_1, false);
2828
await db.addUserCanPush(TEST_REPO, TEST_USERNAME_1);
29-
3029
await db.createUser(TEST_USERNAME_2, 'abc', TEST_EMAIL_2, TEST_USERNAME_2, false);
3130
});
3231

test/testParsePush.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('parsePackFile', () => {
110110
const step = action.steps[0];
111111
expect(step.stepName).to.equal('parsePackFile');
112112
expect(step.error).to.be.true;
113-
expect(step.errorMessage).to.include('No data received');
113+
expect(step.errorMessage).to.include('No body found in request');
114114
});
115115

116116
it('should add error step if req.body is empty', async () => {
@@ -121,7 +121,7 @@ describe('parsePackFile', () => {
121121
const step = action.steps[0];
122122
expect(step.stepName).to.equal('parsePackFile');
123123
expect(step.error).to.be.true;
124-
expect(step.errorMessage).to.include('No data received');
124+
expect(step.errorMessage).to.include('No body found in request');
125125
});
126126

127127
it('should add error step if no ref updates found', async () => {
@@ -536,6 +536,7 @@ describe('parsePackFile', () => {
536536
parent: '456',
537537
author: 'Au Thor',
538538
committer: 'Com Itter',
539+
committerEmail: '[email protected]',
539540
commitTimestamp: '222',
540541
message: 'Commit message here',
541542
authorEmail: '[email protected]',

0 commit comments

Comments
 (0)