mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Test and fix rhizome clean verify
This commit is contained in:
parent
f06d9bb574
commit
2f60b8417f
@ -469,7 +469,7 @@ static int app_rhizome_delete(const struct cli_parsed *parsed, struct cli_contex
|
||||
|
||||
DEFINE_CMD(app_rhizome_clean, 0,
|
||||
"Remove stale and orphaned content from the Rhizome store",
|
||||
"rhizome","clean","[verify]");
|
||||
"rhizome","clean","[verify]" KEYRING_PIN_OPTIONS);
|
||||
static int app_rhizome_clean(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
{
|
||||
DEBUG_cli_parsed(verbose, parsed);
|
||||
@ -481,8 +481,10 @@ static int app_rhizome_clean(const struct cli_parsed *parsed, struct cli_context
|
||||
if (rhizome_opendb() == -1)
|
||||
return -1;
|
||||
|
||||
if (verify)
|
||||
if (verify){
|
||||
keyring = keyring_open_instance_cli(parsed);
|
||||
verify_bundles();
|
||||
}
|
||||
struct rhizome_cleanup_report report;
|
||||
if (rhizome_cleanup(&report) == -1)
|
||||
return -1;
|
||||
|
@ -156,11 +156,12 @@ static enum rhizome_bundle_authorship set_authentic(rhizome_manifest *m, const k
|
||||
* and finally update the database with the result.
|
||||
*/
|
||||
static enum rhizome_bundle_authorship try_author(rhizome_manifest *m, const keyring_identity *id, const sid_t *sid){
|
||||
assert(keyring != NULL);
|
||||
if (!sid)
|
||||
return AUTHOR_UNKNOWN;
|
||||
|
||||
if (!id){
|
||||
if (!keyring)
|
||||
return AUTHOR_UNKNOWN;
|
||||
id = keyring_find_identity_sid(keyring, sid);
|
||||
if (!id)
|
||||
return AUTHOR_UNKNOWN;
|
||||
@ -230,7 +231,6 @@ static enum rhizome_bundle_authorship try_author(rhizome_manifest *m, const keyr
|
||||
void rhizome_authenticate_author(rhizome_manifest *m)
|
||||
{
|
||||
IN();
|
||||
assert(keyring != NULL);
|
||||
DEBUGF(rhizome, "authenticate author for bid=%s", m->has_id ? alloca_tohex_rhizome_bid_t(m->keypair.public_key) : "(none)");
|
||||
switch (m->authorship) {
|
||||
case ANONYMOUS:
|
||||
@ -242,8 +242,8 @@ void rhizome_authenticate_author(rhizome_manifest *m)
|
||||
if (crypto_sign_to_sid(&m->keypair.public_key, &test_sid)==0){
|
||||
if (cmp_sid_t(&test_sid, &m->sender)==0){
|
||||
// self signed bundle, is it ours?
|
||||
keyring_identity *id = keyring_find_identity(keyring, &m->keypair.public_key);
|
||||
if (id){
|
||||
keyring_identity *id;
|
||||
if (keyring && (id = keyring_find_identity(keyring, &m->keypair.public_key))){
|
||||
set_authentic(m, id, &m->sender);
|
||||
RETURNVOID;
|
||||
}else{
|
||||
@ -259,15 +259,17 @@ void rhizome_authenticate_author(rhizome_manifest *m)
|
||||
if (m->has_sender && try_author(m, NULL, &m->sender) == AUTHOR_AUTHENTIC)
|
||||
RETURNVOID;
|
||||
|
||||
keyring_iterator it;
|
||||
keyring_iterator_start(keyring, &it);
|
||||
keyring_identity *id;
|
||||
while((id = keyring_next_identity(&it))){
|
||||
// skip the sender if we've already tried it.
|
||||
if (m->has_sender && cmp_sid_t(&m->sender, id->box_pk)==0)
|
||||
continue;
|
||||
if (try_author(m, id, id->box_pk) == AUTHOR_AUTHENTIC)
|
||||
RETURNVOID;
|
||||
if (keyring){
|
||||
keyring_iterator it;
|
||||
keyring_iterator_start(keyring, &it);
|
||||
keyring_identity *id;
|
||||
while((id = keyring_next_identity(&it))){
|
||||
// skip the sender if we've already tried it.
|
||||
if (m->has_sender && cmp_sid_t(&m->sender, id->box_pk)==0)
|
||||
continue;
|
||||
if (try_author(m, id, id->box_pk) == AUTHOR_AUTHENTIC)
|
||||
RETURNVOID;
|
||||
}
|
||||
}
|
||||
|
||||
RETURNVOID;
|
||||
|
@ -158,19 +158,19 @@ void verify_bundles()
|
||||
rhizome_manifest_to_bar(m, &bar);
|
||||
rhizome_authenticate_author(m);
|
||||
|
||||
if (sqlite_exec_void("UPDATE MANIFESTS SET"
|
||||
"id = ?,"
|
||||
"version = ?,"
|
||||
"bar = ?,"
|
||||
"filesize = ?,"
|
||||
"filehash = ?,"
|
||||
"author = ?,"
|
||||
"service = ?,"
|
||||
"name = ?,"
|
||||
"sender = ?,"
|
||||
"recipient = ?,"
|
||||
"tail = ?,"
|
||||
"manifest_hash = ?"
|
||||
if (sqlite_exec_void("UPDATE MANIFESTS SET "
|
||||
"id = ?, "
|
||||
"version = ?, "
|
||||
"bar = ?, "
|
||||
"filesize = ?, "
|
||||
"filehash = ?, "
|
||||
"author = ?, "
|
||||
"service = ?, "
|
||||
"name = ?, "
|
||||
"sender = ?, "
|
||||
"recipient = ?, "
|
||||
"tail = ?, "
|
||||
"manifest_hash = ? "
|
||||
"WHERE ROWID = ?;",
|
||||
RHIZOME_BID_T, &m->keypair.public_key,
|
||||
INT64, m->version,
|
||||
|
@ -285,6 +285,32 @@ test_AddThenList() {
|
||||
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2
|
||||
}
|
||||
|
||||
doc_CleanVerify="Verify all bundles"
|
||||
setup_CleanVerify() {
|
||||
setup_servald
|
||||
setup_rhizome
|
||||
echo "File1" > file1
|
||||
echo "File2" > file2
|
||||
echo "File3" > file3
|
||||
echo "File4" > file4
|
||||
executeOk_servald rhizome add file '' file1 file1.manifest
|
||||
assert_stdout_add_file file1 !.author !BK
|
||||
executeOk_servald rhizome add file '' file2 file2.manifest
|
||||
assert_stdout_add_file file2 !.author !BK
|
||||
executeOk_servald rhizome add file '' file3 file3.manifest
|
||||
assert_stdout_add_file file3 !.author !BK
|
||||
executeOk_servald rhizome add file '' file4 file4.manifest
|
||||
assert_stdout_add_file file4 !.author !BK
|
||||
executeOk_servald rhizome list file
|
||||
assert_rhizome_list file1 file2 file3 file4
|
||||
}
|
||||
test_CleanVerify() {
|
||||
executeOk_servald rhizome clean verify
|
||||
tfw_cat --stdout --stderr
|
||||
executeOk_servald rhizome list file
|
||||
assert_rhizome_list file1 file2 file3 file4
|
||||
}
|
||||
|
||||
doc_ExtractManifestAfterAdd="Export manifest after one add"
|
||||
setup_ExtractManifestAfterAdd() {
|
||||
setup_servald
|
||||
|
Loading…
x
Reference in New Issue
Block a user