Add ".secret" output field to all rhizome export/extract commands

This commit is contained in:
Andrew Bettison 2013-11-04 16:07:01 +10:30
parent 4d54f55906
commit 675e2021cc
2 changed files with 34 additions and 23 deletions

View File

@ -1666,7 +1666,7 @@ int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *con
bskhex=NULL; bskhex=NULL;
rhizome_bk_t bsk; rhizome_bk_t bsk;
if (bskhex && fromhexstr(bsk.binary, bskhex, RHIZOME_BUNDLE_KEY_BYTES) == -1) if (bskhex && str_to_rhizome_bk_t(&bsk, bskhex) == -1)
return WHYF("invalid bsk: \"%s\"", bskhex); return WHYF("invalid bsk: \"%s\"", bskhex);
rhizome_manifest *m = rhizome_new_manifest(); rhizome_manifest *m = rhizome_new_manifest();
@ -1677,21 +1677,25 @@ int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *con
if (ret==0){ if (ret==0){
// ignore errors // ignore errors
rhizome_extract_privatekey(m, NULL); rhizome_extract_privatekey(m, bskhex ? &bsk : NULL);
const char *blob_service = rhizome_manifest_get(m, "service", NULL, 0); const char *blob_service = rhizome_manifest_get(m, "service", NULL, 0);
cli_field_name(context, "service", ":"); cli_field_name(context, "service", ":");
cli_put_string(context, blob_service, "\n"); cli_put_string(context, blob_service, "\n");
cli_field_name(context, "manifestid", ":"); cli_field_name(context, "manifestid", ":");
cli_put_string(context, alloca_tohex_rhizome_bid_t(bid), "\n"); cli_put_string(context, alloca_tohex_rhizome_bid_t(bid), "\n");
if (m->haveSecret) {
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");
cli_field_name(context, ".author", ":");
cli_put_string(context, alloca_tohex_sid_t(m->author), "\n");
}
cli_field_name(context, "version", ":"); cli_field_name(context, "version", ":");
cli_put_long(context, m->version, "\n"); cli_put_long(context, m->version, "\n");
cli_field_name(context, "inserttime", ":"); cli_field_name(context, "inserttime", ":");
cli_put_long(context, m->inserttime, "\n"); cli_put_long(context, m->inserttime, "\n");
if (m->haveSecret) {
cli_field_name(context, ".author", ":");
cli_put_string(context, alloca_tohex_sid_t(m->author), "\n");
}
cli_field_name(context, ".readonly", ":"); cli_field_name(context, ".readonly", ":");
cli_put_long(context, m->haveSecret?0:1, "\n"); cli_put_long(context, m->haveSecret?0:1, "\n");
cli_field_name(context, "filesize", ":"); cli_field_name(context, "filesize", ":");

View File

@ -215,7 +215,7 @@ setup_ExtractManifestAfterAdd() {
test_ExtractManifestAfterAdd() { test_ExtractManifestAfterAdd() {
executeOk_servald rhizome export manifest $manifestid file1x.manifest executeOk_servald rhizome export manifest $manifestid file1x.manifest
tfw_cat --stdout --stderr tfw_cat --stdout --stderr
assertStdoutLineCount '==' 8 assertStdoutLineCount '==' 9
local size=$(( $(cat file1 | wc -c) + 0 )) local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^service:file$" assertStdoutGrep --matches=1 "^service:file$"
assertStdoutGrep --matches=1 "^manifestid:$manifestid\$" assertStdoutGrep --matches=1 "^manifestid:$manifestid\$"
@ -224,6 +224,7 @@ test_ExtractManifestAfterAdd() {
assertStdoutGrep --matches=1 "^filehash:$filehash\$" assertStdoutGrep --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --matches=1 "^filesize:$size\$" assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^\.author:$SIDB1\$" assertStdoutGrep --matches=1 "^\.author:$SIDB1\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$" assertStdoutGrep --matches=1 "^\.readonly:0\$"
assert [ -e file1x.manifest ] assert [ -e file1x.manifest ]
assert diff file1.manifest file1x.manifest assert diff file1.manifest file1x.manifest
@ -244,7 +245,7 @@ setup_ExtractManifestFileAfterAdd() {
test_ExtractManifestFileAfterAdd() { test_ExtractManifestFileAfterAdd() {
executeOk_servald rhizome export bundle $manifestid file1x.manifest file1x executeOk_servald rhizome export bundle $manifestid file1x.manifest file1x
tfw_cat --stdout --stderr tfw_cat --stdout --stderr
assertStdoutLineCount '==' 8 assertStdoutLineCount '==' 9
local size=$(( $(cat file1 | wc -c) + 0 )) local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^service:file$" assertStdoutGrep --matches=1 "^service:file$"
assertStdoutGrep --matches=1 "^manifestid:$manifestid\$" assertStdoutGrep --matches=1 "^manifestid:$manifestid\$"
@ -253,6 +254,7 @@ test_ExtractManifestFileAfterAdd() {
assertStdoutGrep --matches=1 "^filehash:$filehash\$" assertStdoutGrep --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --matches=1 "^filesize:$size\$" assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^\.author:$SIDB1\$" assertStdoutGrep --matches=1 "^\.author:$SIDB1\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$" assertStdoutGrep --matches=1 "^\.readonly:0\$"
assert [ -e file1x.manifest ] assert [ -e file1x.manifest ]
assert diff file1.manifest file1x.manifest assert diff file1.manifest file1x.manifest
@ -282,7 +284,7 @@ setup_ExtractManifestFileFromExtBlob() {
test_ExtractManifestFileFromExtBlob() { test_ExtractManifestFileFromExtBlob() {
executeOk_servald rhizome export bundle $manifestid1 file1x.manifest file1x executeOk_servald rhizome export bundle $manifestid1 file1x.manifest file1x
tfw_cat --stdout --stderr tfw_cat --stdout --stderr
assertStdoutLineCount '==' 8 assertStdoutLineCount '==' 9
local size=$(( $(cat file1 | wc -c) + 0 )) local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^service:file$" assertStdoutGrep --matches=1 "^service:file$"
assertStdoutGrep --matches=1 "^manifestid:$manifestid1\$" assertStdoutGrep --matches=1 "^manifestid:$manifestid1\$"
@ -291,6 +293,7 @@ test_ExtractManifestFileFromExtBlob() {
assertStdoutGrep --matches=1 "^filehash:$filehash1\$" assertStdoutGrep --matches=1 "^filehash:$filehash1\$"
assertStdoutGrep --matches=1 "^filesize:$size\$" assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^\.author:$SIDB1\$" assertStdoutGrep --matches=1 "^\.author:$SIDB1\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$" assertStdoutGrep --matches=1 "^\.readonly:0\$"
assert [ -e file1x.manifest ] assert [ -e file1x.manifest ]
assert diff file1.manifest file1x.manifest assert diff file1.manifest file1x.manifest
@ -298,7 +301,7 @@ test_ExtractManifestFileFromExtBlob() {
assert diff file1 file1x assert diff file1 file1x
executeOk_servald rhizome export bundle $manifestid2 file2x.manifest file2x executeOk_servald rhizome export bundle $manifestid2 file2x.manifest file2x
tfw_cat --stdout --stderr tfw_cat --stdout --stderr
assertStdoutLineCount '==' 8 assertStdoutLineCount '==' 9
local size=$(( $(cat file2 | wc -c) + 0 )) local size=$(( $(cat file2 | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^service:file$" assertStdoutGrep --matches=1 "^service:file$"
assertStdoutGrep --matches=1 "^manifestid:$manifestid2\$" assertStdoutGrep --matches=1 "^manifestid:$manifestid2\$"
@ -307,6 +310,7 @@ test_ExtractManifestFileFromExtBlob() {
assertStdoutGrep --matches=1 "^filehash:$filehash2\$" assertStdoutGrep --matches=1 "^filehash:$filehash2\$"
assertStdoutGrep --matches=1 "^filesize:$size\$" assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^\.author:$SIDB1\$" assertStdoutGrep --matches=1 "^\.author:$SIDB1\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$" assertStdoutGrep --matches=1 "^\.readonly:0\$"
assert [ -e file2x.manifest ] assert [ -e file2x.manifest ]
assert diff file2.manifest file2x.manifest assert diff file2.manifest file2x.manifest
@ -344,17 +348,18 @@ test_ExtractManifestToStdout() {
executeOk_servald rhizome export manifest $manifestid - executeOk_servald rhizome export manifest $manifestid -
assertStdoutLineCount '>=' 9 assertStdoutLineCount '>=' 9
local size=$(( $(cat file1 | wc -c) + 0 )) local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutGrep --line=..8 --matches=1 "^service:file$" assertStdoutGrep --line=..9 --matches=1 "^service:file$"
assertStdoutGrep --line=..8 --matches=1 "^manifestid:$manifestid\$" assertStdoutGrep --line=..9 --matches=1 "^manifestid:$manifestid\$"
assertStdoutGrep --line=..8 --matches=1 "^version:$version\$" assertStdoutGrep --line=..9 --matches=1 "^version:$version\$"
assertStdoutGrep --line=..8 --matches=1 "^inserttime:$rexp_date\$" assertStdoutGrep --line=..9 --matches=1 "^inserttime:$rexp_date\$"
assertStdoutGrep --line=..8 --matches=1 "^filehash:$filehash\$" assertStdoutGrep --line=..9 --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --line=..8 --matches=1 "^filesize:$size\$" assertStdoutGrep --line=..9 --matches=1 "^filesize:$size\$"
assertStdoutGrep --line=..8 --matches=1 "^\.author:$SIDB1\$" assertStdoutGrep --line=..9 --matches=1 "^\.author:$SIDB1\$"
assertStdoutGrep --line=..8 --matches=1 "^\.readonly:0\$" assertStdoutGrep --line=..9 --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --line=9 --matches=1 "^manifest:" assertStdoutGrep --line=..9 --matches=1 "^\.readonly:0\$"
replayStdout | $SED -n '9s/^manifest://p' >file1x.manifest assertStdoutGrep --line=10 --matches=1 "^manifest:"
replayStdout | $SED -n '10,$p' >>file1x.manifest replayStdout | $SED -n '10s/^manifest://p' >file1x.manifest
replayStdout | $SED -n '11,$p' >>file1x.manifest
cat file1.manifest >file1n.manifest cat file1.manifest >file1n.manifest
echo >>file1n.manifest echo >>file1n.manifest
tfw_cat file1n.manifest file1x.manifest tfw_cat file1n.manifest file1x.manifest
@ -434,7 +439,7 @@ test_ExtractFileAfterAdd() {
tfw_cat --stderr tfw_cat --stderr
assert diff file1 file1x assert diff file1 file1x
local size=$(( $(cat file1 | wc -c) + 0 )) local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutLineCount '==' 8 assertStdoutLineCount '==' 9
assertStdoutGrep --matches=1 "^service:file$" assertStdoutGrep --matches=1 "^service:file$"
assertStdoutGrep --matches=1 "^manifestid:$manifestid\$" assertStdoutGrep --matches=1 "^manifestid:$manifestid\$"
assertStdoutGrep --matches=1 "^version:$version\$" assertStdoutGrep --matches=1 "^version:$version\$"
@ -442,6 +447,7 @@ test_ExtractFileAfterAdd() {
assertStdoutGrep --matches=1 "^filehash:$filehash\$" assertStdoutGrep --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --matches=1 "^filesize:$size\$" assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^\.author:$SIDB1\$" assertStdoutGrep --matches=1 "^\.author:$SIDB1\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$" assertStdoutGrep --matches=1 "^\.readonly:0\$"
} }
@ -1020,7 +1026,7 @@ test_ImportOwnBundle() {
tfw_cat --stderr tfw_cat --stderr
assert cmp fileB.manifest fileBx.manifest assert cmp fileB.manifest fileBx.manifest
assert cmp fileB fileBx assert cmp fileB fileBx
assertStdoutLineCount '==' 8 assertStdoutLineCount '==' 9
local size=$(( $(cat fileB | wc -c) + 0 )) local size=$(( $(cat fileB | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^service:file$" assertStdoutGrep --matches=1 "^service:file$"
assertStdoutGrep --matches=1 "^manifestid:$manifestid\$" assertStdoutGrep --matches=1 "^manifestid:$manifestid\$"
@ -1029,6 +1035,7 @@ test_ImportOwnBundle() {
assertStdoutGrep --matches=1 "^filehash:$filehash\$" assertStdoutGrep --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --matches=1 "^filesize:$size\$" assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^\.author:$SIDB2\$" assertStdoutGrep --matches=1 "^\.author:$SIDB2\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$" assertStdoutGrep --matches=1 "^\.readonly:0\$"
# Now bundle author should be known, so appears to be from here # Now bundle author should be known, so appears to be from here
executeOk_servald rhizome list executeOk_servald rhizome list