Skip to content

Commit 47ab4ac

Browse files
committed
fix: checkAuthorEmails validation errors and failing tests
1 parent 1aeb231 commit 47ab4ac

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
import { Action, Step } from '../../actions';
22
import { getCommitConfig } from '../../../config';
33
import { Commit } from '../../actions/Action';
4+
import { isEmail } from 'validator';
45

56
const commitConfig = getCommitConfig();
67

78
const isEmailAllowed = (email: string): boolean => {
8-
if (!email) {
9+
if (!email || !isEmail(email)) {
910
return false;
1011
}
1112

1213
const [emailLocal, emailDomain] = email.split('@');
1314

14-
if (!emailLocal || !emailDomain) {
15-
return false;
16-
}
17-
1815
if (
1916
commitConfig.author.email.domain.allow &&
20-
!emailDomain.match(new RegExp(commitConfig.author.email.domain.allow, 'g'))
17+
!new RegExp(commitConfig.author.email.domain.allow, 'g').test(emailDomain)
2118
) {
2219
return false;
2320
}
2421

2522
if (
2623
commitConfig.author.email.local.block &&
27-
emailLocal.match(new RegExp(commitConfig.author.email.local.block, 'g'))
24+
new RegExp(commitConfig.author.email.local.block, 'g').test(emailLocal)
2825
) {
2926
return false;
3027
}

test/processors/checkAuthorEmails.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ describe('checkAuthorEmails', () => {
181181
exec({}, action);
182182
}),
183183
{
184-
numRuns: 100
184+
numRuns: 1000
185185
}
186186
);
187187

@@ -200,7 +200,7 @@ describe('checkAuthorEmails', () => {
200200
exec({}, action);
201201
}),
202202
{
203-
numRuns: 100
203+
numRuns: 1000
204204
}
205205
);
206206
expect(action.step.error).to.be.undefined;
@@ -215,7 +215,7 @@ describe('checkAuthorEmails', () => {
215215
exec({}, action);
216216
}),
217217
{
218-
numRuns: 100
218+
numRuns: 1000
219219
}
220220
);
221221

@@ -232,7 +232,7 @@ describe('checkAuthorEmails', () => {
232232
exec({}, action);
233233
}),
234234
{
235-
numRuns: 100
235+
numRuns: 1000
236236
}
237237
);
238238
expect(action.step.error).to.be.undefined;

test/testPush.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ describe('auth', async () => {
9393
// set up a repo, user and push to test against
9494
await db.deleteRepo(TEST_REPO);
9595
await db.deleteUser(TEST_USERNAME_1);
96+
await db.deleteUser(TEST_USERNAME_2);
97+
9698
await db.createRepo({
9799
project: TEST_ORG,
98100
name: TEST_REPO,

0 commit comments

Comments
 (0)