chromium/third_party/blink/web_tests/crypto/subtle/pbkdf2/importKey-failures.html

<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>

<script>
description("Test bad inputs to PKBDF2 importKey()");

jsTestIsAsync = true;

var extractable = false;
rawBytes = new Uint8Array([1, 2]);

var p = Promise.resolve(null);
p.then(function() {
    debug("\nimportKey() with 'encrypt' usage...");
    return crypto.subtle.importKey("raw", rawBytes, "PBKDF2", extractable, ['encrypt']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with null key data...");
    return crypto.subtle.importKey("raw", null, "PBKDF2", extractable, ['deriveKey']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with jwk format...");
    return crypto.subtle.importKey("jwk", {kty: "PBKDF2"}, "PBKDF2", extractable, ['deriveKey']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with spki format...");
    return crypto.subtle.importKey("spki", rawBytes, "PBKDF2", extractable, ['deriveKey']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with empty usages...");
    return crypto.subtle.importKey("raw", rawBytes, "PBKDF2", extractable, []);
}).then(failAndFinishJSTest, function(result) {
    logError(result);

    debug("\nimportKey() with extractable=true ...");
    return crypto.subtle.importKey("raw", rawBytes, "PBKDF2", true, ['deriveKey']);
}).then(failAndFinishJSTest, function(result) {
    logError(result);
}).then(finishJSTest, failAndFinishJSTest);

</script>

</body>
</html>