CLI output from "rhizome add file", with tests

This commit is contained in:
Andrew Bettison 2012-05-04 15:31:03 +09:30
parent 6bc8f5643f
commit f31c326871
4 changed files with 53 additions and 26 deletions

View File

@ -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. */
if (manifestpath[0] && rhizome_write_manifest_file(mout, manifestpath) == -1)
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);
if (mout != m)
rhizome_manifest_free(mout);

View File

@ -252,7 +252,6 @@ int rhizome_add_manifest(rhizome_manifest *m_in,
} else {
/* The manifest had no ID (256 bit random string being a public key in the NaCl CryptoSign
crypto system), so create one. */
printf("manifest does not have an id\n");
rhizome_manifest_createid(m_in);
/* 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

View File

@ -296,7 +296,7 @@ int rhizome_store_bundle(rhizome_manifest *m, const char *associated_filename)
const char *cmdtail;
int i;
char manifestid[65];
char manifestid[crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES * 2 + 1];
strncpy(manifestid,rhizome_manifest_get(m,"id",NULL,0),64);
manifestid[64]=0;
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");
}
printf("stored file\n");
return 0;
}

View File

@ -33,21 +33,38 @@ assert_rhizome_list() {
assertStdoutIs --line=2 -e 'fileid:manifestid:version:inserttime:length:datavalid:date:name\n'
local filename
for filename; do
local filehash='[^:]\+'
local manifestid='[^:]\+'
# 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.
if [ -r "$filename.manifest" ]; then
local name=$(sed -n -e '/^name=/s///p' "$filename.manifest")
if [ "$name" == "$filename" ]; then
filehash=$(sed -n -e '/^filehash=/s///p' "$filename.manifest")
manifestid=$(sed -n -e '/^id=/s///p' "$filename.manifest")
fi
fi
assertStdoutGrep --matches=1 "^$filehash:$manifestid:.*:$filename\$"
unpack_manifest_for_grep "$filename"
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
# file, then use its file hash to check the rhizome list output.
if [ -r "$filename.manifest" ]; then
local name=$(sed -n -e '/^name=/s///p' "$filename.manifest")
if [ "$name" == "${filename##*/}" ]; then
re_filehash=$(sed -n -e '/^filehash=/s///p' "$filename.manifest")
re_manifestid=$(sed -n -e '/^id=/s///p' "$filename.manifest")
fi
fi
}
assert_manifest_newer() {
local manifest1="$1"
local manifest2="$2"
@ -108,6 +125,7 @@ setup_AddNoManifest() {
}
test_AddNoManifest() {
executeOk $dna rhizome add file file1
assert_stdout_add_file file1
}
doc_AddNonExistManifest="Add with non-existent manifest file"
@ -120,16 +138,17 @@ setup_AddNonExistManifest() {
test_AddNonExistManifest() {
assert --error-on-fail [ ! -e file1.manifest ]
executeOk $dna rhizome add file file1 file1.manifest
assert_stdout_add_file file1
assert [ -r file1.manifest ]
tfw_cat -v file1.manifest
local size=$(( $(cat file1 | wc -c) + 0 ))
assertGrep file1.manifest '^name=file1$'
assertGrep file1.manifest '^date=[0-9]\+$'
assertGrep file1.manifest '^version=[0-9]\+$'
assertGrep file1.manifest '^id=[0-9a-fA-F]\{64\}$'
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 "^last_byte=$size\$"
assertGrep file1.manifest "^last_byte=$re_size\$"
}
doc_AddManifest="Add with minimal manifest file"
@ -142,17 +161,16 @@ setup_AddManifest() {
}
test_AddManifest() {
executeOk $dna rhizome add file file1 file1.manifest
tfw_cat --stdout
tfw_cat --stderr
tfw_cat -v file1.manifest
local size=$(( $(cat file1 | wc -c) + 0 ))
assertGrep file1.manifest '^id=[0-9a-fA-F]\{64\}$'
tfw_cat --stdout --stderr -v file1.manifest
assert_stdout_add_file file1 wah
assertGrep file1.manifest '^name=wah$'
assertGrep file1.manifest '^version=[0-9]\+$'
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 "^last_byte=$size\$"
assertGrep file1.manifest "^last_byte=$re_size\$"
}
doc_AddThenList="List contains one file after one add"