storj/lib/uplinkc/testdata/object_test.c

144 lines
4.4 KiB
C
Raw Normal View History

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
#include <string.h>
#include <stdlib.h>
#include "require.h"
#include "uplink.h"
#include "helpers.h"
void handle_project(ProjectRef project);
int main(int argc, char *argv[]) {
with_test_project(&handle_project);
}
void handle_project(ProjectRef project) {
char *_err = "";
char **err = &_err;
char *bucket_name = "test-bucket";
lib/uplink: encryption context (#2349) * lib/uplink: encryption context Change-Id: I5c23dca3286a46b713b30c4997e9ae6e630b2280 * lib/uplink: bucket operation examples Change-Id: Ia0f6e69f365dcff0cf11c731f51b30842bce053b * lib/uplink: encryption key sharing test cases Change-Id: I3a172d565f33f4e591402cdcb9460664a7cc7fbe * fix encrypted path prefix restriction issue Change-Id: I8f3921f9d52aaf4b84039de608b8cbbc88769554 * implement panics in libuplink encryption code todo on cipher suite selection as well as an api concern Change-Id: Ifa39eb3cc4b3443f7d96f9304df9b2ac4ec4085d * implement GetProjectInfo api call to get salt Change-Id: Ic5f6b3be9ea35df48c1aa214ab5d355fb328e2cf * some fixes and accessors for encryption store Change-Id: I3bb61f6712a037900e2a96e72ad4029ec1d3f718 * general fixes to builds/tests/etc Change-Id: I9930fa96acb3b221d9a001f8e274af5729cc8a47 * java bindings changes Change-Id: Ia2bd4c9c69739c8d3154d79616cff1f36fb403b6 * get libuplink examples passing Change-Id: I828f09a144160e0a5dd932324f78491ae2ec8a07 * fix proto.lock file Change-Id: I2fbbf4d0976a7d0473c2645e6dcb21aaa3be7651 * fix proto.lock again Change-Id: I92702cf49e1a340eef6379c2be4f7c4a268112a9 * fix golint issues Change-Id: I631ff9f43307a58e3b25a58cbb4a4cc2495f5eb6 * more linting fixes Change-Id: I51f8f30b367b5bca14c94b15417b9a4c9e7aa0ce * bug fixed by structs bump Change-Id: Ibb03c691fce7606c35c08721b3ef0781ab48a38a * retrigger Change-Id: Ieee0470b6a2d07168a1578552e8e7f271ae93a13 * retrigger Change-Id: I753d63853171e6a436c104ce176048892eb974c5 * semantic merge conflict Change-Id: I9419448496de90340569047a6a16a1b858a7978a * update total to match prod defaults Change-Id: I693d55c1ebb28b5803ee1d26e9e198decf82308b * retrigger Change-Id: I28b74d5d6202f61aa3866fe407d423f6a0a14b9e * retrigger Change-Id: I6fd054885c715f602e2cef623fd464c42e88742c * retrigger Change-Id: I6a01bae88c72406d4ed5a8f13bf8a2b3c650bd2d
2019-06-27 18:36:51 +01:00
char *enc_ctx = "12VtN2sbbn9PvaEvNbNUBiSKnRcSUNxBADwDWGsPY7UV85e82tT6u";
char *object_paths[] = {"test-object1","test-object2","test-object3","test-object4"};
int num_of_objects = 4;
// NB: about +500 years from time of writing
int64_t future_expiration_timestamp = 17329017831;
{ // create buckets
BucketConfig config = test_bucket_config();
BucketInfo info = create_bucket(project, bucket_name, &config, err);
require_noerror(*err);
free_bucket_info(&info);
}
// open bucket
lib/uplink: encryption context (#2349) * lib/uplink: encryption context Change-Id: I5c23dca3286a46b713b30c4997e9ae6e630b2280 * lib/uplink: bucket operation examples Change-Id: Ia0f6e69f365dcff0cf11c731f51b30842bce053b * lib/uplink: encryption key sharing test cases Change-Id: I3a172d565f33f4e591402cdcb9460664a7cc7fbe * fix encrypted path prefix restriction issue Change-Id: I8f3921f9d52aaf4b84039de608b8cbbc88769554 * implement panics in libuplink encryption code todo on cipher suite selection as well as an api concern Change-Id: Ifa39eb3cc4b3443f7d96f9304df9b2ac4ec4085d * implement GetProjectInfo api call to get salt Change-Id: Ic5f6b3be9ea35df48c1aa214ab5d355fb328e2cf * some fixes and accessors for encryption store Change-Id: I3bb61f6712a037900e2a96e72ad4029ec1d3f718 * general fixes to builds/tests/etc Change-Id: I9930fa96acb3b221d9a001f8e274af5729cc8a47 * java bindings changes Change-Id: Ia2bd4c9c69739c8d3154d79616cff1f36fb403b6 * get libuplink examples passing Change-Id: I828f09a144160e0a5dd932324f78491ae2ec8a07 * fix proto.lock file Change-Id: I2fbbf4d0976a7d0473c2645e6dcb21aaa3be7651 * fix proto.lock again Change-Id: I92702cf49e1a340eef6379c2be4f7c4a268112a9 * fix golint issues Change-Id: I631ff9f43307a58e3b25a58cbb4a4cc2495f5eb6 * more linting fixes Change-Id: I51f8f30b367b5bca14c94b15417b9a4c9e7aa0ce * bug fixed by structs bump Change-Id: Ibb03c691fce7606c35c08721b3ef0781ab48a38a * retrigger Change-Id: Ieee0470b6a2d07168a1578552e8e7f271ae93a13 * retrigger Change-Id: I753d63853171e6a436c104ce176048892eb974c5 * semantic merge conflict Change-Id: I9419448496de90340569047a6a16a1b858a7978a * update total to match prod defaults Change-Id: I693d55c1ebb28b5803ee1d26e9e198decf82308b * retrigger Change-Id: I28b74d5d6202f61aa3866fe407d423f6a0a14b9e * retrigger Change-Id: I6fd054885c715f602e2cef623fd464c42e88742c * retrigger Change-Id: I6a01bae88c72406d4ed5a8f13bf8a2b3c650bd2d
2019-06-27 18:36:51 +01:00
BucketRef bucket = open_bucket(project, bucket_name, enc_ctx, err);
require_noerror(*err);
for(int i = 0; i < num_of_objects; i++) {
size_t data_len = 1024 * (i + 1) * (i + 1);
uint8_t *data = malloc(data_len);
fill_random_data(data, data_len);
{ // upload
UploadOptions opts = {
"text/plain",
future_expiration_timestamp,
};
UploaderRef uploader = upload(bucket, object_paths[i], &opts, err);
require_noerror(*err);
2019-06-21 19:44:00 +01:00
size_t uploaded_total = 0;
while (uploaded_total < data_len) {
size_t size_to_write = (data_len - uploaded_total > 256) ? 256 : data_len - uploaded_total;
size_t write_size = upload_write(uploader, (uint8_t *)data+uploaded_total, size_to_write, err);
require_noerror(*err);
2019-06-21 19:44:00 +01:00
if (write_size == 0) {
break;
}
2019-06-21 19:44:00 +01:00
uploaded_total += write_size;
}
upload_commit(uploader, err);
require_noerror(*err);
}
2019-06-21 19:44:00 +01:00
{ // object meta
ObjectRef object_ref = open_object(bucket, object_paths[i], err);
require_noerror(*err);
ObjectMeta object_meta = get_object_meta(object_ref, err);
require_noerror(*err);
require(strcmp(object_paths[i], object_meta.path) == 0);
require(data_len == object_meta.size);
require(future_expiration_timestamp == object_meta.expires);
require((time(NULL) - object_meta.created) <= 2);
require((time(NULL) - object_meta.modified) <= 2);
require(object_meta.checksum_bytes != NULL);
// TODO: checksum is an empty slice in go; is that expected?
// require(object_meta.checksum_length != 0);
free_object_meta(&object_meta);
close_object(object_ref, err);
}
{ // download
DownloaderRef downloader = download(bucket, object_paths[i], err);
require_noerror(*err);
2019-06-21 19:44:00 +01:00
uint8_t downloaded_data[data_len];
memset(downloaded_data, '\0', data_len);
size_t downloaded_total = 0;
2019-06-21 19:44:00 +01:00
size_t size_to_read = 256 + i;
while (true) {
2019-06-21 19:44:00 +01:00
size_t read_size = download_read(downloader, &downloaded_data[downloaded_total], size_to_read, err);
require_noerror(*err);
2019-06-21 19:44:00 +01:00
if (read_size == 0) {
break;
}
2019-06-21 19:44:00 +01:00
downloaded_total += read_size;
}
download_close(downloader, err);
require_noerror(*err);
2019-06-21 19:44:00 +01:00
require(memcmp(data, downloaded_data, data_len) == 0);
}
if (data != NULL) {
free(data);
}
2019-06-21 19:44:00 +01:00
require_noerror(*err);
}
{ // List objects
ObjectList objects_list = list_objects(bucket, NULL, err);
require_noerror(*err);
require(strcmp(bucket_name, objects_list.bucket) == 0);
require(strcmp("", objects_list.prefix) == 0);
require(false == objects_list.more);
require(num_of_objects == objects_list.length);
ObjectInfo *object;
for (int i=0; i < objects_list.length; i++) {
object = &objects_list.items[i];
require(true == array_contains(object->path, object_paths, num_of_objects));
}
free_list_objects(&objects_list);
}
close_bucket(bucket, err);
require_noerror(*err);
lib/uplink: encryption context (#2349) * lib/uplink: encryption context Change-Id: I5c23dca3286a46b713b30c4997e9ae6e630b2280 * lib/uplink: bucket operation examples Change-Id: Ia0f6e69f365dcff0cf11c731f51b30842bce053b * lib/uplink: encryption key sharing test cases Change-Id: I3a172d565f33f4e591402cdcb9460664a7cc7fbe * fix encrypted path prefix restriction issue Change-Id: I8f3921f9d52aaf4b84039de608b8cbbc88769554 * implement panics in libuplink encryption code todo on cipher suite selection as well as an api concern Change-Id: Ifa39eb3cc4b3443f7d96f9304df9b2ac4ec4085d * implement GetProjectInfo api call to get salt Change-Id: Ic5f6b3be9ea35df48c1aa214ab5d355fb328e2cf * some fixes and accessors for encryption store Change-Id: I3bb61f6712a037900e2a96e72ad4029ec1d3f718 * general fixes to builds/tests/etc Change-Id: I9930fa96acb3b221d9a001f8e274af5729cc8a47 * java bindings changes Change-Id: Ia2bd4c9c69739c8d3154d79616cff1f36fb403b6 * get libuplink examples passing Change-Id: I828f09a144160e0a5dd932324f78491ae2ec8a07 * fix proto.lock file Change-Id: I2fbbf4d0976a7d0473c2645e6dcb21aaa3be7651 * fix proto.lock again Change-Id: I92702cf49e1a340eef6379c2be4f7c4a268112a9 * fix golint issues Change-Id: I631ff9f43307a58e3b25a58cbb4a4cc2495f5eb6 * more linting fixes Change-Id: I51f8f30b367b5bca14c94b15417b9a4c9e7aa0ce * bug fixed by structs bump Change-Id: Ibb03c691fce7606c35c08721b3ef0781ab48a38a * retrigger Change-Id: Ieee0470b6a2d07168a1578552e8e7f271ae93a13 * retrigger Change-Id: I753d63853171e6a436c104ce176048892eb974c5 * semantic merge conflict Change-Id: I9419448496de90340569047a6a16a1b858a7978a * update total to match prod defaults Change-Id: I693d55c1ebb28b5803ee1d26e9e198decf82308b * retrigger Change-Id: I28b74d5d6202f61aa3866fe407d423f6a0a14b9e * retrigger Change-Id: I6fd054885c715f602e2cef623fd464c42e88742c * retrigger Change-Id: I6a01bae88c72406d4ed5a8f13bf8a2b3c650bd2d
2019-06-27 18:36:51 +01:00
}