Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
68a5c1fb
Commit
68a5c1fb
authored
Feb 25, 2016
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit tests: add IP functions, refactor test variables
parent
af8f50ad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
35 deletions
+54
-35
AppLimitsTest.php
qa-tests/AppLimitsTest.php
+54
-35
No files found.
qa-tests/AppLimitsTest.php
View file @
68a5c1fb
...
...
@@ -3,61 +3,80 @@ require_once QA_INCLUDE_DIR.'app/limits.php';
class
AppLimitsTest
extends
PHPUnit_Framework_TestCase
{
private
$ipv4_wildcard1
=
'88.77.66.*'
;
private
$ipv4_wildcard2
=
'88.77.55.*'
;
private
$ipv4_wildcard3
=
'88.77.*.*'
;
private
$ipv6
=
'fe80:1:2:3:a:bad:1dea:dad'
;
private
$ipv6_compact
=
'::ffff:7f00:0001'
;
private
$ipv6_expanded
=
'0:0:0:0:0:ffff:7f00:0001'
;
private
$ipv6_wildcard1
=
'::ffff:7f00:*'
;
private
$ipv6_wildcard2
=
'::ffff:7e99:*'
;
private
$ipv6_wildcard3
=
'::ffff:*:*'
;
/**
* Test IP matching function.
* Test IP matching function
with IPv4
.
*/
public
function
test__qa_block_ip_match
()
public
function
test__qa_block_ip_match
__ipv4
()
{
$ipv4a
=
'127.0.0.1'
;
$ipv4b
=
'88.77.66.123'
;
$ipv4_range1
=
'88.77.66.1-88.77.66.200'
;
$ipv4_range2
=
'88.77.66.124-88.77.66.200'
;
$ipv4_wild1
=
'88.77.66.*'
;
$ipv4_wild2
=
'88.77.55.*'
;
$ipv4_wild3
=
'88.77.*.*'
;
$ipv6
=
'fe80:1:2:3:a:bad:1dea:dad'
;
$ipv6_compact
=
'::ffff:7f00:0001'
;
$ipv6_expanded
=
'0:0:0:0:0:ffff:7f00:0001'
;
$ipv6_range1
=
'::ffff:7f00:0001-::ffff:7f00:0099'
;
$ipv6_range2
=
'::ffff:7f00:0002-::ffff:7f00:0099'
;
$ipv6_range3
=
'::ffff:7f00:0001-0:0:0:0:0:ffff:7f00:0099'
;
$ipv6_wildcard1
=
'::ffff:7f00:*'
;
$ipv6_wildcard2
=
'::ffff:7e99:*'
;
$ipv6_wildcard3
=
'::ffff:*:*'
;
// check mixed types
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$ipv4b
,
$ipv6
),
'Mixed IP types'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$ipv4b
,
$
this
->
ipv6
),
'Mixed IP types'
);
// check single IPv4
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv4a
,
$ipv4a
),
'IPv4 match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$ipv4a
,
$ipv4b
),
'IPv4 non-match'
);
// check IPv4 range
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv4b
,
$ipv4_range1
),
'IPv4 range match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$ipv4b
,
$ipv4_range2
),
'IPv4 range non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv4b
,
'88.77.66.1-88.77.66.200'
),
'IPv4 range match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$ipv4b
,
'88.77.66.124-88.77.66.200'
),
'IPv4 range non-match'
);
// check IPv4 wildcard
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv4b
,
$ipv4_wild1
),
'IPv4 wildcard match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$ipv4b
,
$ipv4_wild2
),
'IPv4 wildcard non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv4b
,
$ipv4_wild3
),
'IPv4 double wildcard match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv4b
,
$this
->
ipv4_wildcard1
),
'IPv4 wildcard match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$ipv4b
,
$this
->
ipv4_wildcard2
),
'IPv4 wildcard non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv4b
,
$this
->
ipv4_wildcard3
),
'IPv4 double wildcard match'
);
}
/**
* Test IP matching function with IPv6.
*/
public
function
test__qa_block_ip_match__ipv6
()
{
// check single IPv6
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$
ipv6
,
$
ipv6
),
'IPv6 match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$
ipv6
,
$
ipv6_expanded
),
'IPv6 non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$
ipv6_compact
,
$
ipv6_compact
),
'IPv6 compact match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$
ipv6_compact
,
$
ipv6_expanded
),
'IPv6 compact+expanded match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$
ipv6
,
$
ipv6_compact
),
'IPv6 compact+expanded non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$
this
->
ipv6
,
$this
->
ipv6
),
'IPv6 match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$
this
->
ipv6
,
$this
->
ipv6_expanded
),
'IPv6 non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$
this
->
ipv6_compact
,
$this
->
ipv6_compact
),
'IPv6 compact match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$
this
->
ipv6_compact
,
$this
->
ipv6_expanded
),
'IPv6 compact+expanded match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$
this
->
ipv6
,
$this
->
ipv6_compact
),
'IPv6 compact+expanded non-match'
);
// check IPv6 range
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv6_compact
,
$ipv6_range1
),
'IPv6 range match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$ipv6_compact
,
$ipv6_range2
),
'IPv6 range non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv6_compact
,
$ipv6_range3
),
'IPv6 range compact+expanded match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$this
->
ipv6_compact
,
'::ffff:7f00:0001-0:0:0:0:0:ffff:7f00:0099'
),
'IPv6 range match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$this
->
ipv6_compact
,
'::ffff:7f00:0002-::ffff:7f00:0099'
),
'IPv6 range non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
'ffff::1'
,
'ffff::1-ffff::5'
),
'Large IPv6 range match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
'ffff::1'
,
'ffff::2-ffff::5'
),
'Large IPv6 range non-match'
);
// check IPv6 wildcard
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv6_expanded
,
$ipv6_wildcard1
),
'IPv6 wildcard match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv6_compact
,
$ipv6_wildcard1
),
'IPv6 compact wildcard match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$ipv6_compact
,
$ipv6_wildcard2
),
'IPv6 wildcard non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$ipv6_compact
,
$ipv6_wildcard3
),
'IPv6 double wildcard match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$this
->
ipv6_expanded
,
$this
->
ipv6_wildcard1
),
'IPv6 wildcard match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$this
->
ipv6_compact
,
$this
->
ipv6_wildcard1
),
'IPv6 compact wildcard match'
);
$this
->
assertSame
(
false
,
qa_block_ip_match
(
$this
->
ipv6_compact
,
$this
->
ipv6_wildcard2
),
'IPv6 wildcard non-match'
);
$this
->
assertSame
(
true
,
qa_block_ip_match
(
$this
->
ipv6_compact
,
$this
->
ipv6_wildcard3
),
'IPv6 double wildcard match'
);
}
public
function
test__qa_ip_between
()
{
$this
->
assertTrue
(
qa_ip_between
(
'::1'
,
'0:0:0:0:0:0:0:0001'
,
'0:0:0:0:0:0:0:0005'
),
'IPv6 match'
);
$this
->
assertFalse
(
qa_ip_between
(
'::1'
,
'0:0:0:0:0:0:0:0002'
,
'0:0:0:0:0:0:0:0005'
),
'IPv6 non-match'
);
$this
->
assertTrue
(
qa_ip_between
(
'ffff::3'
,
'ffff::1'
,
'ffff::5'
),
'Large IPv6 match'
);
$this
->
assertFalse
(
qa_ip_between
(
'ffff::1'
,
'ffff::2'
,
'ffff::5'
),
'Large IPv6 non-match'
);
}
public
function
test__qa_ipv6_expand
()
{
$this
->
assertSame
(
'0000:0000:0000:0000:0000:0000:0000:0001'
,
qa_ipv6_expand
(
'::1'
));
$this
->
assertSame
(
'ffff:0000:0000:0000:0000:0000:0000:0001'
,
qa_ipv6_expand
(
'ffff::1'
));
$this
->
assertSame
(
'0000:0000:0000:0000:0000:ffff:7f00:*'
,
qa_ipv6_expand
(
$this
->
ipv6_wildcard1
));
$this
->
assertSame
(
'0000:0000:0000:0000:0000:ffff:*:*'
,
qa_ipv6_expand
(
$this
->
ipv6_wildcard3
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment