Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FakeRlweClient is anything but simple. It partially reimplements the PIR logic from the private_membership::rlwe::PrivateMembershipRlweClient, which forces the policy::RequestHandlerForPsmAutoEnrollment to reply with corresponding data. However, all of this should be implementation details of the PSM library. It contradicts the general idea that tests should be easy to understand. This change drops the FakeRlweClient and the RequestHandlerForPsmAutoEnrollment. Instead, tests can now use psm::RlweTestSupport to construct an RlweClientImpl from a test case from the PSM library's test database. The EmbeddedPolicyTestServer is also using the test cases from the test database to validate requests and send appropriate responses. This makes the test logic less complex, requiring less understanding of implementation details. Bug: b/241911665 Change-Id: Ifae396257638433503ff82e19945e62d38df60c1 Tests: Refactored browser tests Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4155468 Reviewed-by: Danila Kuzmin <dkuzmin@google.com> Commit-Queue: Roland Bock <rbock@google.com> Reviewed-by: Igor <igorcov@chromium.org> Reviewed-by: Amr Aboelkher <amraboelkher@chromium.org> Cr-Commit-Position: refs/heads/main@{#1097319}
- Loading branch information
Roland Bock
authored and
Chromium LUCI CQ
committed
Jan 26, 2023
1 parent
896fbdb
commit b53d286
Showing
14 changed files
with
362 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 0 additions & 113 deletions
113
chrome/browser/ash/policy/enrollment/psm/fake_rlwe_client.cc
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
chrome/browser/ash/policy/enrollment/psm/fake_rlwe_client.h
This file was deleted.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
chrome/browser/ash/policy/enrollment/psm/rlwe_test_support.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ash/policy/enrollment/psm/rlwe_test_support.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "base/check.h" | ||
#include "base/files/file_path.h" | ||
#include "base/files/file_util.h" | ||
#include "base/path_service.h" | ||
#include "base/threading/thread_restrictions.h" | ||
#include "chrome/browser/ash/policy/enrollment/psm/rlwe_client_impl.h" | ||
#include "components/policy/proto/device_management_backend.pb.h" | ||
#include "third_party/private_membership/src/internal/testing/regression_test_data/regression_test_data.pb.h" | ||
#include "third_party/private_membership/src/private_membership_rlwe_client.h" | ||
|
||
namespace em = enterprise_management; | ||
using RlweTestData = | ||
private_membership::rlwe::PrivateMembershipRlweClientRegressionTestData; | ||
|
||
namespace policy::psm::testing { | ||
|
||
namespace { | ||
|
||
std::unique_ptr<RlweClient> CreateRlweClient( | ||
const RlweTestCase& test_case, | ||
const private_membership::rlwe::RlwePlaintextId& /* unused*/) { | ||
auto status_or_client = | ||
private_membership::rlwe::PrivateMembershipRlweClient::CreateForTesting( | ||
private_membership::rlwe::RlweUseCase::CROS_DEVICE_STATE, | ||
{test_case.plaintext_id()}, test_case.ec_cipher_key(), | ||
test_case.seed()); // IN-TEST | ||
CHECK(status_or_client.ok()) << status_or_client.status().message(); | ||
|
||
return std::make_unique<RlweClientImpl>(std::move(status_or_client).value(), | ||
test_case.plaintext_id()); | ||
} | ||
|
||
RlweTestData ReadTestData() { | ||
base::FilePath src_root_dir; | ||
CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &src_root_dir)); | ||
const base::FilePath path_to_test_data = | ||
src_root_dir.AppendASCII("third_party") | ||
.AppendASCII("private_membership") | ||
.AppendASCII("src") | ||
.AppendASCII("internal") | ||
.AppendASCII("testing") | ||
.AppendASCII("regression_test_data") | ||
.AppendASCII("test_data.binarypb"); | ||
|
||
base::ScopedAllowBlockingForTesting allow_blocking; | ||
CHECK(base::PathExists(path_to_test_data)) | ||
<< " path_to_test_data: " << path_to_test_data; | ||
|
||
std::string serialized_test_data; | ||
CHECK(base::ReadFileToString(path_to_test_data, &serialized_test_data)); | ||
|
||
RlweTestData test_data; | ||
CHECK(test_data.ParseFromString(serialized_test_data)); | ||
|
||
return test_data; | ||
} | ||
|
||
} // namespace | ||
|
||
RlweTestCase LoadTestCase(bool is_member) { | ||
const auto test_data = ReadTestData(); | ||
|
||
for (const auto& test_case : test_data.test_cases()) { | ||
if (test_case.is_positive_membership_expected() == is_member) { | ||
return test_case; | ||
} | ||
} | ||
|
||
CHECK(false) << "Could not find psm test data for is_member == " << is_member; | ||
return {}; | ||
} | ||
|
||
RlweClientFactory CreateClientFactory(bool is_member) { | ||
return base::BindRepeating(&CreateRlweClient, LoadTestCase(is_member)); | ||
} | ||
|
||
} // namespace policy::psm::testing |
44 changes: 44 additions & 0 deletions
44
chrome/browser/ash/policy/enrollment/psm/rlwe_test_support.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_ASH_POLICY_ENROLLMENT_PSM_RLWE_TEST_SUPPORT_H_ | ||
#define CHROME_BROWSER_ASH_POLICY_ENROLLMENT_PSM_RLWE_TEST_SUPPORT_H_ | ||
|
||
#include "chrome/browser/ash/policy/enrollment/psm/rlwe_client.h" | ||
|
||
#include <memory> | ||
|
||
#include "base/functional/callback.h" | ||
#include "third_party/private_membership/src/internal/testing/regression_test_data/regression_test_data.pb.h" | ||
|
||
namespace private_membership::rlwe { | ||
class RlwePlaintextId; | ||
} // namespace private_membership::rlwe | ||
|
||
namespace policy::psm::testing { | ||
|
||
using RlweTestCase = private_membership::rlwe:: | ||
PrivateMembershipRlweClientRegressionTestData::TestCase; | ||
|
||
using RlweClientFactory = base::RepeatingCallback<std::unique_ptr<RlweClient>( | ||
const private_membership::rlwe::RlwePlaintextId&)>; | ||
|
||
// Load a test case from the test database provided by the | ||
// third_party/private_membership library. These can be used to simulate PSM | ||
// requests for members or non-members of the set. | ||
// | ||
// Note that this function performs a blocking file read. | ||
RlweTestCase LoadTestCase(bool is_member); | ||
|
||
// Load a test case from the test database provided by the | ||
// third_party/private_membership library. Based on that test case, | ||
// create a callback as needed by the `AutoEnrollmentController` to create an | ||
// `RlweClient`. The returned callback will ignore the plaintext id and | ||
// instead create an `RlweClient` that will create requests as expected by the | ||
// EmbeddedPolicyTestServer. | ||
RlweClientFactory CreateClientFactory(bool is_member = true); | ||
|
||
} // namespace policy::psm::testing | ||
|
||
#endif // CHROME_BROWSER_ASH_POLICY_ENROLLMENT_PSM_RLWE_TEST_SUPPORT_H_ |
Oops, something went wrong.