修复国家设置,允许不设置任何国家,不做判断
This commit is contained in:
@@ -286,6 +286,10 @@ $cfDomainOut = shell_exec(escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($roo
|
||||
$cfDomainJson = json_decode((string) $cfDomainOut, true);
|
||||
reg_assert('Cloudflare 域名自动化 Mock 流转', ($cfDomainJson['ok'] ?? false) === true, (string) $cfDomainOut);
|
||||
|
||||
$countryAllowOut = shell_exec(escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($root . '/tools/verify_country_allowlist.php') . ' 2>/dev/null');
|
||||
$countryAllowJson = json_decode((string) $countryAllowOut, true);
|
||||
reg_assert('国家条件允许列表与 GeoIP 开关', ($countryAllowJson['ok'] ?? false) === true, (string) $countryAllowOut);
|
||||
|
||||
$geoOut = shell_exec(escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($root . '/tools/verify_geoip.php') . ' 2>/dev/null');
|
||||
$geoJson = json_decode((string) $geoOut, true);
|
||||
if (($geoJson['tests']['db_file_exists'] ?? false) === true) {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* 国家条件允许列表与 GeoIP 阶段开关回归
|
||||
*/
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
require_once $root . '/lib/Cloak/CountryAllowlist.php';
|
||||
|
||||
$tests = [];
|
||||
|
||||
$tests['empty_disabled'] = CountryAllowlist::isEnabled('') === false;
|
||||
$tests['whitespace_disabled'] = CountryAllowlist::isEnabled(' , ') === false;
|
||||
$tests['us_enabled'] = CountryAllowlist::isEnabled('US') === true;
|
||||
$tests['multi_enabled'] = CountryAllowlist::isEnabled('US,GB') === true;
|
||||
$tests['empty_allow_all'] = CountryAllowlist::isAllowed('CN', []) === true;
|
||||
|
||||
$tests['cn_comma'] = CountryAllowlist::formatForConfig('US,GB , CA') === 'US,GB,CA';
|
||||
$tests['semicolon'] = CountryAllowlist::formatForConfig('US;GB;CA') === 'US,GB,CA';
|
||||
$tests['cn_semicolon'] = CountryAllowlist::formatForConfig('US;GB;CN') === 'US,GB,CN';
|
||||
$tests['dunhao'] = CountryAllowlist::formatForConfig('US、GB、CA') === 'US,GB,CA';
|
||||
$tests['extra_spaces'] = CountryAllowlist::formatForConfig(' US , GB , CA ') === 'US,GB,CA';
|
||||
$tests['fullwidth_space'] = CountryAllowlist::formatForConfig("US\u{3000},\u{3000}GB") === 'US,GB';
|
||||
$tests['mixed_separators'] = CountryAllowlist::formatForConfig('US,GB;CN、AU') === 'US,GB,CN,AU';
|
||||
$tests['duplicate_codes'] = CountryAllowlist::formatForConfig('US,us, US ,GB') === 'US,GB';
|
||||
$tests['trailing_comma'] = CountryAllowlist::formatForConfig('US,GB,') === 'US,GB';
|
||||
$tests['lowercase'] = CountryAllowlist::formatForConfig('us,gb,ca') === 'US,GB,CA';
|
||||
$tests['mixed_case'] = CountryAllowlist::formatForConfig('Us , gB ; cN') === 'US,GB,CN';
|
||||
$tests['is_allowed_lower_visitor'] = CountryAllowlist::isAllowed('us', CountryAllowlist::parse('US,GB')) === true;
|
||||
$tests['resolved_config'] = CountryAllowlist::formatForConfig('us,gb') === CountryAllowlist::resolvedConfig('us,gb');
|
||||
|
||||
$stage = file_get_contents($root . '/lib/Cloak/Pipeline/stages/check_country_geoip.inc.php');
|
||||
$tests['stage_skips_when_disabled'] = strpos($stage, 'CountryAllowlist::isEnabled()') !== false;
|
||||
|
||||
$pipeline = file_get_contents($root . '/lib/Cloak/Pipeline/CheckPipeline.php');
|
||||
$tests['pipeline_conditional_geo'] = strpos($pipeline, 'CountryAllowlist::isEnabled()') !== false;
|
||||
|
||||
$ok = !in_array(false, $tests, true);
|
||||
echo json_encode(['ok' => $ok, 'tests' => $tests], JSON_UNESCAPED_UNICODE) . "\n";
|
||||
exit($ok ? 0 : 1);
|
||||
@@ -56,9 +56,16 @@ if ($tests['resolver_available']) {
|
||||
$tests['normalize_name'] = CountryCodeNormalizer::toAlpha2('United States') === 'US';
|
||||
$tests['allowlist_name'] = CountryAllowlist::isAllowed('United Kingdom', CountryAllowlist::parse('GB,US'));
|
||||
$tests['allowlist_fullwidth_comma'] = CountryAllowlist::isAllowed('BR', CountryAllowlist::parse('BR,CN'));
|
||||
$tests['allowlist_semicolon'] = CountryAllowlist::isAllowed('GB', CountryAllowlist::parse('US;GB;CA'));
|
||||
$tests['allowlist_country_name'] = CountryAllowlist::isAllowed('BR', CountryAllowlist::parse('Brazil,China'));
|
||||
if (!$tests['normalize_iso2'] || !$tests['normalize_name'] || !$tests['allowlist_name']
|
||||
|| !$tests['allowlist_fullwidth_comma'] || !$tests['allowlist_country_name']) {
|
||||
|| !$tests['allowlist_fullwidth_comma'] || !$tests['allowlist_semicolon'] || !$tests['allowlist_country_name']) {
|
||||
$ok = false;
|
||||
}
|
||||
|
||||
$tests['is_enabled_empty'] = CountryAllowlist::isEnabled('') === false;
|
||||
$tests['is_enabled_us'] = CountryAllowlist::isEnabled('US,GB') === true;
|
||||
if (!$tests['is_enabled_empty'] || !$tests['is_enabled_us']) {
|
||||
$ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user