Remove "rhizome add authored file" command

Now "rhizome add file" takes SID and PIN args, and if SID is empty, an
unauthored bundle (no BK field) is created

Updated dna_rhizome test cases
This commit is contained in:
Andrew Bettison 2012-05-17 12:00:03 +09:30
parent e64469d3e9
commit 2434d51bee
4 changed files with 78 additions and 46 deletions

View File

@ -1052,13 +1052,18 @@ int app_config_get(int argc, const char *const *argv, struct command_line_option
return 0;
}
int cli_optional_sid(const char *arg)
{
return !arg[0] || validateSid(arg);
}
int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_option *o)
{
const char *filepath, *manifestpath,*authorisingSid,*pin;
const char *filepath, *manifestpath, *authorSid, *pin;
cli_arg(argc, argv, o, "filepath", &filepath, NULL, "");
cli_arg(argc, argv, o, "author_sid", &authorSid, cli_optional_sid, "");
cli_arg(argc, argv, o, "pin", &pin, NULL, "");
cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, "");
cli_arg(argc, argv, o, "sid", &authorisingSid,NULL,"");
cli_arg(argc, argv, o, "pin", &pin,NULL,"");
keyring=keyring_open_with_pins(pin);
if (!keyring) { WHY("keyring add: Failed to create/open keyring file");
@ -1098,14 +1103,15 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_
/* Add the manifest and its associated file to the Rhizome database, generating an "id" in the
* process */
rhizome_manifest *mout = NULL;
WHYF("calling rhizome_add_manifest, author='%s'",authorisingSid);
int ret = rhizome_add_manifest(m, &mout, filepath,
if (debug & DEBUG_RHIZOME) DEBUGF("rhizome_add_manifest(author='%s')", authorSid);
int ret = rhizome_add_manifest(
m, &mout, filepath,
NULL, // no groups - XXX should allow them
255, // ttl - XXX should read from somewhere
manifest_file_supplied, // int verifyP
1, // int checkFileP
1, // int signP
authorisingSid // SID of claiming author as hex, so that they can modify the bundle later
authorSid[0] ? authorSid : NULL // SID of author as hex, so that they can modify the bundle later
);
if (ret == -1)
return WHY("Manifest not added to Rhizome database");
@ -1205,11 +1211,6 @@ int cli_uint(const char *arg)
return s != arg && *s == '\0';
}
int cli_optional_sid(const char *arg)
{
return !arg[0] || validateSid(arg);
}
int app_rhizome_list(int argc, const char *const *argv, struct command_line_option *o)
{
const char *service, *sender_sid, *recipient_sid, *offset, *limit;
@ -1526,10 +1527,8 @@ command_line_option command_line_options[]={
"Set specified configuration variable."},
{app_config_get,{"config","get","[<variable>]",NULL},CLIFLAG_STANDALONE,
"Get specified configuration variable."},
{app_rhizome_add_file,{"rhizome","add","file","<filepath>","[<manifestpath>]",NULL},CLIFLAG_STANDALONE,
{app_rhizome_add_file,{"rhizome","add","file","<author_sid>","<pin>","<filepath>","[<manifestpath>]",NULL},CLIFLAG_STANDALONE,
"Add a file to Rhizome and optionally write its manifest to the given path"},
{app_rhizome_add_file,{"rhizome","add","authored","file","<filepath>","<sid>","<pin>","[<manifestpath>]",NULL},CLIFLAG_STANDALONE,
"Add a file to Rhizome and remember who authored it, so that they can modify the bundle later."},
{app_rhizome_list,{"rhizome","list","[<service>]","[<sender_sid>]","[<recipient_sid>]","[<offset>]","[<limit>]",NULL},CLIFLAG_STANDALONE,
"List all manifests and files in Rhizome"},
{app_rhizome_extract_manifest,{"rhizome","extract","manifest","<manifestid>","[<manifestpath>]",NULL},CLIFLAG_STANDALONE,

View File

@ -55,8 +55,8 @@ int rhizome_bundle_import(rhizome_manifest *m_in, rhizome_manifest **m_out, cons
rhizome_manifest *dupm;
int ret = rhizome_add_manifest(m, &dupm, filename, groups, ttl,
verifyP, checkFileP, signP,
NULL /* don't specify author for manifests
received via mesh */);
NULL /* don't specify author for manifests received via mesh */
);
unlink(filename);
if (ret == -1) {
unlink(manifestname);
@ -141,7 +141,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,
int verifyP, // verify that file's hash is consistent with manifest
int checkFileP,
int signP,
const char *author
const char *author // NULL to make an unauthored manifest
)
{
if (m_out) *m_out = NULL;
@ -248,7 +248,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,
}
/* Check if we know its private key */
rhizome_hex_to_bytes(id, m_in->cryptoSignPublic, crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES*2);
if (!rhizome_extract_privatekey(m_in,author))
if (!rhizome_extract_privatekey(m_in, author))
m_in->haveSecret=1;
} else {
/* The manifest had no ID (256 bit random string being a public key in the NaCl CryptoSign
@ -273,8 +273,8 @@ int rhizome_add_manifest(rhizome_manifest *m_in,
if (!rhizome_bk_xor(author,m_in->cryptoSignPublic,
m_in->cryptoSignSecret,
bkbytes)) {
WHYF("set BK='%s'",rhizome_bytes_to_hex(bkbytes,len));
rhizome_manifest_set(m_in,"BK",rhizome_bytes_to_hex(bkbytes,len));
if (debug&DEBUG_RHIZOME) DEBUGF("set BK='%s'", rhizome_bytes_to_hex(bkbytes,len));
rhizome_manifest_set(m_in, "BK", rhizome_bytes_to_hex(bkbytes,len));
} else {
WHY("Failed to set BK");
}
@ -289,7 +289,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,
}
/* Finish completing the manifest */
if (rhizome_manifest_finalise(m_in, signP,author))
if (rhizome_manifest_finalise(m_in, signP, author))
return WHY("Failed to finalise manifest.\n");
/* Okay, it is written, and can be put directly into the rhizome database now */

View File

@ -150,14 +150,14 @@ realpath() {
}
execute() {
echo "# execute $*"
echo -n "# execute "; _tfw_shellarg "$@"
_tfw_getopts execute "$@"
shift $_tfw_getopts_shift
_tfw_execute "$@"
}
executeOk() {
echo "# executeOk $*"
echo -n "# executeOk "; _tfw_shellarg "$@"
_tfw_getopts executeok "$@"
_tfw_opt_exit_status=0
_tfw_dump_on_fail --stderr
@ -169,7 +169,7 @@ assert() {
_tfw_getopts assert "$@"
shift $_tfw_getopts_shift
_tfw_assert "$@" || _tfw_failexit
echo "# assert $*"
echo -n "# assert "; _tfw_shellarg "$@"
return 0
}
@ -179,7 +179,7 @@ assertExpr() {
local awkexpr=$(_tfw_expr_to_awkexpr "$@")
_tfw_message="${_tfw_message+$_tfw_message }($awkexpr)"
_tfw_assert _tfw_eval_awkexpr "$awkexpr" || _tfw_failexit
echo "# assert $awkexpr"
echo -n "# assertExpr "; _tfw_shellarg "$awkexpr"
return 0
}
@ -335,6 +335,23 @@ _tfw_shopt_restore() {
# The rest of this file is parsed for extended glob patterns.
_tfw_shopt -s extglob
# Add shell quotation to the given arguments, so that when expanded using
# 'eval', the exact same argument results. This makes argument handling fully
# immune to spaces and shell metacharacters.
_tfw_shellarg() {
local arg
local -a shellarg=()
_tfw_shopt -s extglob
for arg; do
case "$arg" in
+([A-Za-z_0-9.,+\/-])) shellarg+=("$arg");;
*) shellarg+=("'${arg//'/'\\''}'");;
esac
done
_tfw_shopt_restore
echo "${shellarg[@]}"
}
# Echo the absolute path of the given path, using only Bash builtins.
_tfw_abspath() {
cdopt=-L

View File

@ -23,7 +23,11 @@ source "${0%/*}/../testdefs.sh"
setup_dna_rhizome() {
setup_dna "$@"
executeOk $dna config set debug rhizome
executeOk $dna config set debug.rhizome on
executeOk $dna keyring add
executeOk $dna keyring list
sid=$(replayStdout | sed -ne '1s/^\([0-9a-fA-F]\{64\}\):.*$/\1/p')
assert --message='identity known' [ -n "$sid" ]
}
assert_rhizome_list() {
@ -116,6 +120,18 @@ test_InitialEmptyList() {
assert_rhizome_list
}
doc_AddNoAuthorNoManifest="Add with no author and no manifest file"
setup_AddNoAuthorNoManifest() {
setup_dna_rhizome
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddNoAuthorNoManifest() {
executeOk $dna rhizome add file '' '' file1
assert_stdout_add_file file1
}
doc_AddNoManifest="Add with no manifest file"
setup_AddNoManifest() {
setup_dna_rhizome
@ -124,7 +140,7 @@ setup_AddNoManifest() {
echo "Another test file" >file2
}
test_AddNoManifest() {
executeOk $dna rhizome add file file1
executeOk $dna rhizome add file $sid '' file1
assert_stdout_add_file file1
}
@ -137,7 +153,7 @@ setup_AddNonExistManifest() {
}
test_AddNonExistManifest() {
assert --error-on-fail [ ! -e file1.manifest ]
executeOk $dna rhizome add file file1 file1.manifest
executeOk $dna rhizome add file $sid '' file1 file1.manifest
assert_stdout_add_file file1
assert [ -r file1.manifest ]
tfw_cat -v file1.manifest
@ -158,7 +174,7 @@ setup_AddManifest() {
echo "Another test file" >file2
}
test_AddManifest() {
executeOk $dna rhizome add file file1 file1.manifest
executeOk $dna rhizome add file $sid '' file1 file1.manifest
tfw_cat --stdout --stderr -v file1.manifest
assert_stdout_add_file file1 wah
assertGrep file1.manifest '^name=wah$'
@ -178,10 +194,10 @@ setup_AddThenList() {
}
test_AddThenList() {
# Add first file
executeOk $dna rhizome add file file1 file1.manifest
executeOk $dna rhizome add file $sid '' file1 file1.manifest
assert_rhizome_list file1
# Add second file
executeOk $dna rhizome add file file2 file2.manifest
executeOk $dna rhizome add file $sid '' file2 file2.manifest
assert_rhizome_list file1 file2
}
@ -189,7 +205,7 @@ doc_AddThenExtractManifest="Extract manifest after one add"
setup_AddThenExtractManifest() {
setup_dna_rhizome
echo "A test file" >file1
executeOk $dna rhizome add file file1 file1.manifest
executeOk $dna rhizome add file $sid '' file1 file1.manifest
assert_rhizome_list file1
extract_manifest_id manifestid file1.manifest
extract_manifest_version version file1.manifest
@ -238,7 +254,7 @@ doc_AddThenExtractFile="Extract file after one add"
setup_AddThenExtractFile() {
setup_dna_rhizome
echo "A test file" >file1
executeOk $dna rhizome add file file1 file1.manifest
executeOk $dna rhizome add file $sid '' file1 file1.manifest
assert_rhizome_list file1
extract_manifest_filehash filehash file1.manifest
}
@ -286,9 +302,9 @@ setup_AddDuplicate() {
echo "Another test file" >file2
echo "A test file, second version" >file1_2
# Add first file
executeOk $dna rhizome add file file1 file1.manifest
executeOk $dna rhizome add file $sid '' file1 file1.manifest
# Add second file
executeOk $dna rhizome add file file2 file2.manifest
executeOk $dna rhizome add file $sid '' file2 file2.manifest
# Make sure they are both in the list.
assert_rhizome_list file1 file2
}
@ -296,14 +312,14 @@ test_AddDuplicate() {
# Add first file again - nothing should change in its manifests, and it
# should appear that the add command succeeded (with perhaps some grumbling
# on stderr).
execute --exit-status=2 $dna rhizome add file file1 file1.manifestA
execute --exit-status=2 $dna rhizome add file $sid '' file1 file1.manifestA
assert [ -s file1.manifestA ]
assert_stdout_add_file file1
assert_rhizome_list file1 file2
strip_signatures file1.manifest file1.manifestA
assert diff file1.manifest file1.manifestA
# Repeat for second file.
execute --exit-status=2 $dna rhizome add file file2 file2.manifestA
execute --exit-status=2 $dna rhizome add file $sid '' file2 file2.manifestA
assert [ -s file2.manifestA ]
assert_stdout_add_file file2
assert_rhizome_list file1 file2
@ -319,7 +335,7 @@ test_AddMismatched() {
# Try to add another file using an existing manifest, should fail and leave
# the manifest file unchanged.
cp file1.manifest file1_2.manifest
execute $dna rhizome add file file1_2 file1_2.manifest
execute $dna rhizome add file $sid '' file1_2 file1_2.manifest
assertExitStatus '!=' 0
assert cmp file1.manifest file1_2.manifest
# And rhizome store should be unchanged.
@ -340,7 +356,7 @@ setup_AddUpdateSameVersion() {
}
test_AddUpdateSameVersion() {
tfw_cat -v file1_2.manifest
execute $dna rhizome add file file1_2 file1_2.manifest
execute $dna rhizome add file $sid '' file1_2 file1_2.manifest
assertExitStatus --stderr '!=' 0
tfw_cat -v file1_2.manifest
assert cmp file1_2.manifest file1_2.manifest.orig
@ -358,7 +374,7 @@ setup_AddUpdateNewVersion() {
}
test_AddUpdateNewVersion() {
tfw_cat -v file1_2.manifest
executeOk $dna rhizome add file file1_2 file1_2.manifest
executeOk $dna rhizome add file $sid '' file1_2 file1_2.manifest
assert_stdout_add_file file1_2 file1
assert_manifest_newer file1.manifest file1_2.manifest
# Rhizome store contents reflect new payload.
@ -375,7 +391,7 @@ setup_AddUpdateAutoVersion() {
test_AddUpdateAutoVersion() {
tfw_cat -v file1_2.manifest
sleep 0.001 # Ensure that at least one millisecond has elapsed
executeOk $dna rhizome add file file1_2 file1_2.manifest
executeOk $dna rhizome add file $sid '' file1_2 file1_2.manifest
assert_manifest_newer file1.manifest file1_2.manifest
# Rhizome store contents reflect new payload.
mv -f file1_2.manifest file1.manifest