/**
  * @dataProvider trustedDomainDataProvider
  * @param string $trustedDomains
  * @param string $testDomain
  * @param bool $result
  */
 public function testIsTrustedDomain($trustedDomains, $testDomain, $result)
 {
     $this->config->expects($this->once())->method('getSystemValue')->with('trusted_domains')->will($this->returnValue($trustedDomains));
     $trustedDomainHelper = new TrustedDomainHelper($this->config);
     $this->assertEquals($result, $trustedDomainHelper->isTrustedDomain($testDomain));
 }
Example #2
0
	/**
	 * Returns the server host from the headers, or the first configured
	 * trusted domain if the host isn't in the trusted list
	 * @return string Server host
	 */
	public function getServerHost() {
		// overwritehost is always trusted
		$host = $this->getOverwriteHost();
		if ($host !== null) {
			return $host;
		}

		// get the host from the headers
		$host = $this->getInsecureServerHost();

		// Verify that the host is a trusted domain if the trusted domains
		// are defined
		// If no trusted domain is provided the first trusted domain is returned
		$trustedDomainHelper = new TrustedDomainHelper($this->config);
		if ($trustedDomainHelper->isTrustedDomain($host)) {
			return $host;
		} else {
			$trustedList = $this->config->getSystemValue('trusted_domains', []);
			if(!empty($trustedList)) {
				return $trustedList[0];
			} else {
				return '';
			}
		}
	}
Example #3
0
 /**
  * Returns the server host from the headers, or the first configured
  * trusted domain if the host isn't in the trusted list
  * @return string Server host
  */
 public function getServerHost()
 {
     // FIXME: Ugly workaround that we need to get rid of
     if (\OC::$CLI && defined('PHPUNIT_RUN')) {
         return 'localhost';
     }
     // overwritehost is always trusted
     $host = $this->getOverwriteHost();
     if ($host !== null) {
         return $host;
     }
     // get the host from the headers
     $host = $this->getInsecureServerHost();
     // Verify that the host is a trusted domain if the trusted domains
     // are defined
     // If no trusted domain is provided the first trusted domain is returned
     $trustedDomainHelper = new TrustedDomainHelper($this->config);
     if ($trustedDomainHelper->isTrustedDomain($host)) {
         return $host;
     } else {
         $trustedList = $this->config->getSystemValue('trusted_domains', []);
         return $trustedList[0];
     }
 }