diff --git a/package-lock.json b/package-lock.json index 259b455f3..596cd2714 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,6 +53,7 @@ "react-router-dom": "6.30.1", "simple-git": "^3.28.0", "uuid": "^11.1.0", + "validator": "^13.15.15", "yargs": "^17.7.2" }, "bin": { @@ -73,6 +74,7 @@ "@types/node": "^22.17.0", "@types/react-dom": "^17.0.26", "@types/react-html-parser": "^2.0.7", + "@types/validator": "^13.15.2", "@types/yargs": "^17.0.33", "@typescript-eslint/eslint-plugin": "^8.38.0", "@typescript-eslint/parser": "^8.38.0", @@ -2627,6 +2629,13 @@ "@types/node": "*" } }, + "node_modules/@types/validator": { + "version": "13.15.2", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.15.2.tgz", + "integrity": "sha512-y7pa/oEJJ4iGYBxOpfAKn5b9+xuihvzDVnC/OSvlVnGxVg0pOqmjiMafiJ1KVNQEaPZf9HsEp5icEwGg8uIe5Q==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", @@ -12754,6 +12763,15 @@ "dev": true, "license": "MIT" }, + "node_modules/validator": { + "version": "13.15.15", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.15.15.tgz", + "integrity": "sha512-BgWVbCI72aIQy937xbawcs+hrVaN/CZ2UwutgaJ36hGqRrLNM+f5LUT/YPRbo8IV/ASeFzXszezV+y2+rq3l8A==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 48ba92b92..ddaeb190c 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "react-router-dom": "6.30.1", "simple-git": "^3.28.0", "uuid": "^11.1.0", + "validator": "^13.15.15", "yargs": "^17.7.2" }, "devDependencies": { @@ -96,6 +97,7 @@ "@types/node": "^22.17.0", "@types/react-dom": "^17.0.26", "@types/react-html-parser": "^2.0.7", + "@types/validator": "^13.15.2", "@types/yargs": "^17.0.33", "@typescript-eslint/eslint-plugin": "^8.38.0", "@typescript-eslint/parser": "^8.38.0", diff --git a/src/proxy/processors/push-action/checkAuthorEmails.ts b/src/proxy/processors/push-action/checkAuthorEmails.ts index 9462ed4eb..86c5ae027 100644 --- a/src/proxy/processors/push-action/checkAuthorEmails.ts +++ b/src/proxy/processors/push-action/checkAuthorEmails.ts @@ -1,30 +1,27 @@ import { Action, Step } from '../../actions'; import { getCommitConfig } from '../../../config'; import { Commit } from '../../actions/Action'; +import { isEmail } from 'validator'; const commitConfig = getCommitConfig(); const isEmailAllowed = (email: string): boolean => { - if (!email) { + if (!email || !isEmail(email)) { return false; } const [emailLocal, emailDomain] = email.split('@'); - if (!emailLocal || !emailDomain) { - return false; - } - if ( commitConfig.author.email.domain.allow && - !emailDomain.match(new RegExp(commitConfig.author.email.domain.allow, 'g')) + !new RegExp(commitConfig.author.email.domain.allow, 'g').test(emailDomain) ) { return false; } if ( commitConfig.author.email.local.block && - emailLocal.match(new RegExp(commitConfig.author.email.local.block, 'g')) + new RegExp(commitConfig.author.email.local.block, 'g').test(emailLocal) ) { return false; } diff --git a/test/processors/checkAuthorEmails.test.js b/test/processors/checkAuthorEmails.test.js index 4ef2e041e..ff54c828d 100644 --- a/test/processors/checkAuthorEmails.test.js +++ b/test/processors/checkAuthorEmails.test.js @@ -181,7 +181,7 @@ describe('checkAuthorEmails', () => { exec({}, action); }), { - numRuns: 100 + numRuns: 1000 } ); @@ -200,7 +200,7 @@ describe('checkAuthorEmails', () => { exec({}, action); }), { - numRuns: 100 + numRuns: 1000 } ); expect(action.step.error).to.be.undefined; @@ -215,7 +215,7 @@ describe('checkAuthorEmails', () => { exec({}, action); }), { - numRuns: 100 + numRuns: 1000 } ); @@ -232,7 +232,7 @@ describe('checkAuthorEmails', () => { exec({}, action); }), { - numRuns: 100 + numRuns: 1000 } ); expect(action.step.error).to.be.undefined; diff --git a/test/processors/checkCommitMessages.test.js b/test/processors/checkCommitMessages.test.js index d6d725172..89db0c508 100644 --- a/test/processors/checkCommitMessages.test.js +++ b/test/processors/checkCommitMessages.test.js @@ -164,7 +164,6 @@ describe('checkCommitMessages', () => { fc.integer(), fc.double(), fc.boolean(), - fc.object(), ), author: fc.string() }), @@ -193,7 +192,8 @@ describe('checkCommitMessages', () => { [{ message: null, author: 'me' }], [{ message: {}, author: 'me' }], [{ message: 'SeCrEt', author: 'me' }] - ] + ], + numRuns: 1000 } ); });