1// Copyright 2018 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <array> 6 7#include <Foundation/Foundation.h> 8#include <Security/Security.h> 9 10#include "base/strings/string_number_conversions.h" 11 12#include "base/test/task_environment.h" 13#include "device/fido/fido_constants.h" 14#include "device/fido/fido_test_data.h" 15#include "device/fido/mac/authenticator_config.h" 16#include "device/fido/mac/credential_store.h" 17#include "device/fido/mac/make_credential_operation.h" 18#include "device/fido/test_callback_receiver.h" 19#include "testing/gmock/include/gmock/gmock.h" 20#include "testing/gtest/include/gtest/gtest.h" 21 22namespace device { 23namespace fido { 24namespace mac { 25namespace { 26 27using test::TestCallbackReceiver; 28 29const std::string kRpId = "rp.example.com"; 30const std::vector<uint8_t> kUserId = {10, 11, 12, 13, 14, 15}; 31const char kKeychainAccessGroup[] = 32 "EQHXZ8M8AV.com.google.chrome.webauthn.test"; 33 34CtapMakeCredentialRequest MakeTestRequest() { 35 return CtapMakeCredentialRequest( 36 test_data::kClientDataJson, PublicKeyCredentialRpEntity(kRpId), 37 PublicKeyCredentialUserEntity(kUserId), 38 PublicKeyCredentialParams( 39 {{PublicKeyCredentialParams:: 40 CredentialInfo() /* defaults to ES-256 */}})); 41} 42 43// For demo purposes only. This test does a Touch ID user prompt. It will fail 44// on incompatible hardware and crash if not code signed or lacking the 45// keychain-access-group entitlement. 46TEST(MakeCredentialOperationTest, DISABLED_TestRun) 47API_AVAILABLE(macosx(10.12.2)) { 48 base::test::TaskEnvironment task_environment; 49 TestCallbackReceiver<CtapDeviceResponseCode, 50 base::Optional<AuthenticatorMakeCredentialResponse>> 51 callback_receiver; 52 auto request = MakeTestRequest(); 53 TouchIdCredentialStore credential_store( 54 AuthenticatorConfig{"test-profile", kKeychainAccessGroup}); 55 MakeCredentialOperation op(request, &credential_store, 56 callback_receiver.callback()); 57 58 op.Run(); 59 callback_receiver.WaitForCallback(); 60 auto result = callback_receiver.TakeResult(); 61 CtapDeviceResponseCode error = std::get<0>(result); 62 EXPECT_EQ(CtapDeviceResponseCode::kSuccess, error); 63 auto opt_response = std::move(std::get<1>(result)); 64 ASSERT_TRUE(opt_response); 65} 66 67} // namespace 68} // namespace mac 69} // namespace fido 70} // namespace device 71