Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1179091
DebuggerUtilTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Oct 9, 9:55 PM
Size
2 KB
Mime Type
text/x-php
Expires
Sat, Oct 11, 9:55 PM (20 h, 44 m)
Engine
blob
Format
Raw Data
Handle
765336
Attached To
rINP In-Portal
DebuggerUtilTest.php
View Options
<?php
class
DebuggerUtilTest
extends
AbstractTestCase
{
/**
* @dataProvider netMatchDataOnlineProvider
*/
public
function
testNetMatchOnline
(
$network
,
$expected
)
{
static
$ip
;
if
(
!
$this
->
hasInternetConnectivity
()
)
{
$this
->
markTestSkipped
(
'No Internet Connection.'
);
}
if
(
$ip
===
null
)
{
$ip
=
gethostbyname
(
'www.in-portal.org'
);
}
$this
->
assertSame
(
$expected
,
DebuggerUtil
::
netMatch
(
$network
,
$ip
));
}
protected
function
hasInternetConnectivity
()
{
// Use IP of the "www.google.com" hostname to avoid DNS query, that might fail.
$error_code
=
$error_message
=
null
;
$fp
=
@
fsockopen
(
'142.250.74.36'
,
443
,
$error_code
,
$error_message
,
5
);
if
(
$fp
)
{
fclose
(
$fp
);
return
true
;
}
return
false
;
}
public
static
function
netMatchDataOnlineProvider
()
{
return
array
(
// Hosts.
'matched'
=>
array
(
'www.in-portal.org'
,
true
),
'unmatched'
=>
array
(
'www.yahoo.com'
,
false
),
);
}
/**
* @dataProvider netMatchDataOfflineProvider
*/
public
function
testNetMatchOffline
(
$network
,
$ip
,
$expected
)
{
$this
->
assertSame
(
$expected
,
DebuggerUtil
::
netMatch
(
$network
,
$ip
));
}
public
static
function
netMatchDataOfflineProvider
()
{
return
array
(
// IPv4 address vs IPv4 network.
array
(
'1.2.3.4'
,
'1.2.3.4'
,
true
),
array
(
'1.2.3.4'
,
'1.2.3.5'
,
false
),
array
(
'1.2.3.32-1.2.3.54'
,
'1.2.3.40'
,
true
),
array
(
'1.2.3.32-1.2.3.54'
,
'1.2.3.64'
,
false
),
array
(
'1.2.3.32/27'
,
'1.2.3.35'
,
true
),
array
(
'1.2.3.32/27'
,
'1.2.3.64'
,
false
),
array
(
'1.2.3/27'
,
'1.2.3.5'
,
true
),
array
(
'1.2.3/27'
,
'1.2.3.33'
,
false
),
array
(
'1.2.3.32/255.255.255.224'
,
'1.2.3.35'
,
true
),
array
(
'1.2.3.32/255.255.255.224'
,
'1.2.3.64'
,
false
),
array
(
'1.2.3.32/27'
,
'1.2.3.4.6'
,
false
),
// IPv6 address vs IPv6 network.
array
(
'971a:6ff4:3fe8::7085:f498:fc5a:9893'
,
'971a:6ff4:3fe8::7085:f498:fc5a:9893'
,
true
),
array
(
'971a:6ff4:3fe8::7085:f498:fc5a:9893'
,
'971a:6ff4:3fe8::7085:f498:fc5a:9895'
,
false
),
array
(
'971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895'
,
'971a:6ff4:3fe8::9894'
,
true
),
array
(
'971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895'
,
'971a:6ff4:3fe8::9896'
,
false
),
array
(
'971a:6ff4:3fe8::9893/64'
,
'971a:6ff4:3fe8::9895'
,
true
),
array
(
'971a:6ff4:3fe8::9893/64'
,
'971a:6ff4:3fe9::9895'
,
false
),
// IPv6 address vs IPv4 network.
array
(
'1.2.3.4'
,
'971a:6ff4:3fe8::7085:f498:fc5a:9893'
,
false
),
array
(
'1.2.3.32-1.2.3.54'
,
'971a:6ff4:3fe8::7085:f498:fc5a:9893'
,
false
),
array
(
'1.2.3.32/27'
,
'971a:6ff4:3fe8::7085:f498:fc5a:9893'
,
false
),
array
(
'1.2.3/27'
,
'971a:6ff4:3fe8::7085:f498:fc5a:9893'
,
false
),
array
(
'1.2.3.32/255.255.255.224'
,
'971a:6ff4:3fe8::7085:f498:fc5a:9893'
,
false
),
// IPv4 address vs IPv6 network.
array
(
'971a:6ff4:3fe8::7085:f498:fc5a:9893'
,
'1.2.3.4'
,
false
),
array
(
'971a:6ff4:3fe8::9893-971a:6ff4:3fe8::9895'
,
'1.2.3.4'
,
false
),
array
(
'971a:6ff4:3fe8::9893/64'
,
'1.2.3.4'
,
false
),
);
}
}
Event Timeline
Log In to Comment