Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agree to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdio.h> |
Tao Bao | 00d5757 | 2017-05-02 15:48:54 -0700 | [diff] [blame] | 18 | #include <sys/stat.h> |
| 19 | #include <sys/types.h> |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 20 | #include <unistd.h> |
Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 21 | |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 22 | #include <algorithm> |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 23 | #include <random> |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <vector> |
| 26 | |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 27 | #include <android-base/file.h> |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 28 | #include <android-base/properties.h> |
| 29 | #include <android-base/strings.h> |
Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 30 | #include <gtest/gtest.h> |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 31 | #include <vintf/VintfObjectRecovery.h> |
Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 32 | #include <ziparchive/zip_archive.h> |
| 33 | #include <ziparchive/zip_writer.h> |
| 34 | |
xunchang | 2478885 | 2019-03-22 16:08:52 -0700 | [diff] [blame] | 35 | #include "install/install.h" |
Tao Bao | 7f19d10 | 2019-04-26 22:56:56 -0700 | [diff] [blame] | 36 | #include "install/wipe_device.h" |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 37 | #include "otautil/paths.h" |
xunchang | 2478885 | 2019-03-22 16:08:52 -0700 | [diff] [blame] | 38 | #include "private/setup_commands.h" |
Tianjie Xu | 58a2769 | 2019-08-06 12:32:05 -0700 | [diff] [blame] | 39 | #include "recovery_utils/roots.h" |
Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 40 | |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 41 | static void BuildZipArchive(const std::map<std::string, std::string>& file_map, int fd, |
| 42 | int compression_type) { |
| 43 | FILE* zip_file = fdopen(fd, "w"); |
Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 44 | ZipWriter writer(zip_file); |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 45 | for (const auto& [name, content] : file_map) { |
| 46 | ASSERT_EQ(0, writer.StartEntry(name.c_str(), compression_type)); |
| 47 | ASSERT_EQ(0, writer.WriteBytes(content.data(), content.size())); |
| 48 | ASSERT_EQ(0, writer.FinishEntry()); |
| 49 | } |
Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 50 | ASSERT_EQ(0, writer.Finish()); |
| 51 | ASSERT_EQ(0, fclose(zip_file)); |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | TEST(InstallTest, verify_package_compatibility_no_entry) { |
| 55 | TemporaryFile temp_file; |
| 56 | // The archive must have something to be opened correctly. |
| 57 | BuildZipArchive({ { "dummy_entry", "" } }, temp_file.release(), kCompressStored); |
Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 58 | |
| 59 | // Doesn't contain compatibility zip entry. |
| 60 | ZipArchiveHandle zip; |
| 61 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 62 | ASSERT_TRUE(verify_package_compatibility(zip)); |
| 63 | CloseArchive(zip); |
| 64 | } |
| 65 | |
| 66 | TEST(InstallTest, verify_package_compatibility_invalid_entry) { |
| 67 | TemporaryFile temp_file; |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 68 | BuildZipArchive({ { "compatibility.zip", "" } }, temp_file.release(), kCompressStored); |
Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 69 | |
| 70 | // Empty compatibility zip entry. |
| 71 | ZipArchiveHandle zip; |
| 72 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 73 | ASSERT_FALSE(verify_package_compatibility(zip)); |
| 74 | CloseArchive(zip); |
| 75 | } |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 76 | |
Tao Bao | 8a7afcc | 2017-04-18 22:05:50 -0700 | [diff] [blame] | 77 | TEST(InstallTest, read_metadata_from_package_smoke) { |
| 78 | TemporaryFile temp_file; |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 79 | const std::string content("abc=defg"); |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 80 | BuildZipArchive({ { "META-INF/com/android/metadata", content } }, temp_file.release(), |
| 81 | kCompressStored); |
Tao Bao | 8a7afcc | 2017-04-18 22:05:50 -0700 | [diff] [blame] | 82 | |
| 83 | ZipArchiveHandle zip; |
| 84 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 85 | std::map<std::string, std::string> metadata; |
| 86 | ASSERT_TRUE(ReadMetadataFromPackage(zip, &metadata)); |
| 87 | ASSERT_EQ("defg", metadata["abc"]); |
Tao Bao | 8a7afcc | 2017-04-18 22:05:50 -0700 | [diff] [blame] | 88 | CloseArchive(zip); |
| 89 | |
| 90 | TemporaryFile temp_file2; |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 91 | BuildZipArchive({ { "META-INF/com/android/metadata", content } }, temp_file2.release(), |
| 92 | kCompressDeflated); |
Tao Bao | 8a7afcc | 2017-04-18 22:05:50 -0700 | [diff] [blame] | 93 | |
| 94 | ASSERT_EQ(0, OpenArchive(temp_file2.path, &zip)); |
| 95 | metadata.clear(); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 96 | ASSERT_TRUE(ReadMetadataFromPackage(zip, &metadata)); |
| 97 | ASSERT_EQ("defg", metadata["abc"]); |
Tao Bao | 8a7afcc | 2017-04-18 22:05:50 -0700 | [diff] [blame] | 98 | CloseArchive(zip); |
| 99 | } |
| 100 | |
| 101 | TEST(InstallTest, read_metadata_from_package_no_entry) { |
| 102 | TemporaryFile temp_file; |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 103 | BuildZipArchive({ { "dummy_entry", "" } }, temp_file.release(), kCompressStored); |
Tao Bao | 8a7afcc | 2017-04-18 22:05:50 -0700 | [diff] [blame] | 104 | |
| 105 | ZipArchiveHandle zip; |
| 106 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 107 | std::map<std::string, std::string> metadata; |
| 108 | ASSERT_FALSE(ReadMetadataFromPackage(zip, &metadata)); |
Tao Bao | 8a7afcc | 2017-04-18 22:05:50 -0700 | [diff] [blame] | 109 | CloseArchive(zip); |
| 110 | } |
| 111 | |
xunchang | e0d991c | 2019-03-05 14:50:51 -0800 | [diff] [blame] | 112 | TEST(InstallTest, read_wipe_ab_partition_list) { |
| 113 | std::vector<std::string> partition_list = { |
| 114 | "/dev/block/bootdevice/by-name/system_a", "/dev/block/bootdevice/by-name/system_b", |
| 115 | "/dev/block/bootdevice/by-name/vendor_a", "/dev/block/bootdevice/by-name/vendor_b", |
| 116 | "/dev/block/bootdevice/by-name/userdata", "# Wipe the boot partitions last", |
| 117 | "/dev/block/bootdevice/by-name/boot_a", "/dev/block/bootdevice/by-name/boot_b", |
| 118 | }; |
| 119 | TemporaryFile temp_file; |
| 120 | BuildZipArchive({ { "recovery.wipe", android::base::Join(partition_list, '\n') } }, |
| 121 | temp_file.release(), kCompressDeflated); |
| 122 | std::string wipe_package; |
| 123 | ASSERT_TRUE(android::base::ReadFileToString(temp_file.path, &wipe_package)); |
| 124 | |
xunchang | 55e3d22 | 2019-03-11 11:28:41 -0700 | [diff] [blame] | 125 | auto package = Package::CreateMemoryPackage( |
| 126 | std::vector<uint8_t>(wipe_package.begin(), wipe_package.end()), nullptr); |
| 127 | |
| 128 | auto read_partition_list = GetWipePartitionList(package.get()); |
xunchang | e0d991c | 2019-03-05 14:50:51 -0800 | [diff] [blame] | 129 | std::vector<std::string> expected = { |
| 130 | "/dev/block/bootdevice/by-name/system_a", "/dev/block/bootdevice/by-name/system_b", |
| 131 | "/dev/block/bootdevice/by-name/vendor_a", "/dev/block/bootdevice/by-name/vendor_b", |
| 132 | "/dev/block/bootdevice/by-name/userdata", "/dev/block/bootdevice/by-name/boot_a", |
| 133 | "/dev/block/bootdevice/by-name/boot_b", |
| 134 | }; |
| 135 | ASSERT_EQ(expected, read_partition_list); |
| 136 | } |
| 137 | |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 138 | TEST(InstallTest, verify_package_compatibility_with_libvintf_malformed_xml) { |
| 139 | TemporaryFile compatibility_zip_file; |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 140 | std::string malformed_xml = "malformed"; |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 141 | BuildZipArchive({ { "system_manifest.xml", malformed_xml } }, compatibility_zip_file.release(), |
| 142 | kCompressDeflated); |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 143 | |
| 144 | TemporaryFile temp_file; |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 145 | std::string compatibility_zip_content; |
| 146 | ASSERT_TRUE( |
| 147 | android::base::ReadFileToString(compatibility_zip_file.path, &compatibility_zip_content)); |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 148 | BuildZipArchive({ { "compatibility.zip", compatibility_zip_content } }, temp_file.release(), |
| 149 | kCompressStored); |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 150 | |
| 151 | ZipArchiveHandle zip; |
| 152 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 153 | std::vector<std::string> compatibility_info; |
| 154 | compatibility_info.push_back(malformed_xml); |
| 155 | // Malformed compatibility zip is expected to be rejected by libvintf. But we defer that to |
| 156 | // libvintf. |
| 157 | std::string err; |
| 158 | bool result = |
| 159 | android::vintf::VintfObjectRecovery::CheckCompatibility(compatibility_info, &err) == 0; |
| 160 | ASSERT_EQ(result, verify_package_compatibility(zip)); |
| 161 | CloseArchive(zip); |
| 162 | } |
| 163 | |
| 164 | TEST(InstallTest, verify_package_compatibility_with_libvintf_system_manifest_xml) { |
| 165 | static constexpr const char* system_manifest_xml_path = "/system/manifest.xml"; |
| 166 | if (access(system_manifest_xml_path, R_OK) == -1) { |
| 167 | GTEST_LOG_(INFO) << "Test skipped on devices w/o /system/manifest.xml."; |
| 168 | return; |
| 169 | } |
| 170 | std::string system_manifest_xml_content; |
| 171 | ASSERT_TRUE( |
| 172 | android::base::ReadFileToString(system_manifest_xml_path, &system_manifest_xml_content)); |
| 173 | TemporaryFile compatibility_zip_file; |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 174 | BuildZipArchive({ { "system_manifest.xml", system_manifest_xml_content } }, |
| 175 | compatibility_zip_file.release(), kCompressDeflated); |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 176 | |
| 177 | TemporaryFile temp_file; |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 178 | std::string compatibility_zip_content; |
| 179 | ASSERT_TRUE( |
| 180 | android::base::ReadFileToString(compatibility_zip_file.path, &compatibility_zip_content)); |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 181 | BuildZipArchive({ { "compatibility.zip", compatibility_zip_content } }, temp_file.release(), |
| 182 | kCompressStored); |
Tao Bao | f2784b6 | 2017-04-19 12:37:12 -0700 | [diff] [blame] | 183 | |
| 184 | ZipArchiveHandle zip; |
| 185 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 186 | std::vector<std::string> compatibility_info; |
| 187 | compatibility_info.push_back(system_manifest_xml_content); |
| 188 | std::string err; |
| 189 | bool result = |
| 190 | android::vintf::VintfObjectRecovery::CheckCompatibility(compatibility_info, &err) == 0; |
| 191 | // Make sure the result is consistent with libvintf library. |
| 192 | ASSERT_EQ(result, verify_package_compatibility(zip)); |
| 193 | CloseArchive(zip); |
| 194 | } |
| 195 | |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 196 | TEST(InstallTest, SetUpNonAbUpdateCommands) { |
| 197 | TemporaryFile temp_file; |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 198 | static constexpr const char* UPDATE_BINARY_NAME = "META-INF/com/google/android/update-binary"; |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 199 | BuildZipArchive({ { UPDATE_BINARY_NAME, "" } }, temp_file.release(), kCompressStored); |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 200 | |
| 201 | ZipArchiveHandle zip; |
| 202 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 203 | int status_fd = 10; |
| 204 | std::string package = "/path/to/update.zip"; |
| 205 | TemporaryDir td; |
| 206 | std::string binary_path = std::string(td.path) + "/update_binary"; |
| 207 | Paths::Get().set_temporary_update_binary(binary_path); |
| 208 | std::vector<std::string> cmd; |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 209 | ASSERT_TRUE(SetUpNonAbUpdateCommands(package, zip, 0, status_fd, &cmd)); |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 210 | ASSERT_EQ(4U, cmd.size()); |
| 211 | ASSERT_EQ(binary_path, cmd[0]); |
| 212 | ASSERT_EQ("3", cmd[1]); // RECOVERY_API_VERSION |
| 213 | ASSERT_EQ(std::to_string(status_fd), cmd[2]); |
| 214 | ASSERT_EQ(package, cmd[3]); |
| 215 | struct stat sb; |
| 216 | ASSERT_EQ(0, stat(binary_path.c_str(), &sb)); |
| 217 | ASSERT_EQ(static_cast<mode_t>(0755), sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)); |
| 218 | |
| 219 | // With non-zero retry count. update_binary will be removed automatically. |
| 220 | cmd.clear(); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 221 | ASSERT_TRUE(SetUpNonAbUpdateCommands(package, zip, 2, status_fd, &cmd)); |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 222 | ASSERT_EQ(5U, cmd.size()); |
| 223 | ASSERT_EQ(binary_path, cmd[0]); |
| 224 | ASSERT_EQ("3", cmd[1]); // RECOVERY_API_VERSION |
| 225 | ASSERT_EQ(std::to_string(status_fd), cmd[2]); |
| 226 | ASSERT_EQ(package, cmd[3]); |
| 227 | ASSERT_EQ("retry", cmd[4]); |
| 228 | sb = {}; |
| 229 | ASSERT_EQ(0, stat(binary_path.c_str(), &sb)); |
| 230 | ASSERT_EQ(static_cast<mode_t>(0755), sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)); |
| 231 | |
| 232 | CloseArchive(zip); |
| 233 | } |
| 234 | |
| 235 | TEST(InstallTest, SetUpNonAbUpdateCommands_MissingUpdateBinary) { |
| 236 | TemporaryFile temp_file; |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 237 | // The archive must have something to be opened correctly. |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 238 | BuildZipArchive({ { "dummy_entry", "" } }, temp_file.release(), kCompressStored); |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 239 | |
| 240 | // Missing update binary. |
| 241 | ZipArchiveHandle zip; |
| 242 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 243 | int status_fd = 10; |
| 244 | std::string package = "/path/to/update.zip"; |
| 245 | TemporaryDir td; |
| 246 | Paths::Get().set_temporary_update_binary(std::string(td.path) + "/update_binary"); |
| 247 | std::vector<std::string> cmd; |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 248 | ASSERT_FALSE(SetUpNonAbUpdateCommands(package, zip, 0, status_fd, &cmd)); |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 249 | CloseArchive(zip); |
| 250 | } |
| 251 | |
| 252 | static void VerifyAbUpdateCommands(const std::string& serialno, bool success = true) { |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 253 | TemporaryFile temp_file; |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 254 | |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 255 | const std::string properties = "some_properties"; |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 256 | std::string device = android::base::GetProperty("ro.product.device", ""); |
| 257 | ASSERT_NE("", device); |
| 258 | std::string timestamp = android::base::GetProperty("ro.build.date.utc", ""); |
| 259 | ASSERT_NE("", timestamp); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 260 | |
| 261 | std::vector<std::string> meta{ "ota-type=AB", "pre-device=" + device, |
| 262 | "post-timestamp=" + timestamp }; |
| 263 | if (!serialno.empty()) { |
| 264 | meta.push_back("serialno=" + serialno); |
| 265 | } |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 266 | std::string metadata_string = android::base::Join(meta, "\n"); |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 267 | |
| 268 | BuildZipArchive({ { "payload.bin", "" }, |
| 269 | { "payload_properties.txt", properties }, |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 270 | { "META-INF/com/android/metadata", metadata_string } }, |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 271 | temp_file.release(), kCompressStored); |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 272 | |
| 273 | ZipArchiveHandle zip; |
| 274 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
Tao Bao | 00d5757 | 2017-05-02 15:48:54 -0700 | [diff] [blame] | 275 | ZipEntry payload_entry; |
Elliott Hughes | a86dddb | 2019-05-03 22:52:37 -0700 | [diff] [blame] | 276 | ASSERT_EQ(0, FindEntry(zip, "payload.bin", &payload_entry)); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 277 | |
| 278 | std::map<std::string, std::string> metadata; |
| 279 | ASSERT_TRUE(ReadMetadataFromPackage(zip, &metadata)); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 280 | if (success) { |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 281 | ASSERT_TRUE(CheckPackageMetadata(metadata, OtaType::AB)); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 282 | |
| 283 | int status_fd = 10; |
| 284 | std::string package = "/path/to/update.zip"; |
| 285 | std::vector<std::string> cmd; |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 286 | ASSERT_TRUE(SetUpAbUpdateCommands(package, zip, status_fd, &cmd)); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 287 | ASSERT_EQ(5U, cmd.size()); |
Tao Bao | 2cc9bbb | 2018-08-14 12:34:46 -0700 | [diff] [blame] | 288 | ASSERT_EQ("/system/bin/update_engine_sideload", cmd[0]); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 289 | ASSERT_EQ("--payload=file://" + package, cmd[1]); |
| 290 | ASSERT_EQ("--offset=" + std::to_string(payload_entry.offset), cmd[2]); |
| 291 | ASSERT_EQ("--headers=" + properties, cmd[3]); |
| 292 | ASSERT_EQ("--status_fd=" + std::to_string(status_fd), cmd[4]); |
| 293 | } else { |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 294 | ASSERT_FALSE(CheckPackageMetadata(metadata, OtaType::AB)); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 295 | } |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 296 | CloseArchive(zip); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 297 | } |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 298 | |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 299 | TEST(InstallTest, SetUpAbUpdateCommands) { |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 300 | // Empty serialno will pass the verification. |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 301 | VerifyAbUpdateCommands({}); |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 304 | TEST(InstallTest, SetUpAbUpdateCommands_MissingPayloadPropertiesTxt) { |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 305 | TemporaryFile temp_file; |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 306 | |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 307 | std::string device = android::base::GetProperty("ro.product.device", ""); |
| 308 | ASSERT_NE("", device); |
| 309 | std::string timestamp = android::base::GetProperty("ro.build.date.utc", ""); |
| 310 | ASSERT_NE("", timestamp); |
| 311 | std::string metadata = android::base::Join( |
| 312 | std::vector<std::string>{ |
| 313 | "ota-type=AB", "pre-device=" + device, "post-timestamp=" + timestamp, |
| 314 | }, |
| 315 | "\n"); |
Tianjie Xu | f2fb49a | 2018-10-26 15:16:50 -0700 | [diff] [blame] | 316 | |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 317 | BuildZipArchive( |
| 318 | { |
| 319 | { "payload.bin", "" }, |
| 320 | { "META-INF/com/android/metadata", metadata }, |
| 321 | }, |
| 322 | temp_file.release(), kCompressStored); |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 323 | |
| 324 | ZipArchiveHandle zip; |
| 325 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 326 | int status_fd = 10; |
Tao Bao | 00d5757 | 2017-05-02 15:48:54 -0700 | [diff] [blame] | 327 | std::string package = "/path/to/update.zip"; |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 328 | std::vector<std::string> cmd; |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 329 | ASSERT_FALSE(SetUpAbUpdateCommands(package, zip, status_fd, &cmd)); |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 330 | CloseArchive(zip); |
Tao Bao | bc4b1fe | 2017-04-17 16:46:05 -0700 | [diff] [blame] | 331 | } |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 332 | |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 333 | TEST(InstallTest, SetUpAbUpdateCommands_MultipleSerialnos) { |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 334 | std::string serialno = android::base::GetProperty("ro.serialno", ""); |
| 335 | ASSERT_NE("", serialno); |
| 336 | |
| 337 | // Single matching serialno will pass the verification. |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 338 | VerifyAbUpdateCommands(serialno); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 339 | |
| 340 | static constexpr char alphabet[] = |
| 341 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
| 342 | auto generator = []() { return alphabet[rand() % (sizeof(alphabet) - 1)]; }; |
| 343 | |
| 344 | // Generate 900 random serial numbers. |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 345 | std::string random_serialno; |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 346 | for (size_t i = 0; i < 900; i++) { |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 347 | generate_n(back_inserter(random_serialno), serialno.size(), generator); |
| 348 | random_serialno.append("|"); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 349 | } |
| 350 | // Random serialnos should fail the verification. |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 351 | VerifyAbUpdateCommands(random_serialno, false); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 352 | |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 353 | std::string long_serialno = random_serialno + serialno + "|"; |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 354 | for (size_t i = 0; i < 99; i++) { |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 355 | generate_n(back_inserter(long_serialno), serialno.size(), generator); |
| 356 | long_serialno.append("|"); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 357 | } |
| 358 | // String with the matching serialno should pass the verification. |
Tao Bao | cf60a44 | 2018-06-18 14:56:20 -0700 | [diff] [blame] | 359 | VerifyAbUpdateCommands(long_serialno); |
Tianjie Xu | 69b9649 | 2017-08-17 16:42:57 -0700 | [diff] [blame] | 360 | } |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 361 | |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 362 | static void TestCheckPackageMetadata(const std::string& metadata_string, OtaType ota_type, |
| 363 | bool exptected_result) { |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 364 | TemporaryFile temp_file; |
| 365 | BuildZipArchive( |
| 366 | { |
| 367 | { "META-INF/com/android/metadata", metadata_string }, |
| 368 | }, |
| 369 | temp_file.release(), kCompressStored); |
| 370 | |
| 371 | ZipArchiveHandle zip; |
| 372 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 373 | |
| 374 | std::map<std::string, std::string> metadata; |
| 375 | ASSERT_TRUE(ReadMetadataFromPackage(zip, &metadata)); |
| 376 | ASSERT_EQ(exptected_result, CheckPackageMetadata(metadata, ota_type)); |
| 377 | CloseArchive(zip); |
| 378 | } |
| 379 | |
| 380 | TEST(InstallTest, CheckPackageMetadata_ota_type) { |
| 381 | std::string device = android::base::GetProperty("ro.product.device", ""); |
| 382 | ASSERT_NE("", device); |
| 383 | |
| 384 | // ota-type must be present |
| 385 | std::string metadata = android::base::Join( |
| 386 | std::vector<std::string>{ |
| 387 | "pre-device=" + device, |
| 388 | "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), |
| 389 | }, |
| 390 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 391 | TestCheckPackageMetadata(metadata, OtaType::AB, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 392 | |
| 393 | // Checks if ota-type matches |
| 394 | metadata = android::base::Join( |
| 395 | std::vector<std::string>{ |
| 396 | "ota-type=AB", |
| 397 | "pre-device=" + device, |
| 398 | "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), |
| 399 | }, |
| 400 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 401 | TestCheckPackageMetadata(metadata, OtaType::AB, true); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 402 | |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 403 | TestCheckPackageMetadata(metadata, OtaType::BRICK, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | TEST(InstallTest, CheckPackageMetadata_device_type) { |
| 407 | // device type can not be empty |
| 408 | std::string metadata = android::base::Join( |
| 409 | std::vector<std::string>{ |
| 410 | "ota-type=BRICK", |
| 411 | }, |
| 412 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 413 | TestCheckPackageMetadata(metadata, OtaType::BRICK, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 414 | |
| 415 | // device type mismatches |
| 416 | metadata = android::base::Join( |
| 417 | std::vector<std::string>{ |
| 418 | "ota-type=BRICK", |
| 419 | "pre-device=dummy_device_type", |
| 420 | }, |
| 421 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 422 | TestCheckPackageMetadata(metadata, OtaType::BRICK, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | TEST(InstallTest, CheckPackageMetadata_serial_number_smoke) { |
| 426 | std::string device = android::base::GetProperty("ro.product.device", ""); |
| 427 | ASSERT_NE("", device); |
| 428 | |
| 429 | // Serial number doesn't need to exist |
| 430 | std::string metadata = android::base::Join( |
| 431 | std::vector<std::string>{ |
| 432 | "ota-type=BRICK", |
| 433 | "pre-device=" + device, |
| 434 | }, |
| 435 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 436 | TestCheckPackageMetadata(metadata, OtaType::BRICK, true); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 437 | |
| 438 | // Serial number mismatches |
| 439 | metadata = android::base::Join( |
| 440 | std::vector<std::string>{ |
| 441 | "ota-type=BRICK", |
| 442 | "pre-device=" + device, |
| 443 | "serialno=dummy_serial", |
| 444 | }, |
| 445 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 446 | TestCheckPackageMetadata(metadata, OtaType::BRICK, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 447 | |
| 448 | std::string serialno = android::base::GetProperty("ro.serialno", ""); |
| 449 | ASSERT_NE("", serialno); |
| 450 | metadata = android::base::Join( |
| 451 | std::vector<std::string>{ |
| 452 | "ota-type=BRICK", |
| 453 | "pre-device=" + device, |
| 454 | "serialno=" + serialno, |
| 455 | }, |
| 456 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 457 | TestCheckPackageMetadata(metadata, OtaType::BRICK, true); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | TEST(InstallTest, CheckPackageMetadata_multiple_serial_number) { |
| 461 | std::string device = android::base::GetProperty("ro.product.device", ""); |
| 462 | ASSERT_NE("", device); |
| 463 | |
| 464 | std::string serialno = android::base::GetProperty("ro.serialno", ""); |
| 465 | ASSERT_NE("", serialno); |
| 466 | |
| 467 | std::vector<std::string> serial_numbers; |
| 468 | // Creates a dummy serial number string. |
xunchang | 7b08a5a | 2019-02-05 12:44:53 -0800 | [diff] [blame] | 469 | for (char c = 'a'; c <= 'z'; c++) { |
| 470 | serial_numbers.emplace_back(serialno.size(), c); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | // No matched serialno found. |
| 474 | std::string metadata = android::base::Join( |
| 475 | std::vector<std::string>{ |
| 476 | "ota-type=BRICK", |
| 477 | "pre-device=" + device, |
| 478 | "serialno=" + android::base::Join(serial_numbers, '|'), |
| 479 | }, |
| 480 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 481 | TestCheckPackageMetadata(metadata, OtaType::BRICK, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 482 | |
| 483 | serial_numbers.emplace_back(serialno); |
| 484 | std::shuffle(serial_numbers.begin(), serial_numbers.end(), std::default_random_engine()); |
| 485 | metadata = android::base::Join( |
| 486 | std::vector<std::string>{ |
| 487 | "ota-type=BRICK", |
| 488 | "pre-device=" + device, |
| 489 | "serialno=" + android::base::Join(serial_numbers, '|'), |
| 490 | }, |
| 491 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 492 | TestCheckPackageMetadata(metadata, OtaType::BRICK, true); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | TEST(InstallTest, CheckPackageMetadata_ab_build_version) { |
| 496 | std::string device = android::base::GetProperty("ro.product.device", ""); |
| 497 | ASSERT_NE("", device); |
| 498 | |
| 499 | std::string build_version = android::base::GetProperty("ro.build.version.incremental", ""); |
| 500 | ASSERT_NE("", build_version); |
| 501 | |
| 502 | std::string metadata = android::base::Join( |
| 503 | std::vector<std::string>{ |
| 504 | "ota-type=AB", |
| 505 | "pre-device=" + device, |
| 506 | "pre-build-incremental=" + build_version, |
| 507 | "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), |
| 508 | }, |
| 509 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 510 | TestCheckPackageMetadata(metadata, OtaType::AB, true); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 511 | |
| 512 | metadata = android::base::Join( |
| 513 | std::vector<std::string>{ |
| 514 | "ota-type=AB", |
| 515 | "pre-device=" + device, |
| 516 | "pre-build-incremental=dummy_build", |
| 517 | "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), |
| 518 | }, |
| 519 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 520 | TestCheckPackageMetadata(metadata, OtaType::AB, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | TEST(InstallTest, CheckPackageMetadata_ab_fingerprint) { |
| 524 | std::string device = android::base::GetProperty("ro.product.device", ""); |
| 525 | ASSERT_NE("", device); |
| 526 | |
| 527 | std::string finger_print = android::base::GetProperty("ro.build.fingerprint", ""); |
| 528 | ASSERT_NE("", finger_print); |
| 529 | |
| 530 | std::string metadata = android::base::Join( |
| 531 | std::vector<std::string>{ |
| 532 | "ota-type=AB", |
| 533 | "pre-device=" + device, |
| 534 | "pre-build=" + finger_print, |
| 535 | "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), |
| 536 | }, |
| 537 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 538 | TestCheckPackageMetadata(metadata, OtaType::AB, true); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 539 | |
| 540 | metadata = android::base::Join( |
| 541 | std::vector<std::string>{ |
| 542 | "ota-type=AB", |
| 543 | "pre-device=" + device, |
| 544 | "pre-build=dummy_build_fingerprint", |
| 545 | "post-timestamp=" + std::to_string(std::numeric_limits<int64_t>::max()), |
| 546 | }, |
| 547 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 548 | TestCheckPackageMetadata(metadata, OtaType::AB, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | TEST(InstallTest, CheckPackageMetadata_ab_post_timestamp) { |
| 552 | std::string device = android::base::GetProperty("ro.product.device", ""); |
| 553 | ASSERT_NE("", device); |
| 554 | |
| 555 | // post timestamp is required for upgrade. |
| 556 | std::string metadata = android::base::Join( |
| 557 | std::vector<std::string>{ |
| 558 | "ota-type=AB", |
| 559 | "pre-device=" + device, |
| 560 | }, |
| 561 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 562 | TestCheckPackageMetadata(metadata, OtaType::AB, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 563 | |
| 564 | // post timestamp should be larger than the timestamp on device. |
| 565 | metadata = android::base::Join( |
| 566 | std::vector<std::string>{ |
| 567 | "ota-type=AB", |
| 568 | "pre-device=" + device, |
| 569 | "post-timestamp=0", |
| 570 | }, |
| 571 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 572 | TestCheckPackageMetadata(metadata, OtaType::AB, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 573 | |
| 574 | // fingerprint is required for downgrade |
| 575 | metadata = android::base::Join( |
| 576 | std::vector<std::string>{ |
| 577 | "ota-type=AB", |
| 578 | "pre-device=" + device, |
| 579 | "post-timestamp=0", |
| 580 | "ota-downgrade=yes", |
| 581 | }, |
| 582 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 583 | TestCheckPackageMetadata(metadata, OtaType::AB, false); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 584 | |
| 585 | std::string finger_print = android::base::GetProperty("ro.build.fingerprint", ""); |
| 586 | ASSERT_NE("", finger_print); |
| 587 | |
| 588 | metadata = android::base::Join( |
| 589 | std::vector<std::string>{ |
| 590 | "ota-type=AB", |
| 591 | "pre-device=" + device, |
| 592 | "post-timestamp=0", |
| 593 | "pre-build=" + finger_print, |
| 594 | "ota-downgrade=yes", |
| 595 | }, |
| 596 | "\n"); |
Tao Bao | 36c7276 | 2019-04-30 00:25:41 -0700 | [diff] [blame] | 597 | TestCheckPackageMetadata(metadata, OtaType::AB, true); |
Tianjie Xu | 93b5bf2 | 2018-10-25 10:39:01 -0700 | [diff] [blame] | 598 | } |
Tianjie Xu | 58a2769 | 2019-08-06 12:32:05 -0700 | [diff] [blame] | 599 | |
| 600 | TEST(InstallTest, SetupPackageMount_package_path) { |
| 601 | load_volume_table(); |
| 602 | bool install_with_fuse; |
| 603 | |
| 604 | // Setup should fail if the input path doesn't exist. |
| 605 | ASSERT_FALSE(SetupPackageMount("/does_not_exist", &install_with_fuse)); |
| 606 | |
| 607 | // Package should be installed with fuse if it's not in /cache. |
| 608 | TemporaryDir temp_dir; |
| 609 | TemporaryFile update_package(temp_dir.path); |
| 610 | ASSERT_TRUE(SetupPackageMount(update_package.path, &install_with_fuse)); |
| 611 | ASSERT_TRUE(install_with_fuse); |
| 612 | |
| 613 | // Setup should fail if the input path isn't canonicalized. |
| 614 | std::string uncanonical_package_path = android::base::Join( |
| 615 | std::vector<std::string>{ |
| 616 | temp_dir.path, |
| 617 | "..", |
| 618 | android::base::Basename(temp_dir.path), |
| 619 | android::base::Basename(update_package.path), |
| 620 | }, |
| 621 | '/'); |
| 622 | |
| 623 | ASSERT_EQ(0, access(uncanonical_package_path.c_str(), R_OK)); |
| 624 | ASSERT_FALSE(SetupPackageMount(uncanonical_package_path, &install_with_fuse)); |
| 625 | } |