@@ -130,12 +130,12 @@ test_raw_file_to_archive_stream (gconstpointer data)
130
130
}
131
131
132
132
static gboolean
133
- hi_content_stream_new (GInputStream * * out_stream , guint64 * out_length , GError * * error )
133
+ basic_regfile_content_stream_new (const char * contents , GVariant * xattr , GInputStream * * out_stream ,
134
+ guint64 * out_length , GError * * error )
134
135
{
135
- static const char hi [] = "hi" ;
136
- const size_t len = sizeof (hi ) - 1 ;
136
+ const size_t len = strlen (contents );
137
137
g_autoptr (GMemoryInputStream ) hi_memstream
138
- = (GMemoryInputStream * )g_memory_input_stream_new_from_data (hi , len , NULL );
138
+ = (GMemoryInputStream * )g_memory_input_stream_new_from_data (contents , len , NULL );
139
139
g_autoptr (GFileInfo ) finfo = g_file_info_new ();
140
140
g_file_info_set_attribute_uint32 (finfo , "standard::type" , G_FILE_TYPE_REGULAR );
141
141
g_file_info_set_attribute_boolean (finfo , "standard::is-symlink" , FALSE);
@@ -147,6 +147,12 @@ hi_content_stream_new (GInputStream **out_stream, guint64 *out_length, GError **
147
147
out_length , NULL , error );
148
148
}
149
149
150
+ static gboolean
151
+ hi_content_stream_new (GInputStream * * out_stream , guint64 * out_length , GError * * error )
152
+ {
153
+ return basic_regfile_content_stream_new ("hi" , NULL , out_stream , out_length , error );
154
+ }
155
+
150
156
static void
151
157
test_validate_remotename (void )
152
158
{
@@ -174,6 +180,8 @@ test_object_writes (gconstpointer data)
174
180
175
181
static const char hi_sha256 []
176
182
= "2301b5923720c3edc1f0467addb5c287fd5559e3e0cd1396e7f1edb6b01be9f0" ;
183
+ static const char invalid_hi_sha256 []
184
+ = "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe" ;
177
185
178
186
/* Successful content write */
179
187
{
@@ -193,12 +201,68 @@ test_object_writes (gconstpointer data)
193
201
hi_content_stream_new (& hi_memstream , & len , & error );
194
202
g_assert_no_error (error );
195
203
g_autofree guchar * csum = NULL ;
196
- static const char invalid_hi_sha256 []
197
- = "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe" ;
198
204
g_assert (!ostree_repo_write_content (repo , invalid_hi_sha256 , hi_memstream , len , & csum , NULL ,
199
205
& error ));
200
206
g_assert (error );
201
207
g_assert (strstr (error -> message , "Corrupted file object" ));
208
+ g_clear_error (& error );
209
+ }
210
+
211
+ /* Test a basic regfile inline write, no xattrs */
212
+ g_assert (ostree_repo_write_regfile_inline (repo , hi_sha256 , 0 , 0 , S_IFREG | 0644 , NULL ,
213
+ (guint8 * )"hi" , 2 , NULL , & error ));
214
+ g_assert_no_error (error );
215
+
216
+ /* Test a basic regfile inline write, erroring on checksum */
217
+ g_assert (!ostree_repo_write_regfile_inline (repo , invalid_hi_sha256 , 0 , 0 , S_IFREG | 0644 , NULL ,
218
+ (guint8 * )"hi" , 2 , NULL , & error ));
219
+ g_assert (error != NULL );
220
+ g_clear_error (& error );
221
+
222
+ static const char expected_sha256_with_xattrs []
223
+ = "72473a9e8ace75f89f1504137cfb134feb5372bc1d97e04eb5300e24ad836153" ;
224
+
225
+ GVariantBuilder builder ;
226
+ g_variant_builder_init (& builder , G_VARIANT_TYPE ("a(ayay)" ));
227
+ g_variant_builder_add (& builder , "(^ay^ay)" , "security.selinux" , "foo_t" );
228
+ g_variant_builder_add (& builder , "(^ay^ay)" , "user.blah" , "somedata" );
229
+ g_autoptr (GVariant ) inorder_xattrs = g_variant_ref_sink (g_variant_builder_end (& builder ));
230
+ g_variant_builder_init (& builder , G_VARIANT_TYPE ("a(ayay)" ));
231
+ g_variant_builder_add (& builder , "(^ay^ay)" , "user.blah" , "somedata" );
232
+ g_variant_builder_add (& builder , "(^ay^ay)" , "security.selinux" , "foo_t" );
233
+ g_autoptr (GVariant ) unsorted_xattrs = g_variant_ref_sink (g_variant_builder_end (& builder ));
234
+
235
+ /* Now test with xattrs */
236
+ g_assert (ostree_repo_write_regfile_inline (repo , expected_sha256_with_xattrs , 0 , 0 ,
237
+ S_IFREG | 0644 , inorder_xattrs , (guint8 * )"hi" , 2 ,
238
+ NULL , & error ));
239
+ g_assert_no_error (error );
240
+
241
+ /* And now with a swapped order */
242
+ g_assert (ostree_repo_write_regfile_inline (repo , expected_sha256_with_xattrs , 0 , 0 ,
243
+ S_IFREG | 0644 , unsorted_xattrs , (guint8 * )"hi" , 2 ,
244
+ NULL , & error ));
245
+ g_assert_no_error (error );
246
+
247
+ /* Tests of directory metadata */
248
+ static const char expected_dirmeta_sha256 []
249
+ = "f773ab98198d8e46f77be6ffff5fc1920888c0af5794426c3b1461131d509f34" ;
250
+ g_autoptr (GFileInfo ) fi = g_file_info_new ();
251
+ g_file_info_set_attribute_uint32 (fi , "unix::uid" , 0 );
252
+ g_file_info_set_attribute_uint32 (fi , "unix::gid" , 0 );
253
+ g_file_info_set_attribute_uint32 (fi , "unix::mode" , (0755 | S_IFDIR ));
254
+ {
255
+ g_autoptr (GVariant ) dirmeta = ostree_create_directory_metadata (fi , inorder_xattrs );
256
+ ostree_repo_write_metadata (repo , OSTREE_OBJECT_TYPE_DIR_META , expected_dirmeta_sha256 , dirmeta ,
257
+ NULL , NULL , & error );
258
+ g_assert_no_error (error );
259
+ }
260
+ /* And now with unsorted xattrs */
261
+ {
262
+ g_autoptr (GVariant ) dirmeta = ostree_create_directory_metadata (fi , unsorted_xattrs );
263
+ ostree_repo_write_metadata (repo , OSTREE_OBJECT_TYPE_DIR_META , expected_dirmeta_sha256 , dirmeta ,
264
+ NULL , NULL , & error );
265
+ g_assert_no_error (error );
202
266
}
203
267
}
204
268
0 commit comments