Debian Codegraph @

extensions/SecureLinkFixer/tests/phpunit/HSTSPreloadLookupTest.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright (C) 2018 Kunal Mehta <[email protected]>
4 *
5 * This program 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 * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19 namespace MediaWiki\SecureLinkFixer\Test;
20
21 use MediaWiki\SecureLinkFixer\HSTSPreloadLookup;
22 use MediaWikiIntegrationTestCase;
23 use Wikimedia\TestingAccessWrapper;
24
25 /**
26 * @covers \MediaWiki\SecureLinkFixer\HSTSPreloadLookup
27 */
28 class HSTSPreloadLookupTest extends MediaWikiIntegrationTestCase {
29
30 /**
31 * @dataProvider provideIsPreloaded
32 */
33 public function testIsPreloaded( $host, $expected ) {
34 $lookup = new HSTSPreloadLookup( 'dummy' );
35 TestingAccessWrapper::newFromObject( $lookup )->domains = [
36 // TLD
37 'foobar' => 1,
38 'secure-example.org' => 1,
39 // includeSubdomains=false
40 'insecure-subdomains-example.org' => 0,
41 // Subdomain is secure, root domain isn't
42 'secure.insecure-example.org' => 1,
43 ];
44 $this->assertSame( $expected, $lookup->isPreloaded( $host ) );
45 }
46
47 public static function provideIsPreloaded() {
48 return [
49 [ 'example.foobar', true ],
50 [ 'secure-example.org', true ],
51 [ 'subdomain.secure-example.org', true ],
52 [ 'insecure-subdomains-example.org', true ],
53 [ 'subdomain.insecure-subdomains-example.org', false ],
54 [ 'secure.insecure-example.org', true ],
55 [ 'insecure-example.org', false ],
56 [ 'not-preloaded.org', false ],
57 [ 'pathological.case.that.is.not.preloaded.org', false ],
58 ];
59 }
60 }