Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F99246670
AphrontHTTPSinkTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jan 22, 18:16
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Jan 24, 18:16 (2 d)
Engine
blob
Format
Raw Data
Handle
23755645
Attached To
rPH Phabricator
AphrontHTTPSinkTestCase.php
View Options
<?php
final
class
AphrontHTTPSinkTestCase
extends
PhabricatorTestCase
{
public
function
testHTTPSinkBasics
()
{
$sink
=
new
AphrontIsolatedHTTPSink
();
$sink
->
writeHTTPStatus
(
200
);
$sink
->
writeHeaders
(
array
(
array
(
'X-Test'
,
'test'
)));
$sink
->
writeData
(
'test'
);
$this
->
assertEqual
(
200
,
$sink
->
getEmittedHTTPStatus
());
$this
->
assertEqual
(
array
(
array
(
'X-Test'
,
'test'
)),
$sink
->
getEmittedHeaders
());
$this
->
assertEqual
(
'test'
,
$sink
->
getEmittedData
());
}
public
function
testHTTPSinkStatusCode
()
{
$input
=
$this
->
tryTestCaseMap
(
array
(
200
=>
true
,
'201'
=>
true
,
1
=>
false
,
1000
=>
false
,
'apple'
=>
false
,
''
=>
false
,
),
array
(
$this
,
'tryHTTPSinkStatusCode'
));
}
protected
function
tryHTTPSinkStatusCode
(
$input
)
{
$sink
=
new
AphrontIsolatedHTTPSink
();
$sink
->
writeHTTPStatus
(
$input
);
}
public
function
testHTTPSinkResponseSplitting
()
{
$input
=
$this
->
tryTestCaseMap
(
array
(
'test'
=>
true
,
"test
\n
x"
=>
false
,
"test
\r
x"
=>
false
,
"test
\0
x"
=>
false
,
),
array
(
$this
,
'tryHTTPSinkResponseSplitting'
));
}
protected
function
tryHTTPSinkResponseSplitting
(
$input
)
{
$sink
=
new
AphrontIsolatedHTTPSink
();
$sink
->
writeHeaders
(
array
(
array
(
'X-Test'
,
$input
)));
}
public
function
testHTTPHeaderNames
()
{
$input
=
$this
->
tryTestCaseMap
(
array
(
'test'
=>
true
,
'test:'
=>
false
,
),
array
(
$this
,
'tryHTTPHeaderNames'
));
}
protected
function
tryHTTPHeaderNames
(
$input
)
{
$sink
=
new
AphrontIsolatedHTTPSink
();
$sink
->
writeHeaders
(
array
(
array
(
$input
,
'value'
)));
}
public
function
testJSONContentSniff
()
{
$response
=
id
(
new
AphrontJSONResponse
())
->
setContent
(
array
(
'x'
=>
'<iframe>'
,
));
$sink
=
new
AphrontIsolatedHTTPSink
();
$sink
->
writeResponse
(
$response
);
$this
->
assertEqual
(
'for (;;);{"x":"
\u
003ciframe
\u
003e"}'
,
$sink
->
getEmittedData
(),
'JSONResponse should prevent content-sniffing attacks.'
);
}
}
Event Timeline
Log In to Comment