tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

update-disallowed-input.js (1872B)


      1 function runTest(config)
      2 {
      3    // This test passes |response| to update() as a JSON Web Key Set.
      4    // CDMs other than Clear Key won't expect |response| in this format.
      5    promise_test(function(test) {
      6        var initDataType;
      7        var initData;
      8        var keySystem = config.keysystem;
      9        var mediaKeySession;
     10 
     11        function createReallyLongJWKSet()
     12        {
     13            // This is just a standard JWKSet with a lot of
     14            // extra items added to the end. Key ID and key
     15            // doesn't really matter.
     16            var jwkSet = '{"keys":[{'
     17                       +     '"kty":"oct",'
     18                       +     '"k":"MDEyMzQ1Njc4OTAxMjM0NQ",'
     19                       +     '"kid":"MDEyMzQ1Njc4OTAxMjM0NQ"'
     20                       + '}]';
     21            return jwkSet + ',"test":"unknown"'.repeat(4000) + '}';
     22        }
     23 
     24        var p = navigator.requestMediaKeySystemAccess(keySystem, getSimpleConfiguration()).then(function(access) {
     25            initDataType = access.getConfiguration().initDataTypes[0];
     26            initData = getInitData(initDataType);
     27            return access.createMediaKeys();
     28        }).then(function(mediaKeys) {
     29            mediaKeySession = mediaKeys.createSession();
     30            var eventWatcher = new EventWatcher(test, mediaKeySession, ['message']);
     31            var promise = eventWatcher.wait_for('message');
     32            mediaKeySession.generateRequest(initDataType, initData);
     33            return promise;
     34        }).then(function () {
     35            var jwkSet = createReallyLongJWKSet();
     36            assert_greater_than(jwkSet.length, 65536);
     37            var jwkSetArray = stringToUint8Array(jwkSet);
     38            return mediaKeySession.update(jwkSetArray);
     39        });
     40 
     41        return promise_rejects_js(test, TypeError, p);
     42    }, 'update() with invalid response (longer than 64Kb characters) should fail.');
     43 }