znt/module/common/test/model/checkip.php

38 lines
1.7 KiB
PHP
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env php
<?php
/**
title=测试 commonModel::checkIP();
timeout=0
cid=15656
- 步骤1通配符允许所有IP @1
- 步骤2精确匹配当前IP @1
- 步骤3多个IP白名单匹配 @1
- 步骤4IP范围匹配测试 @1
- 步骤5通配符IP段匹配 @1
- 步骤6CIDR格式匹配测试 @1
- 步骤7不匹配IP测试 @0
- 步骤8空字符串输入测试使用默认配置 @1
- 步骤9更复杂通配符测试 @1
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/model.class.php';
// 设置测试环境的IP地址模拟客户端IP
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$commonTest = new commonModelTest();
r($commonTest->checkIPTest('*')) && p() && e('1'); // 步骤1通配符允许所有IP
r($commonTest->checkIPTest('127.0.0.1')) && p() && e('1'); // 步骤2精确匹配当前IP
r($commonTest->checkIPTest('192.168.1.1,127.0.0.1,10.0.0.1')) && p() && e('1'); // 步骤3多个IP白名单匹配
r($commonTest->checkIPTest('127.0.0.1-127.0.0.255')) && p() && e('1'); // 步骤4IP范围匹配测试
r($commonTest->checkIPTest('127.0.0.*')) && p() && e('1'); // 步骤5通配符IP段匹配
r($commonTest->checkIPTest('127.0.0.0/24')) && p() && e('1'); // 步骤6CIDR格式匹配测试
r($commonTest->checkIPTest('192.168.1.1')) && p() && e('0'); // 步骤7不匹配IP测试
r($commonTest->checkIPTest('')) && p() && e('1'); // 步骤8空字符串输入测试使用默认配置
r($commonTest->checkIPTest('127.*')) && p() && e('1'); // 步骤9更复杂通配符测试