Skip to content

Commit e8d1fd2

Browse files
committed
test: fix test failures caused by conflicts with main
1 parent 3efe9fe commit e8d1fd2

File tree

4 files changed

+55
-38
lines changed

4 files changed

+55
-38
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ const exec = async (req: any, action: Action): Promise<Action> => {
1717
const list = await getUsers({ email: action.userEmail });
1818

1919
if (list.length > 1) {
20-
console.warn(`Multiple users found with email address ${userEmail}, using the first only`);
20+
console.error(`Multiple users found with email address ${userEmail}, ending`);
21+
step.error = true;
22+
step.log(
23+
`Multiple Users have email <${userEmail}> so we cannot uniquely identify the user, ending`,
24+
);
25+
26+
step.setError(
27+
`Your push has been blocked (there are multiple users with email ${action.userEmail})`,
28+
);
29+
action.addStep(step);
30+
return action;
2131
} else if (list.length == 0) {
2232
console.error(`No user with email address ${userEmail} found`);
2333
} else {
@@ -34,8 +44,6 @@ const exec = async (req: any, action: Action): Promise<Action> => {
3444
`User ${username} <${userEmail}> is not allowed to push on repo ${action.repo}, ending`,
3545
);
3646

37-
console.log('setting error');
38-
3947
step.setError(
4048
`Your push has been blocked (${action.userEmail} ` +
4149
`is not allowed to push on repo ` +

test/ConfigLoader.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ describe('ConfigLoader', () => {
3838
});
3939
});
4040

41+
after(() => {
42+
// restore default config
43+
});
44+
4145
describe('loadFromFile', () => {
4246
it('should load configuration from file', async () => {
4347
const testConfig = {
@@ -251,7 +255,6 @@ describe('ConfigLoader', () => {
251255
configLoader = new ConfigLoader(mockConfig);
252256
configLoader.reloadTimer = setInterval(() => {}, 1000);
253257
await configLoader.start();
254-
255258
expect(configLoader.reloadTimer).to.be.null;
256259
});
257260

@@ -297,7 +300,6 @@ describe('ConfigLoader', () => {
297300
configLoader = new ConfigLoader(mockConfig);
298301
configLoader.reloadTimer = setInterval(() => {}, 1000);
299302
expect(configLoader.reloadTimer).to.not.be.null;
300-
301303
await configLoader.stop();
302304
expect(configLoader.reloadTimer).to.be.null;
303305
});

test/processors/checkUserPushPermission.test.js

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ describe('checkUserPushPermission', () => {
1818
getUsersStub = sinon.stub();
1919
isUserPushAllowedStub = sinon.stub();
2020

21-
const checkUserPushPermission = proxyquire('../../src/proxy/processors/push-action/checkUserPushPermission', {
22-
'../../../db': {
23-
getUsers: getUsersStub,
24-
isUserPushAllowed: isUserPushAllowedStub
25-
}
26-
});
21+
const checkUserPushPermission = proxyquire(
22+
'../../src/proxy/processors/push-action/checkUserPushPermission',
23+
{
24+
'../../../db': {
25+
getUsers: getUsersStub,
26+
isUserPushAllowed: isUserPushAllowedStub,
27+
},
28+
},
29+
);
2730

2831
exec = checkUserPushPermission.exec;
2932
});
@@ -39,40 +42,43 @@ describe('checkUserPushPermission', () => {
3942

4043
beforeEach(() => {
4144
req = {};
42-
action = new Action(
43-
'1234567890',
44-
'push',
45-
'POST',
46-
1234567890,
47-
'test/repo.git'
48-
);
45+
action = new Action('1234567890', 'push', 'POST', 1234567890, 'test/repo.git');
4946
action.user = 'git-user';
47+
action.userEmail = '[email protected]';
5048
stepSpy = sinon.spy(Step.prototype, 'log');
5149
});
5250

5351
it('should allow push when user has permission', async () => {
54-
getUsersStub.resolves([{ username: 'db-user', gitAccount: 'git-user' }]);
52+
getUsersStub.resolves([
53+
{ username: 'db-user', email: '[email protected]', gitAccount: 'git-user' },
54+
]);
5555
isUserPushAllowedStub.resolves(true);
5656

5757
const result = await exec(req, action);
5858

5959
expect(result.steps).to.have.lengthOf(1);
6060
expect(result.steps[0].error).to.be.false;
61-
expect(stepSpy.calledWith('User db-user is allowed to push on repo test/repo.git')).to.be.true;
62-
expect(logStub.calledWith('User db-user permission on Repo repo : true')).to.be.true;
61+
expect(stepSpy.lastCall.args[0]).to.equal(
62+
'User db-user <[email protected]> is allowed to push on repo test/repo.git',
63+
);
64+
expect(logStub.lastCall.args[0]).to.equal(
65+
'User db-user <[email protected]> permission on Repo repo : true',
66+
);
6367
});
6468

6569
it('should reject push when user has no permission', async () => {
66-
getUsersStub.resolves([{ username: 'db-user', gitAccount: 'git-user' }]);
70+
getUsersStub.resolves([
71+
{ username: 'db-user', email: '[email protected]', gitAccount: 'git-user' },
72+
]);
6773
isUserPushAllowedStub.resolves(false);
6874

6975
const result = await exec(req, action);
7076

7177
expect(result.steps).to.have.lengthOf(1);
7278
expect(result.steps[0].error).to.be.true;
73-
expect(stepSpy.calledWith('User db-user is not allowed to push on repo test/repo.git, ending')).to.be.true;
74-
expect(result.steps[0].errorMessage).to.include('Rejecting push as user git-user');
75-
expect(logStub.calledWith('User not allowed to Push')).to.be.true;
79+
expect(result.steps[0].errorMessage).to.equal(
80+
'Your push has been blocked ([email protected] is not allowed to push on repo test/repo.git)',
81+
);
7682
});
7783

7884
it('should reject push when no user found for git account', async () => {
@@ -82,21 +88,22 @@ describe('checkUserPushPermission', () => {
8288

8389
expect(result.steps).to.have.lengthOf(1);
8490
expect(result.steps[0].error).to.be.true;
85-
expect(stepSpy.calledWith('User git-user is not allowed to push on repo test/repo.git, ending')).to.be.true;
86-
expect(result.steps[0].errorMessage).to.include('Rejecting push as user git-user');
91+
expect(result.steps[0].errorMessage).to.include('Your push has been blocked');
8792
});
8893

89-
it('should handle multiple users for git account by rejecting push', async () => {
94+
it('should handle multiple users for git account by rejecting the push', async () => {
9095
getUsersStub.resolves([
91-
{ username: 'user1', gitAccount: 'git-user' },
92-
{ username: 'user2', gitAccount: 'git-user' }
96+
{ username: 'user1', email: '[email protected]', gitAccount: 'git-user' },
97+
{ username: 'user2', email: '[email protected]', gitAccount: 'git-user' },
9398
]);
9499

95100
const result = await exec(req, action);
96101

97102
expect(result.steps).to.have.lengthOf(1);
98103
expect(result.steps[0].error).to.be.true;
99-
expect(logStub.calledWith('Users for this git account: [{"username":"user1","gitAccount":"git-user"},{"username":"user2","gitAccount":"git-user"}]')).to.be.true;
104+
expect(result.steps[0].errorMessage).to.equal(
105+
'Your push has been blocked (there are multiple users with email [email protected])',
106+
);
100107
});
101108
});
102109
});

test/testDb.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ describe('Database clients', async () => {
8686
expect(cleanRepos).to.deep.include(TEST_REPO);
8787
});
8888

89-
it('should be able to delete a repo', async function () {
90-
await db.deleteRepo(TEST_REPO.name);
91-
const repos = await db.getRepos();
92-
const cleanRepos = cleanResponseData(TEST_REPO, repos);
93-
expect(cleanRepos).to.not.deep.include(TEST_REPO);
94-
});
95-
9689
it('should be able to filter repos', async function () {
9790
// uppercase the filter value to confirm db client is lowercasing inputs
9891
const repos = await db.getRepos({ name: TEST_REPO.name.toUpperCase() });
@@ -116,6 +109,13 @@ describe('Database clients', async () => {
116109
expect(cleanRepo).to.eql(TEST_REPO);
117110
});
118111

112+
it('should be able to delete a repo', async function () {
113+
await db.deleteRepo(TEST_REPO.name);
114+
const repos = await db.getRepos();
115+
const cleanRepos = cleanResponseData(TEST_REPO, repos);
116+
expect(cleanRepos).to.not.deep.include(TEST_REPO);
117+
});
118+
119119
it('should NOT be able to create a repo with blank project, name or url', async function () {
120120
// test with a null value
121121
let threwError = false;

0 commit comments

Comments
 (0)