chromium/third_party/blink/renderer/modules/credentialmanagement/public_key_credential_unittest.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/credentialmanagement/public_key_credential.h"

#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_arraybuffer_arraybufferview_string.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_client_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_client_inputs_js_on.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_inputs_js_on.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_values.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_values_js_on.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authenticator_selection_criteria.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_creation_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_creation_options_js_on.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_descriptor.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_descriptor_js_on.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_parameters.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_request_options_js_on.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_rp_entity.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_user_entity.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_user_entity_js_on.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_piece.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"

namespace blink {
namespace {

AllOf;
Eq;
Field;
IsNull;
Matcher;
Pointee;
Pointwise;
Property;
String;

#define SUBTEST(F)

constexpr char kTestB64URL[] =;    // 'test' base64-url encoded
constexpr char kTest2B64URL[] =;  // 'TEST2' base64-url encoded
constexpr char kInvalidB64URL[] =;

// Fields to instantiate PublicKeyCredentialOptionsJSON (non-exhaustive). All
// required fields are default-initialized.
struct CredentialDescriptorValues {};

// Fields to instantiate AuthenticationExtensionsClientInputsJSON.
struct ExtensionsClientInputsValues {};

AuthenticationExtensionsClientInputsJSON* MakeExtensionsInputsJSON(
    const ExtensionsClientInputsValues& in) {}

// Fields to instantiate PublicKeyCredentialCreationOptionsJSON.
struct CredentialCreationOptionsValues {};

PublicKeyCredentialCreationOptionsJSON* MakeCreationOptionsJSON(
    const CredentialCreationOptionsValues& in) {}

// Fields to instantiate PublicKeyCredentialRequestOptionsJSON.
struct CredentialRequestOptionsValues {};

PublicKeyCredentialRequestOptionsJSON* MakeRequestOptionsJSON(
    const CredentialRequestOptionsValues& in) {}

// Matches a blink WTF::String and a std::string for byte equality.
MATCHER_P(StrEq, str, "") {}

// Matches a pair of (WTF::String, std::string) for equality (used with
// `testing::Pointwise`).
MATCHER(StrEq, "") {}

// Matches the underlying `T` pointee of a `blink::Member<T>`.
template <typename T>
Matcher<Member<T>> MemberField(Matcher<T> matcher) {}

// Performs WebAuthn Base64URL encoding, which is always unpadded.
WTF::String Base64URLEncode(DOMArrayPiece buffer) {}

// Matches the Base64URL-encoding of the byte contents of a DOMArrayPiece.
MATCHER_P(Base64URL, matcher, "") {}

// Matches a pair of `Member<PublicKeyCredentialDescriptor>` and
// `CredentialDescriptorValues`. (Use with `testing::Pointwise`).
MATCHER(CredentialDescriptorsEq, "") {}

// Matches `PublicKeyCredentialParameters`.
MATCHER_P2(PubKeyCredParamsEq, type, alg, "") {}

// Matches `AuthenticationExtensionsPRFValues`.
MATCHER_P(PRFValuesEq, values, "") {}

// Matches `AuthenticationExtensionsPRFInputs::evalByCredential()`.
MATCHER(PRFCredIdAndValuesEq, "") {}

// Tests `AuthenticationExtensionsClientInputs` and
// `ExtensionsClientInputsValues` for equality. Invoke with SUBTEST().
void ExpectExtensionsMatch(
    const AuthenticationExtensionsClientInputs& extensions,
    const ExtensionsClientInputsValues& values) {}

// Tests `PublicKeyCredentialCreationOptions` and `CreationOptionsValues` for
// equality. Invoke with SUBTEST().
void ExpectCreationOptionsMatches(
    const PublicKeyCredentialCreationOptions& options,
    const CredentialCreationOptionsValues& values) {}

// Tests `PublicKeyCredentialRequestOptions` and `RequestOptionsValues` for
// equality. Invoke with SUBTEST().
void ExpectRequestOptionsMatches(
    const PublicKeyCredentialRequestOptions& options,
    const CredentialRequestOptionsValues& values) {}

// Test parseCreationOptionsFromJSON with minimal fields.
TEST(PublicKeyCredentialTest, ParseCreationOptionsFromJSON) {}

// Test parseRequestOptionsFromJSON with minimal fields.
TEST(PublicKeyCredentialTest, ParseRequestOptions) {}

// Test parseCreationOptionsFromJSON with all fields.
TEST(PublicKeyCredentialTest, ParseCreationOptionsFromJSON_Full) {}

// Test parseRequestOptionsFromJSON with all fields.
TEST(PublicKeyCredentialTest, ParseRequestOptionsFromJSON_Full) {}

// PublicKeyCredentialCreationOptions extensions should convert as expected.
TEST(PublicKeyCredentialTest, ParseCreationOptionsFromJSON_WithExtensions) {}

// PublicKeyCredentialRequestOptions extensions should convert as expected.
TEST(PublicKeyCredentialTest, ParseRequestOptionsFromJSON_WithExtensions) {}

// Parsing PublicKeyCredentialCreationOptionsJSON with invalid base64url data
// should yield meaningful error messages.
TEST(PublicKeyCredentialTest, ParseCreationOptionsFromJSON_InvalidBase64URL) {}

// Parsing PublicKeyCredentialRequestOptionsJSON with invalid base64url data
// should yield meaningful error messages.
TEST(PublicKeyCredentialTest, ParseRequestOptionsFromJSON_InvalidBase64URL) {}

}  // namespace
}  // namespace blink