<!DOCTYPE html><!-- webkit-test-runner [ WebAuthenticationModernEnabled=true ] -->
<title>Web Authentication API: PublicKeyCredential's [[get]] failure cases with a mock u2f authenticator.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/util.js"></script>
<script>
    promise_test(function(t) {
        const options = {
            publicKey: {
                challenge: asciiToUint8Array("123456"),
                allowCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }],
                timeout: 10
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: [testU2fApduNoErrorOnlyResponseBase64] } });
        return promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "Operation timed out.");
    }, "PublicKeyCredential's [[get]] with malformed sign response in a mock hid authenticator.");

    promise_test(function(t) {
        const options = {
            publicKey: {
                challenge: asciiToUint8Array("123456"),
                allowCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }],
                timeout: 10
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fApduWrongDataOnlyResponseBase64] } });
        return promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "Operation timed out.");
    }, "PublicKeyCredential's [[get]] with no matched allow credentials in a mock hid authenticator.");

    promise_test(function(t) {
        const options = {
            publicKey: {
                challenge: asciiToUint8Array("123456"),
                allowCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }, { type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }],
                timeout: 10
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fApduWrongDataOnlyResponseBase64, testU2fApduWrongDataOnlyResponseBase64] } });
        return promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "Operation timed out.");
    }, "PublicKeyCredential's [[get]] with no matched allow credentials in a mock hid authenticator. 2");
</script>
