From cde59e40580aa51e58993420293fb1ce72b4fe1a Mon Sep 17 00:00:00 2001 From: Thijs Kinkhorst <thijs@kinkhorst.com> Date: Fri, 31 Jan 2020 13:56:28 +0000 Subject: [PATCH] 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. --- lib/SimpleSAML/Utils/EMail.php | 1 + tests/lib/SimpleSAML/Utils/EMailTestCase.php | 22 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/SimpleSAML/Utils/EMail.php b/lib/SimpleSAML/Utils/EMail.php index 5b236def8..ef2a96557 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 122fef7b8..6e66c792a 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()); + } } -- GitLab