mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Accept any well formed Rhizome service field
Do not limit service field to only recognised supported values 'file', 'MeshMS1' and 'MeshMS2' New test case checks for malformed service field, fails
This commit is contained in:
parent
72482b3427
commit
5e5e097d7f
@ -1332,7 +1332,7 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
|
||||
if (!m){
|
||||
keyring_free(keyring);
|
||||
return WHY("Manifest struct could not be allocated -- not added to rhizome");
|
||||
}
|
||||
}
|
||||
if (manifestpath && *manifestpath && access(manifestpath, R_OK) == 0) {
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("reading manifest from %s", manifestpath);
|
||||
|
36
rhizome.c
36
rhizome.c
@ -156,32 +156,30 @@ int rhizome_bundle_import_files(rhizome_manifest *m, const char *manifest_path,
|
||||
int rhizome_manifest_check_sanity(rhizome_manifest *m)
|
||||
{
|
||||
/* Ensure manifest meets basic sanity checks. */
|
||||
if (m->filesize == RHIZOME_SIZE_UNSET)
|
||||
return WHY("Manifest missing 'filesize' field");
|
||||
if (m->filesize && rhizome_filehash_t_is_zero(m->filehash))
|
||||
return WHY("Manifest 'filehash' field has not been set");
|
||||
if (m->service == NULL || !m->service[0])
|
||||
return WHY("Manifest missing 'service' field");
|
||||
if (!m->has_date)
|
||||
return WHY("Manifest missing 'date' field");
|
||||
int ret = 0;
|
||||
if (m->version == 0)
|
||||
return WHY("Manifest must have a version number");
|
||||
if (strcasecmp(m->service, RHIZOME_SERVICE_FILE) == 0) {
|
||||
ret = WHY("Manifest must have a version number");
|
||||
if (m->filesize == RHIZOME_SIZE_UNSET)
|
||||
ret = WHY("Manifest missing 'filesize' field");
|
||||
else if (m->filesize && rhizome_filehash_t_is_zero(m->filehash))
|
||||
ret = WHY("Manifest 'filehash' field has not been set");
|
||||
if (m->service == NULL)
|
||||
ret = WHY("Manifest missing 'service' field");
|
||||
else if (strcasecmp(m->service, RHIZOME_SERVICE_FILE) == 0) {
|
||||
if (m->name == NULL)
|
||||
return WHY("Manifest missing 'name' field");
|
||||
ret = WHY("Manifest with service='" RHIZOME_SERVICE_FILE "' missing 'name' field");
|
||||
} else if (strcasecmp(m->service, RHIZOME_SERVICE_MESHMS) == 0
|
||||
|| strcasecmp(m->service, RHIZOME_SERVICE_MESHMS2) == 0) {
|
||||
if (!m->has_sender)
|
||||
return WHY("MeshMS Manifest missing 'sender' field");
|
||||
ret = WHYF("Manifest with service='%s' missing 'sender' field", m->service);
|
||||
if (!m->has_recipient)
|
||||
return WHY("MeshMS Manifest missing 'recipient' field");
|
||||
} else {
|
||||
return WHYF("Invalid service=%s", m->service);
|
||||
ret = WHYF("Manifest with service='%s' missing 'recipient' field", m->service);
|
||||
}
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("sender=%s", m->has_sender ? alloca_tohex_sid_t(m->sender) : "(null)");
|
||||
/* passes all sanity checks */
|
||||
return 0;
|
||||
else if (!rhizome_str_is_manifest_service(m->service))
|
||||
ret = WHYF("Manifest invalid 'service' field %s", alloca_str_toprint(m->service));
|
||||
if (!m->has_date)
|
||||
ret = WHY("Manifest missing 'date' field");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Sets the bundle key "BK" field of a manifest. Returns 1 if the field was set, 0 if not.
|
||||
|
@ -714,17 +714,29 @@ test_AddUpdateAutoVersion() {
|
||||
assert_rhizome_list --fromhere=1 file1_2 file2
|
||||
}
|
||||
|
||||
doc_AddUnsupportedService="Add with unsupported service fails"
|
||||
setup_AddUnsupportedService() {
|
||||
doc_AddServiceInvalid="Add with invalid service fails"
|
||||
setup_AddServiceInvalid() {
|
||||
setup_servald
|
||||
setup_rhizome
|
||||
echo "Message1" >file1
|
||||
echo 'service=Fubar!' >file1.manifest
|
||||
}
|
||||
test_AddServiceInvalid() {
|
||||
execute $servald rhizome add file $SIDB1 file1 file1.manifest
|
||||
tfw_cat --stdout --stderr
|
||||
assertExitStatus '!=' 0
|
||||
}
|
||||
|
||||
doc_AddServiceUnsupported="Add with unsupported service succeeds"
|
||||
setup_AddServiceUnsupported() {
|
||||
setup_servald
|
||||
setup_rhizome
|
||||
echo "Message1" >file1
|
||||
echo 'service=Fubar' >file1.manifest
|
||||
}
|
||||
test_AddUnsupportedService() {
|
||||
execute $servald rhizome add file $SIDB1 file1 file1.manifest
|
||||
test_AddServiceUnsupported() {
|
||||
executeOk_servald rhizome add file $SIDB1 file1 file1.manifest
|
||||
tfw_cat --stdout --stderr
|
||||
assertExitStatus '!=' 0
|
||||
}
|
||||
|
||||
doc_EncryptedPayload="Add and extract an encrypted payload"
|
||||
|
Loading…
x
Reference in New Issue
Block a user