From c42f5bc5f666290b99a1662b9048d3163bee0be9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Oct 2021 13:26:46 +0200 Subject: Add an OCP for trusted domain helper Signed-off-by: Joas Schilling --- tests/lib/Security/TrustedDomainHelperTest.php | 33 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/lib/Security/TrustedDomainHelperTest.php b/tests/lib/Security/TrustedDomainHelperTest.php index aedc4cb6a17..3fedf8964c5 100644 --- a/tests/lib/Security/TrustedDomainHelperTest.php +++ b/tests/lib/Security/TrustedDomainHelperTest.php @@ -27,6 +27,23 @@ class TrustedDomainHelperTest extends \Test\TestCase { $this->config = $this->getMockBuilder(IConfig::class)->getMock(); } + /** + * @dataProvider trustedDomainDataProvider + * @param string $trustedDomains + * @param string $testDomain + * @param bool $result + */ + public function testIsTrustedUrl($trustedDomains, $testDomain, $result) { + $this->config->method('getSystemValue') + ->willReturnMap([ + ['overwritehost', '', ''], + ['trusted_domains', [], $trustedDomains], + ]); + + $trustedDomainHelper = new TrustedDomainHelper($this->config); + $this->assertEquals($result, $trustedDomainHelper->isTrustedUrl('https://' . $testDomain . '/index.php/something')); + } + /** * @dataProvider trustedDomainDataProvider * @param string $trustedDomains @@ -34,14 +51,11 @@ class TrustedDomainHelperTest extends \Test\TestCase { * @param bool $result */ public function testIsTrustedDomain($trustedDomains, $testDomain, $result) { - $this->config->expects($this->at(0)) - ->method('getSystemValue') - ->with('overwritehost') - ->willReturn(''); - $this->config->expects($this->at(1)) - ->method('getSystemValue') - ->with('trusted_domains') - ->willReturn($trustedDomains); + $this->config->method('getSystemValue') + ->willReturnMap([ + ['overwritehost', '', ''], + ['trusted_domains', [], $trustedDomains], + ]); $trustedDomainHelper = new TrustedDomainHelper($this->config); $this->assertEquals($result, $trustedDomainHelper->isTrustedDomain($testDomain)); @@ -122,8 +136,7 @@ class TrustedDomainHelperTest extends \Test\TestCase { } public function testIsTrustedDomainOverwriteHost() { - $this->config->expects($this->at(0)) - ->method('getSystemValue') + $this->config->method('getSystemValue') ->with('overwritehost') ->willReturn('myproxyhost'); -- cgit v1.2.3