5 use Illuminate\Support\Facades\Log;
10 * Many of the tests here are to check on tweaks made
11 * to maintain backwards compatibility.
13 class ConfigTest extends TestCase
15 public function test_filesystem_images_falls_back_to_storage_type_var()
17 $this->runWithEnv('STORAGE_TYPE', 'local_secure', function () {
18 $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', 's3', 'filesystems.images', 's3');
19 $this->checkEnvConfigResult('STORAGE_IMAGE_TYPE', null, 'filesystems.images', 'local_secure');
23 public function test_filesystem_attachments_falls_back_to_storage_type_var()
25 $this->runWithEnv('STORAGE_TYPE', 'local_secure', function () {
26 $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
27 $this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
31 public function test_app_url_blank_if_old_default_value()
33 $initUrl = 'https://example.com/docs';
34 $oldDefault = 'http://bookstack.dev';
35 $this->checkEnvConfigResult('APP_URL', $initUrl, 'app.url', $initUrl);
36 $this->checkEnvConfigResult('APP_URL', $oldDefault, 'app.url', '');
39 public function test_errorlog_plain_webserver_channel()
41 // We can't full test this due to it being targeted for the SAPI logging handler
42 // so we just overwrite that component so we can capture the error log output.
44 'logging.channels.errorlog_plain_webserver.handler_with' => [0],
47 $temp = tempnam(sys_get_temp_dir(), 'bs-test');
48 $original = ini_set('error_log', $temp);
50 Log::channel('errorlog_plain_webserver')->info('Aww, look, a cute puppy');
52 ini_set('error_log', $original);
54 $output = file_get_contents($temp);
55 $this->assertStringContainsString('Aww, look, a cute puppy', $output);
56 $this->assertStringNotContainsString('INFO', $output);
57 $this->assertStringNotContainsString('info', $output);
58 $this->assertStringNotContainsString('testing', $output);
61 public function test_session_cookie_uses_sub_path_from_app_url()
63 $this->checkEnvConfigResult('APP_URL', 'https://example.com', 'session.path', '/');
64 $this->checkEnvConfigResult('APP_URL', 'https://a.com/b', 'session.path', '/b');
65 $this->checkEnvConfigResult('APP_URL', 'https://a.com/b/d/e', 'session.path', '/b/d/e');
66 $this->checkEnvConfigResult('APP_URL', '', 'session.path', '/');
69 public function test_saml2_idp_authn_context_string_parsed_as_space_separated_array()
71 $this->checkEnvConfigResult(
72 'SAML2_IDP_AUTHNCONTEXT',
73 'urn:federation:authentication:windows urn:federation:authentication:linux',
74 'saml2.onelogin.security.requestedAuthnContext',
75 ['urn:federation:authentication:windows', 'urn:federation:authentication:linux']
79 public function test_dompdf_remote_fetching_controlled_by_allow_untrusted_server_fetching_false()
81 $this->checkEnvConfigResult('ALLOW_UNTRUSTED_SERVER_FETCHING', 'false', 'dompdf.options.enable_remote', false);
82 $this->checkEnvConfigResult('ALLOW_UNTRUSTED_SERVER_FETCHING', 'true', 'dompdf.options.enable_remote', true);
85 public function test_dompdf_paper_size_options_are_limited()
87 $this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'cat', 'dompdf.options.default_paper_size', 'a4');
88 $this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'letter', 'dompdf.options.default_paper_size', 'letter');
89 $this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'a4', 'dompdf.options.default_paper_size', 'a4');
92 public function test_snappy_paper_size_options_are_limited()
94 $this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'cat', 'snappy.pdf.options.page-size', 'A4');
95 $this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'letter', 'snappy.pdf.options.page-size', 'Letter');
96 $this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'a4', 'snappy.pdf.options.page-size', 'A4');
100 * Set an environment variable of the given name and value
101 * then check the given config key to see if it matches the given result.
102 * Providing a null $envVal clears the variable.
104 * @param mixed $expectedResult
106 protected function checkEnvConfigResult(string $envName, ?string $envVal, string $configKey, $expectedResult)
108 $this->runWithEnv($envName, $envVal, function () use ($configKey, $expectedResult) {
109 $this->assertEquals($expectedResult, config($configKey));