Expand output of rhizome add and import

Rename 'secret:' field to '.secret:' (non-manifest-fields start with '.'
using the same convention as rhizome list)

Add '.author' and 'BK' fields to "rhizome add"

Add 'BK' field to "rhizome import"

Fix 'rhizomeops' tests to assert no 'author' and 'BK' output fields from
"rhizome add" with no author

Fiz testdefs.sh and testdefs_rhizome.sh to support new output fields
This commit is contained in:
Andrew Bettison 2013-09-27 22:34:22 +09:30
parent ef5622f84a
commit 5e164607aa
5 changed files with 48 additions and 21 deletions

View File

@ -1403,9 +1403,18 @@ int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *co
{
char secret[RHIZOME_BUNDLE_KEY_STRLEN + 1];
rhizome_bytes_to_hex_upper(mout->cryptoSignSecret, secret, RHIZOME_BUNDLE_KEY_BYTES);
cli_field_name(context, "secret", ":");
cli_field_name(context, ".secret", ":");
cli_put_string(context, secret, "\n");
}
if (*authorSidHex) {
cli_field_name(context, ".author", ":");
cli_put_string(context, alloca_tohex_sid_t(authorSid), "\n");
}
const char *bk = rhizome_manifest_get(mout, "BK", NULL, 0);
if (bk) {
cli_field_name(context, "BK", ":");
cli_put_string(context, bk, "\n");
}
cli_field_name(context, "version", ":");
cli_put_long(context, m->version, "\n");
cli_field_name(context, "filesize", ":");
@ -1498,6 +1507,17 @@ int app_rhizome_import_bundle(const struct cli_parsed *parsed, struct cli_contex
cli_field_name(context, "manifestid", ":");
cli_put_string(context, alloca_tohex(m->cryptoSignPublic, RHIZOME_MANIFEST_ID_BYTES), "\n");
}
{
char secret[RHIZOME_BUNDLE_KEY_STRLEN + 1];
rhizome_bytes_to_hex_upper(m->cryptoSignSecret, secret, RHIZOME_BUNDLE_KEY_BYTES);
cli_field_name(context, ".secret", ":");
cli_put_string(context, secret, "\n");
}
const char *bk = rhizome_manifest_get(m, "BK", NULL, 0);
if (bk) {
cli_field_name(context, "BK", ":");
cli_put_string(context, bk, "\n");
}
cli_field_name(context, "version", ":");
cli_put_long(context, m->version, "\n");
cli_field_name(context, "filesize", ":");

View File

@ -264,7 +264,7 @@ int rhizome_direct_form_received(rhizome_http_request *r)
}
rhizome_manifest *mout = NULL;
if (rhizome_manifest_finalise(m, &mout)) {
if (rhizome_manifest_finalise(m, &mout, 1)) {
if (mout && mout!=m)
rhizome_manifest_free(mout);
rhizome_manifest_free(m);

View File

@ -35,7 +35,7 @@ rexp_did='[0-9+#]\{5,\}'
# Utility function for extracting information from the output of servald
# commands that return "key:value\n" pairs.
#
# extract_stdout_keyvalue optional <varname> <key> [<delimiter>] <regular-expression>
# extract_stdout_keyvalue_optional <varname> <key> [<delimiter>] <regular-expression>
#
# Examines the standard output of the last command executed using "execute" or
# any of its variants. If there is a line matching
@ -55,7 +55,9 @@ extract_stdout_keyvalue_optional() {
4) _delim="$3"; _rexp="$4";;
*) error "invalid number of args";;
esac
local _line=$(replayStdout | $GREP "^$_label$_delim")
local _label_re=$(escape_grep_basic "$_label")
local _delim_re=$(escape_grep_basic "$_delim")
local _line=$(replayStdout | $GREP "^$_label_re$_delim_re")
local _value=
local _return=1
if [ -n "$_line" ]; then

View File

@ -123,7 +123,7 @@ assert_stdout_add_file() {
if [ "$re_crypt" = 1 ]; then
opt_filehash=false
fi
fieldnames='service|manifestid|secret|filesize|filehash|name'
fieldnames='service|manifestid|author|secret|BK|filesize|filehash|name'
for arg; do
case "$arg" in
!+($fieldnames))
@ -142,7 +142,9 @@ assert_stdout_add_file() {
done
${opt_service:-true} && assertStdoutGrep --matches=1 "^service:$re_service\$"
${opt_manifestid:-true} && assertStdoutGrep --matches=1 "^manifestid:$re_manifestid\$"
${opt_secret:-true} && assertStdoutGrep --matches=1 "^secret:$re_secret\$"
${opt_author:-true} && assertStdoutGrep --matches=1 "^\.author:$rexp_sid\$"
${opt_secret:-true} && assertStdoutGrep --matches=1 "^\.secret:$re_secret\$"
${opt_BK:-true} && assertStdoutGrep --matches=1 "^BK:$re_BK\$"
${opt_filesize:-true} && assertStdoutGrep --matches=1 "^filesize:$actual_filesize\$"
if replayStdout | $GREP -q '^filesize:0$'; then
assertStdoutGrep --matches=0 "^filehash:"
@ -152,8 +154,9 @@ assert_stdout_add_file() {
}
assert_stdout_import_bundle() {
# Output of "import bundle" is the same as "add file" but without the secret.
assert_stdout_add_file "$@" '!secret'
# Output of "import bundle" is the same as "add file" but without the secret
# or author fields.
assert_stdout_add_file "$@" '!secret' '!author'
}
unpack_manifest_for_grep() {
@ -163,6 +166,7 @@ unpack_manifest_for_grep() {
re_version="$rexp_version"
re_date="$rexp_date"
re_secret="$rexp_bundlesecret"
re_BK="$rexp_bundlekey"
re_sender="\($rexp_sid\)\{0,1\}"
re_recipient="\($rexp_sid\)\{0,1\}"
re_filesize="$rexp_filesize"
@ -184,6 +188,7 @@ unpack_manifest_for_grep() {
re_crypt=$($SED -n -e '/^crypt=/s///p' "$filename.manifest")
re_name=$($SED -n -e '/^name=/s///p' "$filename.manifest")
re_name=$(escape_grep_basic "$re_name")
re_BK=$($SED -n -e '/^BK=/s///p' "$filename.manifest")
re_sender=$($SED -n -e '/^sender=/s///p' "$filename.manifest")
re_recipient=$($SED -n -e '/^recipient=/s///p' "$filename.manifest")
fi
@ -217,7 +222,7 @@ extract_stdout_version() {
}
extract_stdout_secret() {
extract_stdout_keyvalue "$1" secret "$rexp_bundlesecret"
extract_stdout_keyvalue "$1" .secret "$rexp_bundlesecret"
}
extract_stdout_BK() {

View File

@ -63,7 +63,7 @@ setup_AddNoAuthorNoManifest() {
}
test_AddNoAuthorNoManifest() {
executeOk_servald rhizome add file '' file1
assert_stdout_add_file file1
assert_stdout_add_file file1 !author !BK
}
doc_AddNoManifest="Add with no manifest file"
@ -87,7 +87,7 @@ setup_AddNoAuthor() {
}
test_AddNoAuthor() {
executeOk_servald rhizome add file '' file1 file1.manifest
assert_stdout_add_file file1
assert_stdout_add_file file1 !author !BK
assertGrep --matches=0 file1.manifest '^BK='
}
@ -113,7 +113,7 @@ setup_AddNoAuthorEncrypted() {
test_AddNoAuthorEncrypted() {
executeOk_servald rhizome add file '' file1 file1.manifest
tfw_cat --stdout --stderr
assert_stdout_add_file file1
assert_stdout_add_file file1 !author !BK
extract_stdout_secret file1_secret
assertGrep --matches=0 file1.manifest '^BK='
executeOk_servald rhizome extract file $re_manifestid file1x $file1_secret
@ -852,7 +852,7 @@ setup_MeshMSAddMissingAuthor() {
}
test_MeshMSAddMissingAuthor() {
executeOk_servald rhizome add file '' file1 file1.manifest
assert_stdout_add_file file1
assert_stdout_add_file file1 !author !BK
assert_manifest_complete file1.manifest
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 file1
@ -867,13 +867,13 @@ setup_ListFilter() {
echo "File3" > file3
echo "File4" > file4
executeOk_servald rhizome add file '' file1 file1.manifest
assert_stdout_add_file file1
assert_stdout_add_file file1 !author !BK
executeOk_servald rhizome add file '' file2 file2.manifest
assert_stdout_add_file file2
assert_stdout_add_file file2 !author !BK
executeOk_servald rhizome add file '' file3 file3.manifest
assert_stdout_add_file file3
assert_stdout_add_file file3 !author !BK
executeOk_servald rhizome add file '' file4 file4.manifest
assert_stdout_add_file file4
assert_stdout_add_file file4 !author !BK
}
test_ListFilter() {
executeOk_servald rhizome list file
@ -897,16 +897,16 @@ setup_MeshMSListFilter() {
echo "Message3" >file4
echo -e "service=MeshMS1\nsender=$SIDB2\nrecipient=$SIDB3" >file4.manifest
executeOk_servald rhizome add file '' file1 file1.manifest
assert_stdout_add_file file1
assert_stdout_add_file file1 !author !BK
assert_manifest_complete file1.manifest
executeOk_servald rhizome add file '' file2 file2.manifest
assert_stdout_add_file file2
assert_stdout_add_file file2 !author !BK
assert_manifest_complete file2.manifest
executeOk_servald rhizome add file '' file3 file3.manifest
assert_stdout_add_file file3
assert_stdout_add_file file3 !author !BK
assert_manifest_complete file3.manifest
executeOk_servald rhizome add file '' file4 file4.manifest
assert_stdout_add_file file4
assert_stdout_add_file file4 !author !BK
assert_manifest_complete file4.manifest
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 file1 file2 file3 file4