|
| 1 | +<?php |
| 2 | + |
| 3 | +/* This file is part of Jeedom. |
| 4 | +* |
| 5 | +* Jeedom is free software: you can redistribute it and/or modify |
| 6 | +* it under the terms of the GNU General Public License as published by |
| 7 | +* the Free Software Foundation, either version 3 of the License, or |
| 8 | +* (at your option) any later version. |
| 9 | +* |
| 10 | +* Jeedom is distributed in the hope that it will be useful, |
| 11 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +* GNU General Public License for more details. |
| 14 | +* |
| 15 | +* You should have received a copy of the GNU General Public License |
| 16 | +* along with Jeedom. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +*/ |
| 18 | + |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +/** |
| 22 | + * Regression test: `Access-Control-Allow-Credentials: true` combined with |
| 23 | + * `Access-Control-Allow-Origin: *` is rejected by all modern browsers, so the |
| 24 | + * credentials directive is dead code that misleads reviewers about the |
| 25 | + * intended cross-origin policy. It must not reappear in the shipped config. |
| 26 | + */ |
| 27 | +class corsHeadersTest extends TestCase { |
| 28 | + |
| 29 | + public function testHtaccessHasNoAllowCredentials() { |
| 30 | + $path = __DIR__ . '/../.htaccess'; |
| 31 | + $this->assertFileExists($path); |
| 32 | + $content = file_get_contents($path); |
| 33 | + $this->assertDoesNotMatchRegularExpression( |
| 34 | + '/Access-Control-Allow-Credentials/i', |
| 35 | + $content, |
| 36 | + '.htaccess must not emit Access-Control-Allow-Credentials with Allow-Origin: *' |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + public function testNginxDefaultHasNoAllowCredentials() { |
| 41 | + $path = __DIR__ . '/../install/nginx_default'; |
| 42 | + $this->assertFileExists($path); |
| 43 | + $content = file_get_contents($path); |
| 44 | + $this->assertDoesNotMatchRegularExpression( |
| 45 | + '/Access-Control-Allow-Credentials/i', |
| 46 | + $content, |
| 47 | + 'nginx_default must not emit Access-Control-Allow-Credentials with Allow-Origin: *' |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + public function testJeeApiHasNoAllowCredentials() { |
| 52 | + $path = __DIR__ . '/../core/api/jeeApi.php'; |
| 53 | + $this->assertFileExists($path); |
| 54 | + $content = file_get_contents($path); |
| 55 | + $this->assertDoesNotMatchRegularExpression( |
| 56 | + '/Access-Control-Allow-Credentials/i', |
| 57 | + $content, |
| 58 | + 'jeeApi.php must not emit Access-Control-Allow-Credentials with Allow-Origin: *' |
| 59 | + ); |
| 60 | + } |
| 61 | +} |
0 commit comments