mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SecureLinkFixer
synced 2024-11-14 11:15:00 +00:00
0509d34225
* Turn HSTSPreloadLookup into a real service, per @todo * Convert Hooks into a non-static class, take lookup as an argument * Update tests for new calling style == Test plan == * CI/tests pass * Use Special:ExpandTemplates with a preloaded domain and localhost, observe preloaded link changes, localhost stays http Bug: T271027 Change-Id: I0196350e85c09eedfba4dbf1dab81f9a757b2a12
68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Copyright (C) 2018 Kunal Mehta <legoktm@debian.org>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
namespace MediaWiki\SecureLinkFixer;
|
|
|
|
use Benchmarker;
|
|
use MediaWiki\MediaWikiServices;
|
|
use const RUN_MAINTENANCE_IF_MAIN;
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
if ( $IP === false ) {
|
|
$IP = __DIR__ . '/../../..';
|
|
}
|
|
require_once "$IP/maintenance/includes/Benchmarker.php";
|
|
|
|
/**
|
|
* Benchmark the current HSTSPreloadLookup implementation
|
|
*
|
|
* @codeCoverageIgnore
|
|
*/
|
|
class BenchLookup extends Benchmarker {
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->addDescription( 'Benchmark for HSTSPreloadLookup' );
|
|
$this->requireExtension( 'SecureLinkFixer' );
|
|
}
|
|
|
|
public function execute() {
|
|
$lookup = MediaWikiServices::getInstance()->getService( 'HSTSPreloadLookup' );
|
|
$domains = [
|
|
// Need to traverse up one domain to find it
|
|
'foobar.dev',
|
|
// Directly in map
|
|
'wikipedia.org',
|
|
// Need to traverse up one domain to not find it
|
|
'not-preloaded.com',
|
|
// Need to traverse up 6 domains to not find it
|
|
'pathological.case.that.is.not.preloaded.org',
|
|
];
|
|
$benches = [];
|
|
foreach ( $domains as $domain ) {
|
|
$benches[] = [
|
|
'function' => [ $lookup, 'isPreloaded' ],
|
|
'args' => [ $domain ],
|
|
];
|
|
}
|
|
$this->bench( $benches );
|
|
}
|
|
}
|
|
|
|
$maintClass = BenchLookup::class;
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|