Commit 0a7ef2a1 authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[DeviceSync v2] Add fake CryptAuthDeviceSyncer implementation

Bug: 951969
Change-Id: Ia7c033604400393c55dea4d2895f5a2d320264d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1710886
Commit-Queue: Josh Nohle <nohle@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685208}
parent 15b81d50
......@@ -169,6 +169,8 @@ static_library("test_support") {
"cryptauth_v2_device_sync_test_devices.h",
"fake_cryptauth_device_manager.cc",
"fake_cryptauth_device_manager.h",
"fake_cryptauth_device_syncer.cc",
"fake_cryptauth_device_syncer.h",
"fake_cryptauth_ecies_encryptor.cc",
"fake_cryptauth_ecies_encryptor.h",
"fake_cryptauth_enrollment_manager.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_device_syncer.h"
#include "chromeos/services/device_sync/cryptauth_device_sync_result.h"
namespace chromeos {
namespace device_sync {
FakeCryptAuthDeviceSyncer::FakeCryptAuthDeviceSyncer() = default;
FakeCryptAuthDeviceSyncer::~FakeCryptAuthDeviceSyncer() = default;
void FakeCryptAuthDeviceSyncer::FinishAttempt(
const CryptAuthDeviceSyncResult& device_sync_result) {
DCHECK(client_metadata_);
DCHECK(client_app_metadata_);
OnAttemptFinished(device_sync_result);
}
void FakeCryptAuthDeviceSyncer::OnAttemptStarted(
const cryptauthv2::ClientMetadata& client_metadata,
const cryptauthv2::ClientAppMetadata& client_app_metadata) {
client_metadata_ = client_metadata;
client_app_metadata_ = client_app_metadata;
}
FakeCryptAuthDeviceSyncerFactory::FakeCryptAuthDeviceSyncerFactory() = default;
FakeCryptAuthDeviceSyncerFactory::~FakeCryptAuthDeviceSyncerFactory() = default;
std::unique_ptr<CryptAuthDeviceSyncer>
FakeCryptAuthDeviceSyncerFactory::BuildInstance(
CryptAuthDeviceRegistry* device_registry,
CryptAuthKeyRegistry* key_registry,
CryptAuthClientFactory* client_factory,
std::unique_ptr<base::OneShotTimer> timer) {
last_device_registry_ = device_registry;
last_key_registry_ = key_registry;
last_client_factory_ = client_factory;
auto instance = std::make_unique<FakeCryptAuthDeviceSyncer>();
instances_.push_back(instance.get());
return instance;
}
} // 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_DEVICE_SYNCER_H_
#define CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_DEVICE_SYNCER_H_
#include <vector>
#include "base/macros.h"
#include "base/optional.h"
#include "chromeos/services/device_sync/cryptauth_device_syncer.h"
#include "chromeos/services/device_sync/cryptauth_device_syncer_impl.h"
#include "chromeos/services/device_sync/proto/cryptauth_client_app_metadata.pb.h"
#include "chromeos/services/device_sync/proto/cryptauth_common.pb.h"
namespace chromeos {
namespace device_sync {
class CryptAuthDeviceSyncResult;
// Implementation of CryptAuthDeviceSyncer for use in tests.
class FakeCryptAuthDeviceSyncer : public CryptAuthDeviceSyncer {
public:
FakeCryptAuthDeviceSyncer();
~FakeCryptAuthDeviceSyncer() override;
const base::Optional<cryptauthv2::ClientMetadata>& client_metadata() const {
return client_metadata_;
}
const base::Optional<cryptauthv2::ClientAppMetadata>& client_app_metadata()
const {
return client_app_metadata_;
}
void FinishAttempt(const CryptAuthDeviceSyncResult& device_sync_result);
private:
// CryptAuthDeviceSyncer:
void OnAttemptStarted(
const cryptauthv2::ClientMetadata& client_metadata,
const cryptauthv2::ClientAppMetadata& client_app_metadata) override;
base::Optional<cryptauthv2::ClientMetadata> client_metadata_;
base::Optional<cryptauthv2::ClientAppMetadata> client_app_metadata_;
DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthDeviceSyncer);
};
class FakeCryptAuthDeviceSyncerFactory
: public CryptAuthDeviceSyncerImpl::Factory {
public:
FakeCryptAuthDeviceSyncerFactory();
~FakeCryptAuthDeviceSyncerFactory() override;
const std::vector<FakeCryptAuthDeviceSyncer*>& instances() const {
return instances_;
}
const CryptAuthDeviceRegistry* last_device_registry() const {
return last_device_registry_;
}
const CryptAuthKeyRegistry* last_key_registry() const {
return last_key_registry_;
}
const CryptAuthClientFactory* last_client_factory() const {
return last_client_factory_;
}
private:
// CryptAuthDeviceSyncerImpl::Factory:
std::unique_ptr<CryptAuthDeviceSyncer> BuildInstance(
CryptAuthDeviceRegistry* device_registry,
CryptAuthKeyRegistry* key_registry,
CryptAuthClientFactory* client_factory,
std::unique_ptr<base::OneShotTimer> timer = nullptr) override;
std::vector<FakeCryptAuthDeviceSyncer*> instances_;
CryptAuthDeviceRegistry* last_device_registry_ = nullptr;
CryptAuthKeyRegistry* last_key_registry_ = nullptr;
CryptAuthClientFactory* last_client_factory_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthDeviceSyncerFactory);
};
} // namespace device_sync
} // namespace chromeos
#endif // CHROMEOS_SERVICES_DEVICE_SYNC_FAKE_CRYPTAUTH_DEVICE_SYNCER_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