IDB should store RTCCertificate
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Dec 2018 17:44:47 +0000 (17:44 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Dec 2018 17:44:47 +0000 (17:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192599

Reviewed by Brady Eidson.

Source/WebCore:

In case there is no script execution context, do not create a JS DOM wrapper for RTCCertificate.
Instead, create an empty object so that the deserialization can still succeed.
This should only impact IDB deserialization in the Network Process which does not need the actual JS DOM wrapper.

Test: webrtc/certificates-indexeddb.html

* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneDeserializer::readTerminal):

LayoutTests:

* webrtc/certificates-indexeddb-expected.txt: Added.
* webrtc/certificates-indexeddb.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239211 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webrtc/certificates-indexeddb-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/certificates-indexeddb.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/SerializedScriptValue.cpp

index dc4e041..368d2c0 100644 (file)
@@ -1,3 +1,13 @@
+2018-12-14  Youenn Fablet  <youenn@apple.com>
+
+        IDB should store RTCCertificate
+        https://bugs.webkit.org/show_bug.cgi?id=192599
+
+        Reviewed by Brady Eidson.
+
+        * webrtc/certificates-indexeddb-expected.txt: Added.
+        * webrtc/certificates-indexeddb.html: Added.
+
 2018-12-13  Ryosuke Niwa  <rniwa@webkit.org>
 
         Make HTMLConverter work across shadow boundaries
diff --git a/LayoutTests/webrtc/certificates-indexeddb-expected.txt b/LayoutTests/webrtc/certificates-indexeddb-expected.txt
new file mode 100644 (file)
index 0000000..cdcf735
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Testing certificates IndexedDB storage 
+
diff --git a/LayoutTests/webrtc/certificates-indexeddb.html b/LayoutTests/webrtc/certificates-indexeddb.html
new file mode 100644 (file)
index 0000000..3aa8bac
--- /dev/null
@@ -0,0 +1,54 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing certificates IndexedDB storage</title>
+        <script src="../resources/testharness.js"></script>
+        <script src="../resources/testharnessreport.js"></script>
+    </head>
+    <body>
+        <script>
+let certificate;
+
+function storeKey() {
+    var objectStore = db.transaction("certificate", "readwrite").objectStore("certificate");
+    var req = objectStore.put(certificate, "mycertificate");
+    req.onerror = function(event) {
+        assert_unreached("Could not put a key into database: " + event.target.error.name);
+    }
+    req.onsuccess = function(event) { readKey(); }
+}
+
+function readKey() {
+    var objectStore = db.transaction("certificate").objectStore("certificate");
+    var req = objectStore.get("mycertificate");
+    req.onerror = function(event) {
+        assert_not_reached("Could not get a key from database: " + event.target.error.name);
+    }
+    req.onsuccess = function(event) {
+        assert_not_equals(event.target.result, undefined);
+        assert_equals(event.target.result.expires, certificate.expires);
+        done();
+    }
+}
+
+async function doTest() {
+    certificate = await  RTCPeerConnection.generateCertificate({ name: 'ECDSA', namedCurve: 'P-256' });
+
+    var openRequest = indexedDB.open("rtc");
+    openRequest.onupgradeneeded = function(event) {
+        var objectStore = event.target.result.createObjectStore("certificate");
+    }
+    openRequest.onerror = function(event) {
+        assert_not_reached("Could not open database: " + event.target.error.name);
+    }
+    openRequest.onsuccess = function(event) {
+        db = event.target.result;
+        storeKey();
+    }
+}
+doTest();
+
+        </script>
+    </body>
+</html>
index 47f24eb..ec9bbfc 100644 (file)
@@ -1,3 +1,19 @@
+2018-12-14  Youenn Fablet  <youenn@apple.com>
+
+        IDB should store RTCCertificate
+        https://bugs.webkit.org/show_bug.cgi?id=192599
+
+        Reviewed by Brady Eidson.
+
+        In case there is no script execution context, do not create a JS DOM wrapper for RTCCertificate.
+        Instead, create an empty object so that the deserialization can still succeed.
+        This should only impact IDB deserialization in the Network Process which does not need the actual JS DOM wrapper.
+
+        Test: webrtc/certificates-indexeddb.html
+
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneDeserializer::readTerminal):
+
 2018-12-14  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][BFC] Transition to logical margin types.
index ab8120f..2b8d9c0 100644 (file)
@@ -2717,6 +2717,9 @@ private:
             fingerprints.uncheckedAppend(RTCCertificate::DtlsFingerprint { algorithm->string(), value->string() });
         }
 
+        if (!m_isDOMGlobalObject)
+            return constructEmptyObject(m_exec, m_globalObject->objectPrototype());
+
         auto rtcCertificate = RTCCertificate::create(SecurityOrigin::createFromString(origin->string()), expires, WTFMove(fingerprints), certificate->takeString(), keyedMaterial->takeString());
         return toJSNewlyCreated(m_exec, jsCast<JSDOMGlobalObject*>(m_globalObject), WTFMove(rtcCertificate));
     }