Add test infrastructure and tests for existing HTTP 0.9 sandbox machinery
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Nov 2016 21:17:45 +0000 (21:17 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Nov 2016 21:17:45 +0000 (21:17 +0000)
commit6a4004175f80265ac5cc5d30e6cce81925260016
treee2934127d5677b4f08edd11a17e4f58017bee2e8
parent354f05c40054913430f8ca6ee806815189c43974
Add test infrastructure and tests for existing HTTP 0.9 sandbox machinery
https://bugs.webkit.org/show_bug.cgi?id=164389
<rdar://problem/29101072>

Reviewed by Alex Christensen.

Source/WebCore:

Add test infrastructure to support registering an arbitrary port as the default port
for a protocol. The behavior of various machinery, including the HTTP 0.9 machinery,
can be effected by whether the resource request was made using the default port for
the protocol. We expose window.internals.registerDefaultPortForProtocol() to allow
a test to override the default port associated with a protocol so as to support
testing these code paths using the existing port 8000 server started by run-webkit-httpd.
Without window.internals.registerDefaultPortForProtocol() we would need to teach
run-webkit-httpd to run a web server on port 80, which requires superuser privileges
(since it is a privileged port number) and is more likely to interfere with an
existing web server setup.

Tests: http/tests/security/http-0.9/default-port-plugin-blocked.html
       http/tests/security/http-0.9/default-port-script-blocked.html
       http/tests/security/http-0.9/iframe-blocked.html
       http/tests/security/http-0.9/image-blocked.html
       http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed-ref-test.html
       http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed.html
       http/tests/security/http-0.9/image-on-HTTP-0.9-page-blocked.html
       http/tests/security/http-0.9/worker-connect-src-blocked.html
       http/tests/security/http-0.9/worker-importScripts-blocked.html
       http/tests/security/http-0.9/xhr-asynchronous-blocked.html

* platform/URL.cpp:
(WebCore::defaultPortForProtocolMapForTesting): Added.
(WebCore::registerDefaultPortForProtocolForTesting): Adds the specified (protocol, port) to the
mapping used for testing.
(WebCore::clearDefaultPortForProtocolMapForTesting): Clears the protocol to default port testing map.
We call this function from Internals::resetToConsistentState() so that the mapping is cleared between
test runs.
(WebCore::defaultPortForProtocol): Modified to check the protocol to default port map for testing
before consulting URLParser::defaultPortForProtocol().
* platform/URL.h:
* testing/Internals.cpp:
(WebCore::Internals::resetToConsistentState): Clear the default port mapping used for testing.
(WebCore::Internals::registerDefaultPortForProtocol): Added.
* testing/Internals.h:
* testing/Internals.idl: Added declaration for registerDefaultPortForProtocol().

LayoutTests:

Add tests for the existing HTTP 0.9 sandbox machinery. Until we fix <https://bugs.webkit.org/show_bug.cgi?id=164387>,
these tests can only be run singly (i.e. pass --run-singly to run-webkit-tests). So, we skip
these tests to avoid test failures when run-webkit-tests runs in parallel mode (the default
mode and the mode used on the buildbots).

* TestExpectations:
* http/tests/security/http-0.9/default-port-plugin-blocked-expected.txt: Added.
* http/tests/security/http-0.9/default-port-plugin-blocked.html: Added.
* http/tests/security/http-0.9/default-port-script-blocked-expected.txt: Added.
* http/tests/security/http-0.9/default-port-script-blocked.html: Added.
* http/tests/security/http-0.9/iframe-blocked-expected.txt: Added.
* http/tests/security/http-0.9/iframe-blocked.html: Added.
* http/tests/security/http-0.9/image-blocked-expected.txt: Added.
* http/tests/security/http-0.9/image-blocked.html: Added.
* http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed-expected.txt: Added.
* http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed-ref-test-expected.html: Added.
* http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed-ref-test.html: Added.
* http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed.html: Added.
* http/tests/security/http-0.9/image-on-HTTP-0.9-page-blocked-expected.txt: Added.
* http/tests/security/http-0.9/image-on-HTTP-0.9-page-blocked.html: Added.
* http/tests/security/http-0.9/resources/blue-square.png: Added.
* http/tests/security/http-0.9/resources/nph-alert-fail.pl: Added.
* http/tests/security/http-0.9/resources/nph-fail.pl: Added.
* http/tests/security/http-0.9/resources/nph-image-on-HTTP-0.9-default-port-page-allowed.pl: Added.
* http/tests/security/http-0.9/resources/nph-image-on-HTTP-0.9-page-blocked.pl: Added.
* http/tests/security/http-0.9/resources/nph-image.pl: Added.
* http/tests/security/http-0.9/resources/nph-load-plugin-fail.pl: Added.
* http/tests/security/http-0.9/resources/nph-worker-fail.pl: Added.
* http/tests/security/http-0.9/worker-connect-src-blocked-expected.txt: Added.
* http/tests/security/http-0.9/worker-connect-src-blocked.html: Added.
* http/tests/security/http-0.9/worker-importScripts-blocked-expected.txt: Added.
* http/tests/security/http-0.9/worker-importScripts-blocked.html: Added.
* http/tests/security/http-0.9/xhr-asynchronous-blocked-expected.txt: Added.
* http/tests/security/http-0.9/xhr-asynchronous-blocked.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@208475 268f45cc-cd09-0410-ab3c-d52691b4dbfc
36 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/security/http-0.9/default-port-plugin-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/default-port-plugin-blocked.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/default-port-script-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/default-port-script-blocked.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/iframe-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/iframe-blocked.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/image-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/image-blocked.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed-ref-test-expected.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed-ref-test.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/image-on-HTTP-0.9-page-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/image-on-HTTP-0.9-page-blocked.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/resources/blue-square.png [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/resources/nph-alert-fail.pl [new file with mode: 0755]
LayoutTests/http/tests/security/http-0.9/resources/nph-fail.pl [new file with mode: 0755]
LayoutTests/http/tests/security/http-0.9/resources/nph-image-on-HTTP-0.9-default-port-page-allowed.pl [new file with mode: 0755]
LayoutTests/http/tests/security/http-0.9/resources/nph-image-on-HTTP-0.9-page-blocked.pl [new file with mode: 0755]
LayoutTests/http/tests/security/http-0.9/resources/nph-image.pl [new file with mode: 0755]
LayoutTests/http/tests/security/http-0.9/resources/nph-load-plugin-fail.pl [new file with mode: 0755]
LayoutTests/http/tests/security/http-0.9/resources/nph-worker-fail.pl [new file with mode: 0755]
LayoutTests/http/tests/security/http-0.9/worker-connect-src-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/worker-connect-src-blocked.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/worker-importScripts-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/worker-importScripts-blocked.html [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/xhr-asynchronous-blocked-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/http-0.9/xhr-asynchronous-blocked.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/URL.cpp
Source/WebCore/platform/URL.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl