Skip to content
Snippets Groups Projects
Commit cde59e40 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst
Browse files

Remove any mailto: prefixes when set in technicalcontact email config.

People might do this in the past to get correct metadata (thereby
breaking other email related functions). But our metadata generator
will now take care of this, so we can just ignore any mailto: prefix.
parent e7f2f5f6
No related branches found
No related tags found
No related merge requests found
...@@ -66,6 +66,7 @@ class EMail ...@@ -66,6 +66,7 @@ class EMail
{ {
$config = Configuration::getInstance(); $config = Configuration::getInstance();
$address = $config->getString('technicalcontact_email', 'na@example.org'); $address = $config->getString('technicalcontact_email', 'na@example.org');
$address = preg_replace('/^mailto:/i', '', $address);
if ('na@example.org' === $address) { if ('na@example.org' === $address) {
throw new \Exception('technicalcontact_email must be changed from the default value'); throw new \Exception('technicalcontact_email must be changed from the default value');
} }
......
...@@ -130,4 +130,26 @@ class EMailTestCase extends ClearStateTestCase ...@@ -130,4 +130,26 @@ class EMailTestCase extends ClearStateTestCase
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
$email->setTransportMethod('smtp'); $email->setTransportMethod('smtp');
} }
/**
* Test setting configuration.
*
* @return void
*/
public function testGetDefaultMailAddress()
{
Configuration::loadFromArray([
'technicalcontact_email' => 'gamaarna@example.org',
], '[ARRAY]', 'simplesaml');
$mail = new EMail('test', null, 'phpunit@simplesamlphp.org');
$this->assertEquals('gamaarna@example.org', $mail->getDefaultMailAddress());
Configuration::loadFromArray([
'technicalcontact_email' => 'mailto:gamaarna@example.org',
], '[ARRAY]', 'simplesaml');
$mail = new EMail('test', null, 'phpunit@simplesamlphp.org');
$this->assertEquals('gamaarna@example.org', $mail->getDefaultMailAddress());
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment