-
Notifications
You must be signed in to change notification settings - Fork 1
/
manifest_test.cc
241 lines (229 loc) · 8.94 KB
/
manifest_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Copyright 2018 The Chromium OS 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 <gtest/gtest.h>
#include "imageloader/manifest.h"
namespace imageloader {
TEST(ManifestTest, ParseManifest) {
const std::string fs_type = R"("ext4")";
const std::string is_removable = R"(true)";
const std::string image_sha256_hash =
R"("4CF41BD11362CCB4707FB93939DBB5AC48745EDFC9DC8D7702852FFAA81B3B3F")";
const std::string table_sha256_hash =
R"("0E11DA3D7140C6B95496787F50D15152434EBA22B60443BFA7E054FF4C799276")";
const std::string version = R"("9824.0.4")";
const std::string id = R"("foo")";
const std::string name = R"("bar")";
const std::string image_type = R"("dlc")";
const std::string preallocated_size = R"("600613")";
const std::string size = R"("42")";
const std::string preload_allowed = R"(true)";
const std::string used_by = R"("foo-user")";
const std::string mount_file_required = R"(true)";
const std::string description = R"("foo-description")";
const std::string manifest_version = R"(1)";
const std::string manifest_raw = std::string() + R"(
{
"description":)" + description +
R"(,
"fs-type":)" + fs_type + R"(,
"id":)" + id + R"(,
"image-sha256-hash":)" + image_sha256_hash +
R"(,
"image-type":)" + image_type + R"(,
"is-removable":)" + is_removable +
R"(,
"manifest-version":)" + manifest_version +
R"(,
"mount-file-required":)" + mount_file_required +
R"(,
"name":)" + name + R"(,
"pre-allocated-size":)" + preallocated_size +
R"(,
"preload-allowed":)" + preload_allowed +
R"(,
"size":)" + size + R"(,
"table-sha256-hash":)" + table_sha256_hash +
R"(,
"used-by":)" + used_by + R"(,
"version":)" + version + R"(
}
)";
Manifest manifest;
// Parse the manifest raw string.
ASSERT_TRUE(manifest.ParseManifest(manifest_raw));
EXPECT_EQ(manifest.fs_type(), FileSystem::kExt4);
EXPECT_EQ(manifest.is_removable(), true);
EXPECT_NE(manifest.image_sha256().size(), 0);
EXPECT_NE(manifest.table_sha256().size(), 0);
EXPECT_NE(manifest.version().size(), 0);
EXPECT_EQ(manifest.manifest_version(), 1);
EXPECT_EQ(manifest.id(), "foo");
EXPECT_EQ(manifest.name(), "bar");
EXPECT_EQ(manifest.image_type(), "dlc");
EXPECT_EQ(manifest.preallocated_size(), 600613);
EXPECT_EQ(manifest.size(), 42);
EXPECT_EQ(manifest.preload_allowed(), true);
EXPECT_EQ(manifest.used_by(), "foo-user");
EXPECT_EQ(manifest.mount_file_required(), true);
EXPECT_EQ(manifest.description(), "foo-description");
}
TEST(ManifestTest, ParseManifestNoOptional) {
const std::string is_removable = R"(true)";
const std::string image_sha256_hash =
R"("4CF41BD11362CCB4707FB93939DBB5AC48745EDFC9DC8D7702852FFAA81B3B3F")";
const std::string table_sha256_hash =
R"("0E11DA3D7140C6B95496787F50D15152434EBA22B60443BFA7E054FF4C799276")";
const std::string version = R"("9824.0.4")";
const std::string manifest_version = R"(1)";
const std::string manifest_raw = std::string() + R"(
{
"is-removable":)" + is_removable +
R"(,
"image-sha256-hash":)" + image_sha256_hash +
R"(,
"table-sha256-hash":)" + table_sha256_hash +
R"(,
"version":)" + version + R"(,
"manifest-version":)" + manifest_version +
R"(
}
)";
Manifest manifest;
// Parse the manifest raw string.
ASSERT_TRUE(manifest.ParseManifest(manifest_raw));
// Should default to squashfs.
EXPECT_EQ(manifest.fs_type(), FileSystem::kSquashFS);
EXPECT_EQ(manifest.is_removable(), true);
EXPECT_NE(manifest.image_sha256().size(), 0);
EXPECT_NE(manifest.table_sha256().size(), 0);
EXPECT_NE(manifest.version().size(), 0);
EXPECT_EQ(manifest.manifest_version(), 1);
EXPECT_EQ(manifest.preload_allowed(), false);
EXPECT_EQ(manifest.used_by(), "");
EXPECT_EQ(manifest.description(), "");
// Sizes should default to 0.
EXPECT_EQ(manifest.preallocated_size(), 0);
EXPECT_EQ(manifest.size(), 0);
}
TEST(ManifestTest, ParseManifestNoImageHash) {
const std::string is_removable = R"(true)";
const std::string table_sha256_hash =
R"("0E11DA3D7140C6B95496787F50D15152434EBA22B60443BFA7E054FF4C799276")";
const std::string version = R"("9824.0.4")";
const std::string manifest_version = R"(1)";
const std::string manifest_raw = std::string() + R"(
{
"is-removable":)" + is_removable +
R"(,
"table-sha256-hash":)" + table_sha256_hash +
R"(,
"version":)" + version + R"(,
"manifest-version":)" + manifest_version +
R"(
}
)";
Manifest manifest;
// Parse the manifest raw string.
ASSERT_FALSE(manifest.ParseManifest(manifest_raw));
}
TEST(ManifestTest, ParseManifestNoTableHash) {
const std::string is_removable = R"(true)";
const std::string image_sha256_hash =
R"("4CF41BD11362CCB4707FB93939DBB5AC48745EDFC9DC8D7702852FFAA81B3B3F")";
const std::string version = R"("9824.0.4")";
const std::string manifest_version = R"(1)";
const std::string manifest_raw = std::string() + R"(
{
"is-removable":)" + is_removable +
R"(,
"image-sha256-hash":)" + image_sha256_hash +
R"(,
"version":)" + version + R"(,
"manifest-version":)" + manifest_version +
R"(
}
)";
Manifest manifest;
// Parse the manifest raw string.
ASSERT_FALSE(manifest.ParseManifest(manifest_raw));
}
TEST(ManifestTest, ParseManifestNoVersion) {
const std::string is_removable = R"(true)";
const std::string image_sha256_hash =
R"("4CF41BD11362CCB4707FB93939DBB5AC48745EDFC9DC8D7702852FFAA81B3B3F")";
const std::string table_sha256_hash =
R"("0E11DA3D7140C6B95496787F50D15152434EBA22B60443BFA7E054FF4C799276")";
const std::string manifest_version = R"(1)";
const std::string manifest_raw = std::string() + R"(
{
"is-removable":)" + is_removable +
R"(,
"image-sha256-hash":)" + image_sha256_hash +
R"(,
"table-sha256-hash":)" + table_sha256_hash +
R"(,
"manifest-version":)" + manifest_version +
R"(
}
)";
Manifest manifest;
// Parse the manifest raw string.
ASSERT_FALSE(manifest.ParseManifest(manifest_raw));
}
TEST(ManifestTest, ParseManifestBadPreallocatedSize) {
const std::string is_removable = R"(true)";
const std::string image_sha256_hash =
R"("4CF41BD11362CCB4707FB93939DBB5AC48745EDFC9DC8D7702852FFAA81B3B3F")";
const std::string table_sha256_hash =
R"("0E11DA3D7140C6B95496787F50D15152434EBA22B60443BFA7E054FF4C799276")";
const std::string version = R"("9824.0.4")";
const std::string manifest_version = R"(1)";
const std::string pre_allocated_size = R"("not a number")";
const std::string manifest_raw = std::string() + R"(
{
"is-removable":)" + is_removable +
R"(,
"image-sha256-hash":)" + image_sha256_hash +
R"(,
"table-sha256-hash":)" + table_sha256_hash +
R"(,
"version":)" + version + R"(,
"manifest-version":)" + manifest_version +
R"(,
"pre-allocated-size":)" + pre_allocated_size +
R"(
}
)";
Manifest manifest;
// Parse the manifest raw string.
ASSERT_FALSE(manifest.ParseManifest(manifest_raw));
}
TEST(ManifestTest, ParseManifestBadSize) {
const std::string is_removable = R"(true)";
const std::string image_sha256_hash =
R"("4CF41BD11362CCB4707FB93939DBB5AC48745EDFC9DC8D7702852FFAA81B3B3F")";
const std::string table_sha256_hash =
R"("0E11DA3D7140C6B95496787F50D15152434EBA22B60443BFA7E054FF4C799276")";
const std::string version = R"("9824.0.4")";
const std::string manifest_version = R"(1)";
const std::string size = R"("not a number")";
const std::string manifest_raw = std::string() + R"(
{
"is-removable":)" + is_removable +
R"(,
"image-sha256-hash":)" + image_sha256_hash +
R"(,
"table-sha256-hash":)" + table_sha256_hash +
R"(,
"version":)" + version + R"(,
"manifest-version":)" + manifest_version +
R"(,
"size":)" + size + R"(
}
)";
Manifest manifest;
// Parse the manifest raw string.
ASSERT_FALSE(manifest.ParseManifest(manifest_raw));
}
} // namespace imageloader