Commit 92fbd1f3 authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

Add mock test classes for CryptAuthKey{Creator,ProofComputer}

These mock classes override the lone function of their parent classes.
The functions simply store the input parameters, and they can only be
called once. The classes also provides accessors to these input
parameters. Notably, the callback can be retrieved and called with any
desired arguments.

Bug: 899080
Change-Id: I489ac90964f547b78933258162565cd22bf8e88b
Reviewed-on: https://chromium-review.googlesource.com/c/1469292
Commit-Queue: Josh Nohle <nohle@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632282}
parent 8d6b229a
...@@ -20,10 +20,6 @@ static_library("device_sync") { ...@@ -20,10 +20,6 @@ static_library("device_sync") {
"cryptauth_enroller_factory_impl.h", "cryptauth_enroller_factory_impl.h",
"cryptauth_enroller_impl.cc", "cryptauth_enroller_impl.cc",
"cryptauth_enroller_impl.h", "cryptauth_enroller_impl.h",
"cryptauth_key_creator.cc",
"cryptauth_key_creator.h",
"cryptauth_key_creator_impl.cc",
"cryptauth_key_creator_impl.h",
"cryptauth_enrollment_manager.cc", "cryptauth_enrollment_manager.cc",
"cryptauth_enrollment_manager.h", "cryptauth_enrollment_manager.h",
"cryptauth_enrollment_manager_impl.cc", "cryptauth_enrollment_manager_impl.cc",
...@@ -40,6 +36,10 @@ static_library("device_sync") { ...@@ -40,6 +36,10 @@ static_library("device_sync") {
"cryptauth_key.h", "cryptauth_key.h",
"cryptauth_key_bundle.cc", "cryptauth_key_bundle.cc",
"cryptauth_key_bundle.h", "cryptauth_key_bundle.h",
"cryptauth_key_creator.cc",
"cryptauth_key_creator.h",
"cryptauth_key_creator_impl.cc",
"cryptauth_key_creator_impl.h",
"cryptauth_key_proof_computer.h", "cryptauth_key_proof_computer.h",
"cryptauth_key_proof_computer_impl.cc", "cryptauth_key_proof_computer_impl.cc",
"cryptauth_key_proof_computer_impl.h", "cryptauth_key_proof_computer_impl.h",
...@@ -123,6 +123,10 @@ static_library("test_support") { ...@@ -123,6 +123,10 @@ static_library("test_support") {
"fake_cryptauth_enrollment_scheduler.h", "fake_cryptauth_enrollment_scheduler.h",
"fake_cryptauth_gcm_manager.cc", "fake_cryptauth_gcm_manager.cc",
"fake_cryptauth_gcm_manager.h", "fake_cryptauth_gcm_manager.h",
"fake_cryptauth_key_creator.cc",
"fake_cryptauth_key_creator.h",
"fake_cryptauth_key_proof_computer.cc",
"fake_cryptauth_key_proof_computer.h",
"fake_device_sync.cc", "fake_device_sync.cc",
"fake_device_sync.h", "fake_device_sync.h",
"fake_device_sync_observer.cc", "fake_device_sync_observer.cc",
...@@ -159,10 +163,10 @@ source_set("unit_tests") { ...@@ -159,10 +163,10 @@ source_set("unit_tests") {
"cryptauth_client_impl_unittest.cc", "cryptauth_client_impl_unittest.cc",
"cryptauth_device_manager_impl_unittest.cc", "cryptauth_device_manager_impl_unittest.cc",
"cryptauth_enroller_impl_unittest.cc", "cryptauth_enroller_impl_unittest.cc",
"cryptauth_key_creator_impl_unittest.cc",
"cryptauth_enrollment_manager_impl_unittest.cc", "cryptauth_enrollment_manager_impl_unittest.cc",
"cryptauth_gcm_manager_impl_unittest.cc", "cryptauth_gcm_manager_impl_unittest.cc",
"cryptauth_key_bundle_unittest.cc", "cryptauth_key_bundle_unittest.cc",
"cryptauth_key_creator_impl_unittest.cc",
"cryptauth_key_proof_computer_impl_unittest.cc", "cryptauth_key_proof_computer_impl_unittest.cc",
"cryptauth_key_registry_impl_unittest.cc", "cryptauth_key_registry_impl_unittest.cc",
"cryptauth_key_unittest.cc", "cryptauth_key_unittest.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/services/device_sync/fake_cryptauth_key_creator.h"
#include <utility>
namespace chromeos {
namespace device_sync {
FakeCryptAuthKeyCreator::FakeCryptAuthKeyCreator() = default;
FakeCryptAuthKeyCreator::~FakeCryptAuthKeyCreator() = default;
void FakeCryptAuthKeyCreator::CreateKeys(
const base::flat_map<CryptAuthKeyBundle::Name, CreateKeyData>&
keys_to_create,
const base::Optional<CryptAuthKey>& server_ephemeral_dh,
CreateKeysCallback create_keys_callback) {
DCHECK(!keys_to_create.empty());
DCHECK(keys_to_create_.empty());
keys_to_create_ = keys_to_create;
server_ephemeral_dh_ = server_ephemeral_dh;
create_keys_callback_ = std::move(create_keys_callback);
}
} // namespace device_sync
} // namespace chromeos
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_KEY_CREATOR_H_
#define CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_KEY_CREATOR_H_
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/optional.h"
#include "chromeos/services/device_sync/cryptauth_key.h"
#include "chromeos/services/device_sync/cryptauth_key_bundle.h"
#include "chromeos/services/device_sync/cryptauth_key_creator.h"
namespace chromeos {
namespace device_sync {
class FakeCryptAuthKeyCreator : public CryptAuthKeyCreator {
public:
FakeCryptAuthKeyCreator();
~FakeCryptAuthKeyCreator() override;
// CryptAuthKeyCreator:
void CreateKeys(const base::flat_map<CryptAuthKeyBundle::Name, CreateKeyData>&
keys_to_create,
const base::Optional<CryptAuthKey>& server_ephemeral_dh,
CreateKeysCallback create_keys_callback) override;
const base::flat_map<CryptAuthKeyBundle::Name, CreateKeyData>&
keys_to_create() const {
return keys_to_create_;
}
const base::Optional<CryptAuthKey>& server_ephemeral_dh() const {
return server_ephemeral_dh_;
}
CreateKeysCallback& create_keys_callback() { return create_keys_callback_; }
private:
base::flat_map<CryptAuthKeyBundle::Name, CreateKeyData> keys_to_create_;
base::Optional<CryptAuthKey> server_ephemeral_dh_;
CreateKeysCallback create_keys_callback_;
DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthKeyCreator);
};
} // namespace device_sync
} // namespace chromeos
#endif // CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_KEY_CREATOR_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/services/device_sync/fake_cryptauth_key_proof_computer.h"
#include <utility>
namespace chromeos {
namespace device_sync {
FakeCryptAuthKeyProofComputer::FakeCryptAuthKeyProofComputer() = default;
FakeCryptAuthKeyProofComputer::~FakeCryptAuthKeyProofComputer() = default;
void FakeCryptAuthKeyProofComputer::ComputeKeyProofs(
const std::vector<std::pair<CryptAuthKey, std::string>>& key_payload_pairs,
ComputeKeyProofsCallback compute_key_proofs_callback) {
DCHECK(!key_payload_pairs.empty());
DCHECK(key_payload_pairs_.empty());
key_payload_pairs_ = key_payload_pairs;
compute_key_proofs_callback_ = std::move(compute_key_proofs_callback);
}
} // namespace device_sync
} // namespace chromeos
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_KEY_PROOF_COMPUTER_H_
#define CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_KEY_PROOF_COMPUTER_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "chromeos/services/device_sync/cryptauth_key.h"
#include "chromeos/services/device_sync/cryptauth_key_proof_computer.h"
namespace chromeos {
namespace device_sync {
class FakeCryptAuthKeyProofComputer : public CryptAuthKeyProofComputer {
public:
FakeCryptAuthKeyProofComputer();
~FakeCryptAuthKeyProofComputer() override;
// CryptAuthKeyProofComputer:
void ComputeKeyProofs(
const std::vector<std::pair<CryptAuthKey, std::string>>&
key_payload_pairs,
ComputeKeyProofsCallback compute_key_proofs_callback) override;
const std::vector<std::pair<CryptAuthKey, std::string>>& key_payload_pairs()
const {
return key_payload_pairs_;
}
ComputeKeyProofsCallback& compute_key_proofs_callback() {
return compute_key_proofs_callback_;
}
private:
std::vector<std::pair<CryptAuthKey, std::string>> key_payload_pairs_;
ComputeKeyProofsCallback compute_key_proofs_callback_;
DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthKeyProofComputer);
};
} // namespace device_sync
} // namespace chromeos
#endif // CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_KEY_PROOF_COMPUTER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment