mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-02 19:36:48 +00:00
CLI output from "rhizome add file", with tests
This commit is contained in:
parent
6bc8f5643f
commit
f31c326871
@ -1018,6 +1018,17 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_
|
|||||||
invoking this command can read it to obtain feedback on the result. */
|
invoking this command can read it to obtain feedback on the result. */
|
||||||
if (manifestpath[0] && rhizome_write_manifest_file(mout, manifestpath) == -1)
|
if (manifestpath[0] && rhizome_write_manifest_file(mout, manifestpath) == -1)
|
||||||
ret = WHY("Could not overwrite manifest file.");
|
ret = WHY("Could not overwrite manifest file.");
|
||||||
|
cli_puts("manifestid"); cli_delim(":");
|
||||||
|
cli_puts(rhizome_bytes_to_hex(m->cryptoSignPublic, crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)); cli_delim("\n");
|
||||||
|
cli_puts("filehash"); cli_delim(":");
|
||||||
|
cli_puts(m->fileHexHash); cli_delim("\n");
|
||||||
|
cli_puts("filesize"); cli_delim(":");
|
||||||
|
cli_printf("%lld", m->fileLength); cli_delim("\n");
|
||||||
|
const char *name = rhizome_manifest_get(m, "name", NULL, 0);
|
||||||
|
if (name) {
|
||||||
|
cli_puts("name"); cli_delim(":");
|
||||||
|
cli_puts(name); cli_delim("\n");
|
||||||
|
}
|
||||||
rhizome_manifest_free(m);
|
rhizome_manifest_free(m);
|
||||||
if (mout != m)
|
if (mout != m)
|
||||||
rhizome_manifest_free(mout);
|
rhizome_manifest_free(mout);
|
||||||
|
@ -252,7 +252,6 @@ int rhizome_add_manifest(rhizome_manifest *m_in,
|
|||||||
} else {
|
} else {
|
||||||
/* The manifest had no ID (256 bit random string being a public key in the NaCl CryptoSign
|
/* The manifest had no ID (256 bit random string being a public key in the NaCl CryptoSign
|
||||||
crypto system), so create one. */
|
crypto system), so create one. */
|
||||||
printf("manifest does not have an id\n");
|
|
||||||
rhizome_manifest_createid(m_in);
|
rhizome_manifest_createid(m_in);
|
||||||
/* The ID is implicit in transit, but we need to store it in the file, so that reimporting
|
/* The ID is implicit in transit, but we need to store it in the file, so that reimporting
|
||||||
manifests on receiver nodes works easily. We might implement something that strips the id
|
manifests on receiver nodes works easily. We might implement something that strips the id
|
||||||
|
@ -296,7 +296,7 @@ int rhizome_store_bundle(rhizome_manifest *m, const char *associated_filename)
|
|||||||
const char *cmdtail;
|
const char *cmdtail;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
char manifestid[65];
|
char manifestid[crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES * 2 + 1];
|
||||||
strncpy(manifestid,rhizome_manifest_get(m,"id",NULL,0),64);
|
strncpy(manifestid,rhizome_manifest_get(m,"id",NULL,0),64);
|
||||||
manifestid[64]=0;
|
manifestid[64]=0;
|
||||||
for(i=0;i<64;i++)
|
for(i=0;i<64;i++)
|
||||||
@ -727,7 +727,6 @@ int rhizome_store_file(const char *file,char *hash,int priority)
|
|||||||
return WHY("SQLite3 failed write all blob data");
|
return WHY("SQLite3 failed write all blob data");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("stored file\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,19 +33,36 @@ assert_rhizome_list() {
|
|||||||
assertStdoutIs --line=2 -e 'fileid:manifestid:version:inserttime:length:datavalid:date:name\n'
|
assertStdoutIs --line=2 -e 'fileid:manifestid:version:inserttime:length:datavalid:date:name\n'
|
||||||
local filename
|
local filename
|
||||||
for filename; do
|
for filename; do
|
||||||
local filehash='[^:]\+'
|
unpack_manifest_for_grep "$filename"
|
||||||
local manifestid='[^:]\+'
|
assertStdoutGrep --matches=1 "^$re_filehash:$re_manifestid:.*:$re_name\$"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_stdout_add_file() {
|
||||||
|
local filename="$1"
|
||||||
|
unpack_manifest_for_grep "$filename"
|
||||||
|
assertStdoutLineCount '==' 4
|
||||||
|
assertStdoutGrep --matches=1 "^name:${2:-$re_name}\$"
|
||||||
|
assertStdoutGrep --matches=1 "^manifestid:$re_manifestid\$"
|
||||||
|
assertStdoutGrep --matches=1 "^filehash:$re_filehash\$"
|
||||||
|
assertStdoutGrep --matches=1 "^filesize:$re_size\$"
|
||||||
|
}
|
||||||
|
|
||||||
|
unpack_manifest_for_grep() {
|
||||||
|
local filename="$1"
|
||||||
|
re_size=$(( $(cat "$filename" | wc -c) + 0 ))
|
||||||
|
re_filehash='[0-9a-fA-F]\{128\}'
|
||||||
|
re_manifestid='[0-9a-fA-F]\{64\}'
|
||||||
|
re_name="${filename##*/}" # should escape grep metacharacters
|
||||||
# If there is a manifest file that looks like it matches this payload
|
# If there is a manifest file that looks like it matches this payload
|
||||||
# file, then use its file hash to check the rhizome list output.
|
# file, then use its file hash to check the rhizome list output.
|
||||||
if [ -r "$filename.manifest" ]; then
|
if [ -r "$filename.manifest" ]; then
|
||||||
local name=$(sed -n -e '/^name=/s///p' "$filename.manifest")
|
local name=$(sed -n -e '/^name=/s///p' "$filename.manifest")
|
||||||
if [ "$name" == "$filename" ]; then
|
if [ "$name" == "${filename##*/}" ]; then
|
||||||
filehash=$(sed -n -e '/^filehash=/s///p' "$filename.manifest")
|
re_filehash=$(sed -n -e '/^filehash=/s///p' "$filename.manifest")
|
||||||
manifestid=$(sed -n -e '/^id=/s///p' "$filename.manifest")
|
re_manifestid=$(sed -n -e '/^id=/s///p' "$filename.manifest")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
assertStdoutGrep --matches=1 "^$filehash:$manifestid:.*:$filename\$"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_manifest_newer() {
|
assert_manifest_newer() {
|
||||||
@ -108,6 +125,7 @@ setup_AddNoManifest() {
|
|||||||
}
|
}
|
||||||
test_AddNoManifest() {
|
test_AddNoManifest() {
|
||||||
executeOk $dna rhizome add file file1
|
executeOk $dna rhizome add file file1
|
||||||
|
assert_stdout_add_file file1
|
||||||
}
|
}
|
||||||
|
|
||||||
doc_AddNonExistManifest="Add with non-existent manifest file"
|
doc_AddNonExistManifest="Add with non-existent manifest file"
|
||||||
@ -120,16 +138,17 @@ setup_AddNonExistManifest() {
|
|||||||
test_AddNonExistManifest() {
|
test_AddNonExistManifest() {
|
||||||
assert --error-on-fail [ ! -e file1.manifest ]
|
assert --error-on-fail [ ! -e file1.manifest ]
|
||||||
executeOk $dna rhizome add file file1 file1.manifest
|
executeOk $dna rhizome add file file1 file1.manifest
|
||||||
|
assert_stdout_add_file file1
|
||||||
assert [ -r file1.manifest ]
|
assert [ -r file1.manifest ]
|
||||||
tfw_cat -v file1.manifest
|
tfw_cat -v file1.manifest
|
||||||
local size=$(( $(cat file1 | wc -c) + 0 ))
|
|
||||||
assertGrep file1.manifest '^name=file1$'
|
assertGrep file1.manifest '^name=file1$'
|
||||||
assertGrep file1.manifest '^date=[0-9]\+$'
|
assertGrep file1.manifest '^date=[0-9]\+$'
|
||||||
assertGrep file1.manifest '^version=[0-9]\+$'
|
assertGrep file1.manifest '^version=[0-9]\+$'
|
||||||
assertGrep file1.manifest '^id=[0-9a-fA-F]\{64\}$'
|
assertGrep file1.manifest "^id=$re_manifestid\$"
|
||||||
assertGrep file1.manifest "^filesize=$size\$"
|
assertGrep file1.manifest "^filehash=$re_filehash\$"
|
||||||
|
assertGrep file1.manifest "^filesize=$re_size\$"
|
||||||
assertGrep file1.manifest "^first_byte=0$"
|
assertGrep file1.manifest "^first_byte=0$"
|
||||||
assertGrep file1.manifest "^last_byte=$size\$"
|
assertGrep file1.manifest "^last_byte=$re_size\$"
|
||||||
}
|
}
|
||||||
|
|
||||||
doc_AddManifest="Add with minimal manifest file"
|
doc_AddManifest="Add with minimal manifest file"
|
||||||
@ -142,17 +161,16 @@ setup_AddManifest() {
|
|||||||
}
|
}
|
||||||
test_AddManifest() {
|
test_AddManifest() {
|
||||||
executeOk $dna rhizome add file file1 file1.manifest
|
executeOk $dna rhizome add file file1 file1.manifest
|
||||||
tfw_cat --stdout
|
tfw_cat --stdout --stderr -v file1.manifest
|
||||||
tfw_cat --stderr
|
assert_stdout_add_file file1 wah
|
||||||
tfw_cat -v file1.manifest
|
|
||||||
local size=$(( $(cat file1 | wc -c) + 0 ))
|
|
||||||
assertGrep file1.manifest '^id=[0-9a-fA-F]\{64\}$'
|
|
||||||
assertGrep file1.manifest '^name=wah$'
|
assertGrep file1.manifest '^name=wah$'
|
||||||
assertGrep file1.manifest '^version=[0-9]\+$'
|
assertGrep file1.manifest '^version=[0-9]\+$'
|
||||||
assertGrep file1.manifest '^date=12345$'
|
assertGrep file1.manifest '^date=12345$'
|
||||||
assertGrep file1.manifest "^filesize=$size\$"
|
assertGrep file1.manifest "^id=$re_manifestid\$"
|
||||||
|
assertGrep file1.manifest "^filehash=$re_filehash\$"
|
||||||
|
assertGrep file1.manifest "^filesize=$re_size\$"
|
||||||
assertGrep file1.manifest "^first_byte=0$"
|
assertGrep file1.manifest "^first_byte=0$"
|
||||||
assertGrep file1.manifest "^last_byte=$size\$"
|
assertGrep file1.manifest "^last_byte=$re_size\$"
|
||||||
}
|
}
|
||||||
|
|
||||||
doc_AddThenList="List contains one file after one add"
|
doc_AddThenList="List contains one file after one add"
|
||||||
|
Loading…
Reference in New Issue
Block a user