<commit_before><?php

/**
 * Test: Spaze\ContentSecurityPolicy\Config.
 *
 * @testCase Spaze\ContentSecurityPolicy\ConfigTest
 * @author <NAME>
 * @package Spaze\ContentSecurityPolicy\Config
 */

use Spaze\ContentSecurityPolicy\Config;
use Tester\Assert;

require __DIR__ . '/../vendor/autoload.php';

class ConfigTest extends Tester\TestCase
{

	public function testGetDefaultKey()
	{
		$config = new Config();
		Assert::same(Config::DEFAULT_KEY, $config->getDefaultKey());
	}


	public function testGetHeaderDefaultKeys()
	{
		$config = new Config();
		$config->setPolicy([
			'DEFAULT_DEFAULT' => [
				'default-src' => "'none'",
				'img-src' => 'https://example.com',
			]
		]);
		Assert::same("default-src 'none'; img-src https://example.com", $config->getHeader('Foo', 'bar'));
	}


	public function testGetHeaderDefaultAction()
	{
		$config = new Config();
		$config->setPolicy([
			'foo_DEFAULT' => [
				'default-src' => "'none'",
				'img-src' => 'https://foo.example.com',
			]
		]);
		Assert::same("default-src 'none'; img-src https://foo.example.com", $config->getHeader('Foo', 'bar'));
	}


	public function testGetHeader()
	{
		$config = new Config();
		$config->setPolicy([
			'foo_bar' => [
				'default-src' => "'none'",
				'img-src' => 'https://foobar.example.com',
			]
		]);
		Assert::same("default-src 'none'; img-src https://foobar.example.com", $config->getHeader('Foo', 'bar'));
	}


	public function testGetHeaderLegacyBrowser()
	{
		$config = new Config();
		$config->setPolicy([
			'foo_bar' => [
				'default-src' => "'none'",
				'child-src' => 'https://example.com',
			]
		]);
		Assert::same("default-src 'none'; child-src https://example.com", $config->getHeader('Foo', 'bar'));
		$config->supportLegacyBrowsers();
		Assert::same("default-src 'none'; child-src https://example.com; frame-src https://example.com", $config->getHeader('Foo', 'bar'));
	}

}

$testCase = new ConfigTest();
$testCase->run();<commit_msg>Add tests for defaults and modules<commit_after><?php

/**
 * Test: Spaze\ContentSecurityPolicy\Config.
 *
 * @testCase Spaze\ContentSecurityPolicy\ConfigTest
 * @author <NAME>
 * @package Spaze\ContentSecurityPolicy\Config
 */

use Spaze\ContentSecurityPolicy\Config;
use Tester\Assert;

require __DIR__ . '/../vendor/autoload.php';

class ConfigTest extends Tester\TestCase
{

	public function testGetDefaultKey()
	{
		$config = new Config();
		Assert::same(Config::DEFAULT_KEY, $config->getDefaultKey());
	}


	public function testGetHeaderDefaultKeys()
	{
		$config = new Config();
		$config->setPolicy([
			'DEFAULT_DEFAULT' => [
				'default-src' => "'none'",
				'img-src' => 'https://example.com',
			]
		]);
		Assert::same("default-src 'none'; img-src https://example.com", $config->getHeader('Foo', 'bar'));
	}


	public function testGetHeaderDefaultAction()
	{
		$config = new Config();
		$config->setPolicy([
			'foo_DEFAULT' => [
				'default-src' => "'none'",
				'img-src' => 'https://foo.example.com',
			]
		]);
		Assert::same("default-src 'none'; img-src https://foo.example.com", $config->getHeader('Foo', 'bar'));
	}


	public function testGetHeader()
	{
		$config = new Config();
		$config->setPolicy([
			'foo_bar' => [
				'default-src' => "'none'",
				'img-src' => 'https://foobar.example.com',
			]
		]);
		Assert::same("default-src 'none'; img-src https://foobar.example.com", $config->getHeader('Foo', 'bar'));
	}


	public function testGetHeaderDefaultUppercase()
	{
		$config = new Config();
		$config->setPolicy([
			'foo_DEFAULT' => [
				'default-src' => "'none'",
				'img-src' => 'https://example.com',
			],
			'foo_default' => [
				'default-src' => "'none'",
				'img-src' => 'https://default.example.com',
			],
		]);
		Assert::same("default-src 'none'; img-src https://example.com", $config->getHeader('Foo', 'bar'));
		Assert::same("default-src 'none'; img-src https://default.example.com", $config->getHeader('Foo', 'default'));
	}


	public function testGetHeaderModule()
	{
		$config = new Config();
		$config->setPolicy([
			'foo_foo_bar' => [
				'default-src' => "'none'",
				'img-src' => 'https://foobar.example.com',
			]
		]);
		Assert::same("default-src 'none'; img-src https://foobar.example.com", $config->getHeader('Foo:Foo', 'bar'));
	}


	public function testGetHeaderDefaultModule()
	{
		$config = new Config();
		$config->setPolicy([
			'DEFAULT_DEFAULT_DEFAULT' => [
				'default-src' => "'none'",
				'img-src' => 'https://default.example.com',
			],
			'DEFAULT_foo_bar' => [
				'default-src' => "'none'",
				'img-src' => 'https://foobar.example.com',
			],
		]);
		Assert::same("default-src 'none'; img-src https://default.example.com", $config->getHeader('Waldo:Foo', 'bar'));
	}


	public function testGetHeaderLegacyBrowser()
	{
		$config = new Config();
		$config->setPolicy([
			'foo_bar' => [
				'default-src' => "'none'",
				'child-src' => 'https://example.com',
			]
		]);
		Assert::same("default-src 'none'; child-src https://example.com", $config->getHeader('Foo', 'bar'));
		$config->supportLegacyBrowsers();
		Assert::same("default-src 'none'; child-src https://example.com; frame-src https://example.com", $config->getHeader('Foo', 'bar'));
	}

}

$testCase = new ConfigTest();
$testCase->run();
{'fraction_non_alphanumeric': 0.2166507177033493, 'fraction_numerical': 0.0, 'mean_word_length': 4.020172910662824, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 75, 'https://': 29, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3355933', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1793, 'n_words': 300}