2019-06-13 16:09:05 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-06-21 13:24:06 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2019-06-13 16:09:05 +01:00
|
|
|
// test_bucket_config returns test bucket configuration.
|
|
|
|
BucketConfig test_bucket_config() {
|
|
|
|
BucketConfig config = {};
|
|
|
|
|
2019-06-21 19:44:00 +01:00
|
|
|
config.path_cipher = STORJ_ENC_AESGCM;
|
2019-06-13 16:09:05 +01:00
|
|
|
|
2019-06-21 19:44:00 +01:00
|
|
|
config.encryption_parameters.cipher_suite = STORJ_ENC_AESGCM;
|
2019-06-21 13:24:06 +01:00
|
|
|
config.encryption_parameters.block_size = 2048;
|
2019-06-13 16:09:05 +01:00
|
|
|
|
2019-06-21 19:44:00 +01:00
|
|
|
config.redundancy_scheme.algorithm = STORJ_REED_SOLOMON;
|
2019-07-30 12:40:05 +01:00
|
|
|
config.redundancy_scheme.share_size = 256;
|
2019-08-26 19:40:44 +01:00
|
|
|
config.redundancy_scheme.required_shares = 2;
|
|
|
|
config.redundancy_scheme.repair_shares = 3;
|
|
|
|
config.redundancy_scheme.optimal_shares = 4;
|
|
|
|
config.redundancy_scheme.total_shares = 5;
|
2019-06-13 16:09:05 +01:00
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
// with_test_project opens default test project and calls handleProject callback.
|
2019-06-24 03:06:14 +01:00
|
|
|
void with_test_project(void (*handleProject)(ProjectRef)) {
|
2019-06-13 16:09:05 +01:00
|
|
|
char *_err = "";
|
|
|
|
char **err = &_err;
|
|
|
|
|
|
|
|
char *satellite_addr = getenv("SATELLITE_0_ADDR");
|
|
|
|
char *apikeyStr = getenv("GATEWAY_0_API_KEY");
|
|
|
|
|
|
|
|
printf("using SATELLITE_0_ADDR: %s\n", satellite_addr);
|
|
|
|
printf("using GATEWAY_0_API_KEY: %s\n", apikeyStr);
|
|
|
|
|
|
|
|
{
|
|
|
|
UplinkConfig cfg = {};
|
2019-07-30 12:40:05 +01:00
|
|
|
cfg.Volatile.tls.skip_peer_ca_whitelist = true; // TODO: add CA Whitelist
|
2019-06-13 16:09:05 +01:00
|
|
|
|
|
|
|
// New uplink
|
2019-06-15 12:23:12 +01:00
|
|
|
UplinkRef uplink = new_uplink(cfg, err);
|
2019-06-13 16:09:05 +01:00
|
|
|
require_noerror(*err);
|
|
|
|
requiref(uplink._handle != 0, "got empty uplink\n");
|
|
|
|
|
|
|
|
{
|
|
|
|
// parse api key
|
2019-06-15 12:23:12 +01:00
|
|
|
APIKeyRef apikey = parse_api_key(apikeyStr, err);
|
2019-06-13 16:09:05 +01:00
|
|
|
require_noerror(*err);
|
|
|
|
requiref(apikey._handle != 0, "got empty apikey\n");
|
|
|
|
|
|
|
|
{
|
|
|
|
// open a project
|
2019-06-24 03:06:14 +01:00
|
|
|
ProjectRef project = open_project(uplink, satellite_addr, apikey, err);
|
2019-06-13 16:09:05 +01:00
|
|
|
require_noerror(*err);
|
|
|
|
requiref(project._handle != 0, "got empty project\n");
|
|
|
|
|
|
|
|
handleProject(project);
|
|
|
|
|
|
|
|
// close project
|
|
|
|
close_project(project, err);
|
|
|
|
require_noerror(*err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// free api key
|
|
|
|
free_api_key(apikey);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close uplinks
|
|
|
|
close_uplink(uplink, err);
|
|
|
|
require_noerror(*err);
|
|
|
|
}
|
|
|
|
|
|
|
|
requiref(internal_UniverseIsEmpty(), "universe is not empty\n");
|
2019-06-21 13:24:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void fill_random_data(uint8_t *buffer, size_t length) {
|
|
|
|
for(size_t i = 0; i < length; i++) {
|
|
|
|
buffer[i] = (uint8_t)i*31;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool array_contains(char *item, char *array[], int array_size) {
|
|
|
|
for (int i = 0; i < array_size; i++) {
|
|
|
|
if(strcmp(array[i], item) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-06-13 16:09:05 +01:00
|
|
|
}
|