Commit efd3ccaf authored by jsbell@chromium.org's avatar jsbell@chromium.org

Cache.put() validation of Request properties

Cache.put() should fail the operation if request's scheme is not
"http" or "https", or if the method is not "GET"

Spec:
https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html

R=jkarlin@chromium.org
BUG=425505

Review URL: https://codereview.chromium.org/675733003

git-svn-id: svn://svn.chromium.org/blink/trunk@184310 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 05ec8993
......@@ -9,10 +9,10 @@ PASS Cache.put with HTTP 500 response
FAIL Cache.put called twice with same Request and different Responses Entry already exists.
FAIL Cache.put with an invalid request assert_promise_rejects: Cache.put should only accept a Request object as the request. Promise did not reject.
PASS Cache.put with an invalid response
FAIL Cache.put with a non-HTTP/HTTPS request assert_promise_rejects: Cache.put should reject non-HTTP/HTTPS requests with a TypeError. Promise did not reject.
PASS Cache.put with a non-HTTP/HTTPS request
FAIL Cache.put with a relative URL assert_equals: Cache.put should accept a relative URL as the request. :[object].url expected "" but got "http://127.0.0.1:8000/serviceworker/resources/relative-url"
FAIL Cache.put with a non-GET request assert_promise_rejects: Cache.put should throw a TypeError for non-GET requests. Promise did not reject.
FAIL Cache.put with a non-GET request assert_promise_rejects: Cache.put should throw a TypeError for non-GET requests. Promise did not reject.
PASS Cache.put with a non-GET request
PASS Cache.put with an empty response
Harness: the test ran to completion.
......@@ -372,6 +372,12 @@ ScriptPromise Cache::deleteImpl(ScriptState* scriptState, Request* request, cons
ScriptPromise Cache::putImpl(ScriptState* scriptState, Request* request, Response* response)
{
KURL url(KURL(), request->url());
if (!url.protocolIsInHTTPFamily())
return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError("Request scheme '" + url.protocol() + "' is unsupported", scriptState->isolate()));
if (request->method() != "GET")
return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError("Request method '" + request->method() + "' is unsupported", scriptState->isolate()));
WebVector<WebServiceWorkerCache::BatchOperation> batchOperations(size_t(1));
batchOperations[0].operationType = WebServiceWorkerCache::OperationTypePut;
request->populateWebServiceWorkerRequest(batchOperations[0].request);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment