function MailerDsnConfigValidationTest::testMailerTransportSMTPOptionsValidation
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ MailerDsnConfigValidationTest.php, line 304
Class
- MailerDsnConfigValidationTest
- Tests validation of mailer dsn config.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testMailerTransportSMTPOptionsValidation() : void {
$config = $this->config('system.mail');
$this->assertFalse($config->isNew());
$data = $config->get();
// Set scheme to smtps.
$data['mailer_dsn']['scheme'] = 'smtps';
// If the options contain an invalid peer_fingerprint, it should be an error.
$data['mailer_dsn']['options'] = [
'verify_peer' => FALSE,
'peer_fingerprint' => 'BE:F7:B9:CA:0F:6E:0F:29:9B:E9:B4:64:99:35:D6:27',
];
$violations = $this->configManager
->createFromNameAndData($config->getName(), $data)
->validate();
$this->assertCount(1, $violations);
$this->assertSame('mailer_dsn.options.peer_fingerprint', $violations[0]->getPropertyPath());
$this->assertSame('The peer_fingerprint option requires an md5, sha1 or sha256 certificate fingerprint in hex with all separators (colons) removed.', (string) $violations[0]->getMessage());
// If the options contain a valid peer_fingerprint, it should be accepted.
$data['mailer_dsn']['options'] = [
'verify_peer' => FALSE,
'peer_fingerprint' => 'BEF7B9CA0F6E0F299BE9B4649935D627',
];
$violations = $this->configManager
->createFromNameAndData($config->getName(), $data)
->validate();
$this->assertCount(0, $violations);
// If the options contain a valid peer_fingerprint, it should be accepted.
$data['mailer_dsn']['options'] = [
'verify_peer' => TRUE,
'peer_fingerprint' => '87abbc4d1c3f23146362c6a1168fb7e90a56569c4c97275c69c0630dc06e526d',
];
$violations = $this->configManager
->createFromNameAndData($config->getName(), $data)
->validate();
$this->assertCount(0, $violations);
// If the options contain a local_domain with a newline, it should be an error.
$data['mailer_dsn']['options'] = [
'local_domain' => "host\nwith\nnewline",
];
$violations = $this->configManager
->createFromNameAndData($config->getName(), $data)
->validate();
$this->assertCount(1, $violations);
$this->assertSame('mailer_dsn.options.local_domain', $violations[0]->getPropertyPath());
$this->assertSame('The local_domain is not allowed to span multiple lines or contain control characters.', (string) $violations[0]->getMessage());
// If the options contain a local_domain with unexpected characters, it should be an error.
$data['mailer_dsn']['options'] = [
'local_domain' => "host\rwith\tcontrol-chars",
];
$violations = $this->configManager
->createFromNameAndData($config->getName(), $data)
->validate();
$this->assertCount(1, $violations);
$this->assertSame('mailer_dsn.options.local_domain', $violations[0]->getPropertyPath());
$this->assertSame('The local_domain is not allowed to span multiple lines or contain control characters.', (string) $violations[0]->getMessage());
// If the options contain a valid local_domain, it should be accepted.
$data['mailer_dsn']['options'] = [
'local_domain' => 'www.example.com',
];
$violations = $this->configManager
->createFromNameAndData($config->getName(), $data)
->validate();
$this->assertCount(0, $violations);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.