Commit 74463020 authored by Julian Pastarmov's avatar Julian Pastarmov Committed by Commit Bot

Modify the getDeviceData api to return no error when the file is missing

Before the API would return an error now it returns no error and an
empty blob instead.

BUG=1046705
TEST=uni_tests

Change-Id: Id15fa397d9db5dcded5db40caac9a719bc9312ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026971Reviewed-by: default avatarOwen Min <zmin@chromium.org>
Commit-Queue: Julian Pastarmov <pastarmovj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736496}
parent 0bc2e114
...@@ -473,9 +473,16 @@ void RetrieveDeviceData( ...@@ -473,9 +473,16 @@ void RetrieveDeviceData(
return; return;
} }
data_file = data_file.AppendASCII(id); data_file = data_file.AppendASCII(id);
// TODO(pastarmovj): Make sure the resulting path is still a direct file or // If the file does not exist don't treat this as an error rather return an
// subdir+file of the EV folder. // empty string.
if (!base::PathExists(data_file)) {
std::move(callback).Run("", true);
return;
}
std::string data; std::string data;
// ReadFileToString does not permit traversal with .. so this is guaranteed to
// be a descendant of the data directory up to links created outside of
// Chrome.
bool result = base::ReadFileToString(data_file, &data); bool result = base::ReadFileToString(data_file, &data);
std::move(callback).Run(data, result); std::move(callback).Run(data, result);
......
...@@ -211,6 +211,32 @@ TEST_F(EnterpriseReportingPrivateDeviceDataFunctionsTest, DeviceDataMissing) { ...@@ -211,6 +211,32 @@ TEST_F(EnterpriseReportingPrivateDeviceDataFunctionsTest, DeviceDataMissing) {
browser(), browser(),
extensions::api_test_utils::NONE); extensions::api_test_utils::NONE);
ASSERT_TRUE(function->GetResultList()); ASSERT_TRUE(function->GetResultList());
EXPECT_EQ(1u, function->GetResultList()->GetSize());
EXPECT_TRUE(function->GetError().empty());
}
TEST_F(EnterpriseReportingPrivateDeviceDataFunctionsTest, DeviceBadId) {
auto set_function =
base::MakeRefCounted<EnterpriseReportingPrivateSetDeviceDataFunction>();
std::unique_ptr<base::ListValue> set_values =
std::make_unique<base::ListValue>();
set_values->AppendString("a/b");
set_values->Append(
std::make_unique<base::Value>(base::Value::BlobStorage({1, 2, 3})));
extension_function_test_utils::RunFunction(set_function.get(),
std::move(set_values), browser(),
extensions::api_test_utils::NONE);
ASSERT_TRUE(set_function->GetError().empty());
// Try to read the directory as a file and should fail.
auto function =
base::MakeRefCounted<EnterpriseReportingPrivateGetDeviceDataFunction>();
std::unique_ptr<base::ListValue> values = std::make_unique<base::ListValue>();
values->AppendString("a");
extension_function_test_utils::RunFunction(function.get(), std::move(values),
browser(),
extensions::api_test_utils::NONE);
ASSERT_TRUE(function->GetResultList());
EXPECT_EQ(0u, function->GetResultList()->GetSize()); EXPECT_EQ(0u, function->GetResultList()->GetSize());
EXPECT_FALSE(function->GetError().empty()); EXPECT_FALSE(function->GetError().empty());
} }
...@@ -263,8 +289,11 @@ TEST_F(EnterpriseReportingPrivateDeviceDataFunctionsTest, RetrieveDeviceData) { ...@@ -263,8 +289,11 @@ TEST_F(EnterpriseReportingPrivateDeviceDataFunctionsTest, RetrieveDeviceData) {
std::move(values2), browser(), std::move(values2), browser(),
extensions::api_test_utils::NONE); extensions::api_test_utils::NONE);
ASSERT_TRUE(get_function2->GetResultList()); ASSERT_TRUE(get_function2->GetResultList());
EXPECT_EQ(0u, get_function2->GetResultList()->GetSize()); EXPECT_TRUE(get_function2->GetResultList()->Get(0, &single_result));
EXPECT_FALSE(get_function2->GetError().empty()); EXPECT_TRUE(get_function2->GetError().empty());
ASSERT_TRUE(single_result);
ASSERT_TRUE(single_result->is_blob());
EXPECT_EQ(base::Value::BlobStorage(), single_result->GetBlob());
} }
// TODO(pastarmovj): Remove once implementation for the other platform exists. // TODO(pastarmovj): Remove once implementation for the other platform exists.
......
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