| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
namespace MediaWiki\SecureLinkFixer\Test; |
| 20 |
|
| 21 |
use MediaWiki\SecureLinkFixer\HSTSPreloadLookup; |
| 22 |
use MediaWikiIntegrationTestCase; |
| 23 |
use Wikimedia\TestingAccessWrapper; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
class HSTSPreloadLookupTest extends MediaWikiIntegrationTestCase { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function testIsPreloaded( $host, $expected ) { |
| 34 |
$lookup = new HSTSPreloadLookup( 'dummy' ); |
| 35 |
TestingAccessWrapper::newFromObject( $lookup )->domains = [ |
| 36 |
|
| 37 |
'foobar' => 1, |
| 38 |
'secure-example.org' => 1, |
| 39 |
|
| 40 |
'insecure-subdomains-example.org' => 0, |
| 41 |
|
| 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 |
} |