Skip to content
Snippets Groups Projects
Commit e28342ae authored by Karolis Linkevičius's avatar Karolis Linkevičius Committed by Max Pogonowski
Browse files

Issue #3417829 by darvanen, k-l: Add support for localDisposableOnly and...

Issue #3417829 by darvanen, k-l: Add support for localDisposableOnly and localFreeOnly configuration
parent 82c29807
No related branches found
No related tags found
1 merge request!14Add support for LocalDisposableOnly and LocalFreeOnly configuration
Pipeline #142276 passed
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# With thanks to:
# * The GitLab Acceleration Initiative participants
# * DrupalSpoons
################
################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################
################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
# "ref" value can be:
# - Recommended (default) - `ref: $_GITLAB_TEMPLATES_REF` - The Drupal Association will update this value to the recommended tag for contrib.
# - Latest - `ref: main` - Get the latest additions and bug fixes as they are merged into the templates.
# - Minor or Major latests - `ref: 1.x-latest` or `ref: 1.0.x-latest` - Get the latest additions within a minor (mostly bugfixes) or major (bugs and new features).
# - Fixed tag - `ref: 1.0.1` - Set the value to a known tag. This will not get any updates.
# If you change the default value of ref, you should set the _CURL_TEMPLATES_REF variable in the variables section to be the same as set here.
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
################
# Pipeline configuration variables
#
# These are the variables provided to the Run Pipeline form that a user may want to override.
#
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
################
variables:
OPT_IN_TEST_NEXT_MINOR: '1'
OPT_IN_TEST_NEXT_MAJOR: '1'
# Temporarily disable failing analysis checks until they're working, see
# module issue queue for relevant work.
SKIP_CSPELL: '1'
SKIP_PHPCS: '1'
SKIP_PHPSTAN: '1'
name: 'Advanced Email Validation'
type: module
description: 'User account email validation using MX records and lists of free or disposable emails (configurable).'
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^9.3 || ^10 || ^11
package: User
configure: advanced_email_validation.settings
dependencies:
......
......@@ -17,6 +17,6 @@
"source": "http://cgit.drupalcode.org/advanced_email_validation"
},
"require": {
"stymiee/email-validator": "^1.0.1"
"stymiee/email-validator": "^1.1.4"
}
}
......@@ -17,3 +17,6 @@ domain_lists:
- ''
banned:
- ''
local_list_only:
disposable: false
free: false
......@@ -52,3 +52,11 @@ advanced_email_validation.settings:
type: sequence
sequence:
type: string
local_list_only:
type: mapping
label: Local list only
mapping:
disposable:
type: boolean
free:
type: boolean
......@@ -55,6 +55,8 @@ class AdvancedEmailValidator implements AdvancedEmailValidatorInterface {
'bannedList' => $domainLists[self::BANNED_DOMAIN],
'disposableList' => $domainLists[self::DISPOSABLE_DOMAIN],
'freeList' => $domainLists[self::FREE_DOMAIN],
'LocalDisposableOnly' => $moduleConfig->get('local_list_only.' . self::DISPOSABLE_DOMAIN),
'LocalFreeOnly' => $moduleConfig->get('local_list_only.' . self::FREE_DOMAIN),
];
$validatorConfig = !empty($configOverrides) ? $configOverrides : $defaultConfig;
......
......@@ -69,6 +69,15 @@ class SettingsForm extends ConfigFormBase {
];
}
if (array_key_exists('local_list_only', $check)) {
$form[$key][$key . '_local_list_only'] = [
'#type' => 'checkbox',
'#title' => $check['local_list_only']['title'],
'#description' => $check['local_list_only']['description'],
'#default_value' => $config->get('local_list_only.' . $key),
];
}
$weight++;
if (array_key_exists('rule_title', $check)) {
......@@ -123,6 +132,11 @@ class SettingsForm extends ConfigFormBase {
}
$config->set('domain_lists.' . $key, $domainList);
}
if (array_key_exists('local_list_only', $check)) {
$localList = (bool)$form_state->getValue($key . '_local_list_only');
$config->set('local_list_only.' . $key, $localList);
}
}
$config->save();
......
......@@ -48,6 +48,11 @@ class EmailValidatorHelper {
'title' => t('Additional disposable domains'),
'description' => $libraryIntro,
],
'local_list_only' => [
'title' => t('Use local domain list only'),
'description' => t('Disposable domain validation will be limited to
the domains you provide above.'),
],
],
AdvancedEmailValidator::FREE_DOMAIN => [
......@@ -58,6 +63,11 @@ class EmailValidatorHelper {
'title' => t('Additional free domains'),
'description' => $libraryIntro,
],
'local_list_only' => [
'title' => t('Use local domain list only'),
'description' => t('Free domain validation will be limited to
the domains you provide above.'),
],
],
AdvancedEmailValidator::BANNED_DOMAIN => [
......
......@@ -162,6 +162,12 @@ class EmailValidationTest extends KernelTestBase {
'mail' => $accountName . '@drupal.org',
]);
// User that should fail free email validation when using fetched lists.
$freeEmailAccount = User::create([
'name' => $accountName,
'mail' => $accountName . '@gmail.com',
]);
// Turn the test on and customise the list.
$config = $this->config('advanced_email_validation.settings');
$config->set('rules.free', 1)
......@@ -171,6 +177,11 @@ class EmailValidationTest extends KernelTestBase {
// Run validation.
$violations = $drupalEmailAccount->validate();
$this->assertEquals(1, $violations->count(), 'Custom free provider validation should fail with an email address on the custom free provider list.');
// Turn on local-only validation.
$config->set('local_list_only.free', TRUE)->save();
$violations = $freeEmailAccount->validate();
$this->assertEquals(0, $violations->count(), 'Free provider validation should pass with an email using a free email provider that is not in the custom list.');
}
/**
......@@ -222,6 +233,13 @@ class EmailValidationTest extends KernelTestBase {
'mail' => $accountName . '@drupal.org',
]);
// User that should fail disposable email validation when using fetched
// lists.
$disposableEmailAccount = User::create([
'name' => $accountName,
'mail' => $accountName . '@mailinator.com',
]);
// Turn the test on and customise the list.
$config = $this->config('advanced_email_validation.settings');
$config->set('rules.disposable', 1)
......@@ -231,6 +249,11 @@ class EmailValidationTest extends KernelTestBase {
// Run validation.
$violations = $drupalEmailAccount->validate();
$this->assertEquals(1, $violations->count(), 'Custom disposable provider validation should fail with an email using a provider on the custom disposable provider list.');
// Turn on local-only validation.
$config->set('local_list_only.disposable', TRUE)->save();
$violations = $disposableEmailAccount->validate();
$this->assertEquals(0, $violations->count(), 'Disposable provider validation should pass with an email using a disposable email provider that is not in the custom list.');
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment