diff --git a/lib/SimpleSAML/Utils/EMail.php b/lib/SimpleSAML/Utils/EMail.php index 5b236def82e6b44a7a8c7d178e3c3970471c4e34..ef2a965572471170bb67bb82d9976f74acf3d576 100644 --- a/lib/SimpleSAML/Utils/EMail.php +++ b/lib/SimpleSAML/Utils/EMail.php @@ -66,6 +66,7 @@ class EMail { $config = Configuration::getInstance(); $address = $config->getString('technicalcontact_email', 'na@example.org'); + $address = preg_replace('/^mailto:/i', '', $address); if ('na@example.org' === $address) { throw new \Exception('technicalcontact_email must be changed from the default value'); } diff --git a/tests/lib/SimpleSAML/Utils/EMailTestCase.php b/tests/lib/SimpleSAML/Utils/EMailTestCase.php index 122fef7b8f648ba3e9245d9d8dd674ce46d575c4..6e66c792a68ff6b268b13c9129eb8c139563b05c 100644 --- a/tests/lib/SimpleSAML/Utils/EMailTestCase.php +++ b/tests/lib/SimpleSAML/Utils/EMailTestCase.php @@ -130,4 +130,26 @@ class EMailTestCase extends ClearStateTestCase $this->expectException(\InvalidArgumentException::class); $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()); + } }