2007-10-11 07:30:36 +00:00
|
|
|
|
|
|
|
from twisted.trial import unittest
|
2008-01-14 20:43:25 +00:00
|
|
|
from cStringIO import StringIO
|
2008-01-14 21:12:27 +00:00
|
|
|
import urllib
|
2007-10-11 07:30:36 +00:00
|
|
|
|
2008-01-14 20:43:25 +00:00
|
|
|
from allmydata.util import fileutil, hashutil
|
2007-10-11 07:30:36 +00:00
|
|
|
from allmydata import uri
|
|
|
|
|
|
|
|
# at least import the CLI scripts, even if we don't have any real tests for
|
|
|
|
# them yet.
|
2008-01-14 20:43:25 +00:00
|
|
|
from allmydata.scripts import tahoe_ls, tahoe_get, tahoe_put, tahoe_rm
|
2007-10-11 08:55:29 +00:00
|
|
|
_hush_pyflakes = [tahoe_ls, tahoe_get, tahoe_put, tahoe_rm]
|
2007-10-11 07:30:36 +00:00
|
|
|
|
2008-01-14 20:43:25 +00:00
|
|
|
from allmydata.scripts import cli, debug
|
|
|
|
|
2007-10-11 07:30:36 +00:00
|
|
|
|
|
|
|
class CLI(unittest.TestCase):
|
|
|
|
def test_options(self):
|
|
|
|
fileutil.rm_dir("cli/test_options")
|
|
|
|
fileutil.make_dirs("cli/test_options")
|
2008-01-04 00:48:53 +00:00
|
|
|
fileutil.make_dirs("cli/test_options/private")
|
2007-10-11 07:30:36 +00:00
|
|
|
open("cli/test_options/node.url","w").write("http://localhost:8080/\n")
|
2007-12-05 00:00:58 +00:00
|
|
|
filenode_uri = uri.WriteableSSKFileURI(writekey="\x00"*16,
|
|
|
|
fingerprint="\x00"*32)
|
|
|
|
private_uri = uri.NewDirectoryURI(filenode_uri).to_string()
|
2008-01-04 00:48:53 +00:00
|
|
|
open("cli/test_options/private/root_dir.cap", "w").write(private_uri + "\n")
|
2007-10-11 07:30:36 +00:00
|
|
|
o = cli.ListOptions()
|
|
|
|
o.parseOptions(["--node-directory", "cli/test_options"])
|
|
|
|
self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
|
2008-01-08 17:41:27 +00:00
|
|
|
self.failUnlessEqual(o['dir-cap'], private_uri)
|
2007-10-11 07:30:36 +00:00
|
|
|
self.failUnlessEqual(o['vdrive_pathname'], "")
|
|
|
|
|
|
|
|
o = cli.ListOptions()
|
|
|
|
o.parseOptions(["--node-directory", "cli/test_options",
|
|
|
|
"--node-url", "http://example.org:8111/"])
|
|
|
|
self.failUnlessEqual(o['node-url'], "http://example.org:8111/")
|
2008-01-08 17:41:27 +00:00
|
|
|
self.failUnlessEqual(o['dir-cap'], private_uri)
|
2007-10-11 07:30:36 +00:00
|
|
|
self.failUnlessEqual(o['vdrive_pathname'], "")
|
|
|
|
|
|
|
|
o = cli.ListOptions()
|
|
|
|
o.parseOptions(["--node-directory", "cli/test_options",
|
2008-01-08 17:41:27 +00:00
|
|
|
"--dir-cap", "root"])
|
2007-10-11 07:30:36 +00:00
|
|
|
self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
|
2008-01-08 17:41:27 +00:00
|
|
|
self.failUnlessEqual(o['dir-cap'], private_uri)
|
2007-10-11 07:30:36 +00:00
|
|
|
self.failUnlessEqual(o['vdrive_pathname'], "")
|
|
|
|
|
|
|
|
o = cli.ListOptions()
|
2007-12-03 21:52:42 +00:00
|
|
|
o.parseOptions(["--node-directory", "cli/test_options"])
|
2007-10-11 07:30:36 +00:00
|
|
|
self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
|
|
|
|
self.failUnlessEqual(o['vdrive_pathname'], "")
|
|
|
|
|
|
|
|
o = cli.ListOptions()
|
2007-12-05 00:00:58 +00:00
|
|
|
other_filenode_uri = uri.WriteableSSKFileURI(writekey="\x11"*16,
|
|
|
|
fingerprint="\x11"*32)
|
|
|
|
other_uri = uri.NewDirectoryURI(other_filenode_uri).to_string()
|
2007-10-11 07:30:36 +00:00
|
|
|
o.parseOptions(["--node-directory", "cli/test_options",
|
2008-01-08 17:41:27 +00:00
|
|
|
"--dir-cap", other_uri])
|
2007-10-11 07:30:36 +00:00
|
|
|
self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
|
2008-01-08 17:41:27 +00:00
|
|
|
self.failUnlessEqual(o['dir-cap'], other_uri)
|
2007-10-11 07:30:36 +00:00
|
|
|
self.failUnlessEqual(o['vdrive_pathname'], "")
|
|
|
|
|
|
|
|
o = cli.ListOptions()
|
|
|
|
o.parseOptions(["--node-directory", "cli/test_options",
|
2008-01-08 17:41:27 +00:00
|
|
|
"--dir-cap", other_uri, "subdir"])
|
2007-10-11 07:30:36 +00:00
|
|
|
self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
|
2008-01-08 17:41:27 +00:00
|
|
|
self.failUnlessEqual(o['dir-cap'], other_uri)
|
2007-10-11 07:30:36 +00:00
|
|
|
self.failUnlessEqual(o['vdrive_pathname'], "subdir")
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
def _dump_cap(self, *args):
|
|
|
|
out,err = StringIO(), StringIO()
|
|
|
|
config = debug.DumpCapOptions()
|
|
|
|
config.parseOptions(args)
|
|
|
|
debug.dump_cap(config, out, err)
|
|
|
|
self.failIf(err.getvalue())
|
|
|
|
output = out.getvalue()
|
|
|
|
return output
|
|
|
|
|
|
|
|
def test_dump_cap_chk(self):
|
|
|
|
key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
2008-02-01 19:27:37 +00:00
|
|
|
storage_index = hashutil.storage_index_hash(key)
|
2008-01-14 20:43:25 +00:00
|
|
|
uri_extension_hash = hashutil.uri_extension_hash("stuff")
|
|
|
|
needed_shares = 25
|
|
|
|
total_shares = 100
|
|
|
|
size = 1234
|
|
|
|
u = uri.CHKFileURI(key=key,
|
|
|
|
uri_extension_hash=uri_extension_hash,
|
|
|
|
needed_shares=needed_shares,
|
|
|
|
total_shares=total_shares,
|
|
|
|
size=size)
|
|
|
|
output = self._dump_cap(u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("CHK File:" in output, output)
|
2008-02-15 02:27:47 +00:00
|
|
|
self.failUnless("key: aaaqeayeaudaocajbifqydiob4" in output, output)
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("UEB hash: nf3nimquen7aeqm36ekgxomalstenpkvsdmf6fplj7swdatbv5oa" in output, output)
|
|
|
|
self.failUnless("size: 1234" in output, output)
|
|
|
|
self.failUnless("k/N: 25/100" in output, output)
|
|
|
|
self.failUnless("storage index: hdis5iaveku6lnlaiccydyid7q" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2008-02-15 02:27:47 +00:00
|
|
|
output = self._dump_cap("--client-secret", "5s33nk3qpvnj2fw3z4mnm2y6fa",
|
2008-01-14 20:43:25 +00:00
|
|
|
u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("client renewal secret: znxmki5zdibb5qlt46xbdvk2t55j7hibejq3i5ijyurkr6m6jkhq" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
output = self._dump_cap(u.get_verifier().to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failIf("key: " in output, output)
|
|
|
|
self.failUnless("UEB hash: nf3nimquen7aeqm36ekgxomalstenpkvsdmf6fplj7swdatbv5oa" in output, output)
|
|
|
|
self.failUnless("size: 1234" in output, output)
|
|
|
|
self.failUnless("k/N: 25/100" in output, output)
|
|
|
|
self.failUnless("storage index: hdis5iaveku6lnlaiccydyid7q" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2008-01-14 21:12:27 +00:00
|
|
|
prefixed_u = "http://127.0.0.1/uri/%s" % urllib.quote(u.to_string())
|
|
|
|
output = self._dump_cap(prefixed_u)
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("CHK File:" in output, output)
|
2008-02-15 02:27:47 +00:00
|
|
|
self.failUnless("key: aaaqeayeaudaocajbifqydiob4" in output, output)
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("UEB hash: nf3nimquen7aeqm36ekgxomalstenpkvsdmf6fplj7swdatbv5oa" in output, output)
|
|
|
|
self.failUnless("size: 1234" in output, output)
|
|
|
|
self.failUnless("k/N: 25/100" in output, output)
|
|
|
|
self.failUnless("storage index: hdis5iaveku6lnlaiccydyid7q" in output, output)
|
2008-01-14 21:12:27 +00:00
|
|
|
|
2008-01-14 20:43:25 +00:00
|
|
|
def test_dump_cap_lit(self):
|
|
|
|
u = uri.LiteralFileURI("this is some data")
|
|
|
|
output = self._dump_cap(u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("Literal File URI:" in output, output)
|
|
|
|
self.failUnless("data: this is some data" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
def test_dump_cap_ssk(self):
|
|
|
|
writekey = "\x01" * 16
|
|
|
|
fingerprint = "\xfe" * 32
|
|
|
|
u = uri.WriteableSSKFileURI(writekey, fingerprint)
|
|
|
|
|
|
|
|
output = self._dump_cap(u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("SSK Writeable URI:" in output, output)
|
2008-02-15 02:27:47 +00:00
|
|
|
self.failUnless("writekey: aeaqcaibaeaqcaibaeaqcaibae" in output, output)
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("readkey: nvgh5vj2ekzzkim5fgtb4gey5y" in output, output)
|
|
|
|
self.failUnless("storage index: nt4fwemuw7flestsezvo2eveke" in output, output)
|
2008-02-15 02:27:47 +00:00
|
|
|
self.failUnless("fingerprint: 737p57x6737p57x6737p57x6737p57x6737p57x6737p57x6737a" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2008-02-15 02:58:01 +00:00
|
|
|
output = self._dump_cap("--client-secret", "5s33nk3qpvnj2fw3z4mnm2y6fa",
|
2008-01-14 20:43:25 +00:00
|
|
|
u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("file renewal secret: arpszxzc2t6kb4okkg7sp765xgkni5z7caavj7lta73vmtymjlxq" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
fileutil.make_dirs("cli/test_dump_cap/private")
|
|
|
|
f = open("cli/test_dump_cap/private/secret", "w")
|
2008-02-15 02:58:01 +00:00
|
|
|
f.write("5s33nk3qpvnj2fw3z4mnm2y6fa\n")
|
2008-01-14 20:43:25 +00:00
|
|
|
f.close()
|
|
|
|
output = self._dump_cap("--client-dir", "cli/test_dump_cap",
|
|
|
|
u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("file renewal secret: arpszxzc2t6kb4okkg7sp765xgkni5z7caavj7lta73vmtymjlxq" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
output = self._dump_cap("--client-dir", "cli/test_dump_cap_BOGUS",
|
|
|
|
u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failIf("file renewal secret:" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
output = self._dump_cap("--nodeid", "tqc35esocrvejvg4mablt6aowg6tl43j",
|
|
|
|
u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("write_enabler: mgcavriox2wlb5eer26unwy5cw56elh3sjweffckkmivvsxtaknq" in output, output)
|
|
|
|
self.failIf("file renewal secret:" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
output = self._dump_cap("--nodeid", "tqc35esocrvejvg4mablt6aowg6tl43j",
|
2008-02-15 02:58:01 +00:00
|
|
|
"--client-secret", "5s33nk3qpvnj2fw3z4mnm2y6fa",
|
2008-01-14 20:43:25 +00:00
|
|
|
u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("write_enabler: mgcavriox2wlb5eer26unwy5cw56elh3sjweffckkmivvsxtaknq" in output, output)
|
|
|
|
self.failUnless("file renewal secret: arpszxzc2t6kb4okkg7sp765xgkni5z7caavj7lta73vmtymjlxq" in output, output)
|
|
|
|
self.failUnless("lease renewal secret: 7pjtaumrb7znzkkbvekkmuwpqfjyfyamznfz4bwwvmh4nw33lorq" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
u = u.get_readonly()
|
|
|
|
output = self._dump_cap(u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("SSK Read-only URI:" in output, output)
|
|
|
|
self.failUnless("readkey: nvgh5vj2ekzzkim5fgtb4gey5y" in output, output)
|
|
|
|
self.failUnless("storage index: nt4fwemuw7flestsezvo2eveke" in output, output)
|
|
|
|
self.failUnless("fingerprint: 737p57x6737p57x6737p57x6737p57x6737p57x6737p57x6737a" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
u = u.get_verifier()
|
|
|
|
output = self._dump_cap(u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("SSK Verifier URI:" in output, output)
|
|
|
|
self.failUnless("storage index: nt4fwemuw7flestsezvo2eveke" in output, output)
|
|
|
|
self.failUnless("fingerprint: 737p57x6737p57x6737p57x6737p57x6737p57x6737p57x6737a" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
def test_dump_cap_directory(self):
|
|
|
|
writekey = "\x01" * 16
|
|
|
|
fingerprint = "\xfe" * 32
|
|
|
|
u1 = uri.WriteableSSKFileURI(writekey, fingerprint)
|
|
|
|
u = uri.NewDirectoryURI(u1)
|
|
|
|
|
|
|
|
output = self._dump_cap(u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("Directory Writeable URI:" in output, output)
|
|
|
|
self.failUnless("writekey: aeaqcaibaeaqcaibaeaqcaibae" in output,
|
|
|
|
output)
|
|
|
|
self.failUnless("readkey: nvgh5vj2ekzzkim5fgtb4gey5y" in output, output)
|
|
|
|
self.failUnless("storage index: nt4fwemuw7flestsezvo2eveke" in output,
|
|
|
|
output)
|
2008-02-15 02:27:47 +00:00
|
|
|
self.failUnless("fingerprint: 737p57x6737p57x6737p57x6737p57x6737p57x6737p57x6737a" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2008-02-15 02:58:01 +00:00
|
|
|
output = self._dump_cap("--client-secret", "5s33nk3qpvnj2fw3z4mnm2y6fa",
|
2008-01-14 20:43:25 +00:00
|
|
|
u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("file renewal secret: arpszxzc2t6kb4okkg7sp765xgkni5z7caavj7lta73vmtymjlxq" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
output = self._dump_cap("--nodeid", "tqc35esocrvejvg4mablt6aowg6tl43j",
|
|
|
|
u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("write_enabler: mgcavriox2wlb5eer26unwy5cw56elh3sjweffckkmivvsxtaknq" in output, output)
|
|
|
|
self.failIf("file renewal secret:" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
output = self._dump_cap("--nodeid", "tqc35esocrvejvg4mablt6aowg6tl43j",
|
2008-02-15 02:58:01 +00:00
|
|
|
"--client-secret", "5s33nk3qpvnj2fw3z4mnm2y6fa",
|
2008-01-14 20:43:25 +00:00
|
|
|
u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("write_enabler: mgcavriox2wlb5eer26unwy5cw56elh3sjweffckkmivvsxtaknq" in output, output)
|
|
|
|
self.failUnless("file renewal secret: arpszxzc2t6kb4okkg7sp765xgkni5z7caavj7lta73vmtymjlxq" in output, output)
|
|
|
|
self.failUnless("lease renewal secret: 7pjtaumrb7znzkkbvekkmuwpqfjyfyamznfz4bwwvmh4nw33lorq" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
u = u.get_readonly()
|
|
|
|
output = self._dump_cap(u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("Directory Read-only URI:" in output, output)
|
|
|
|
self.failUnless("readkey: nvgh5vj2ekzzkim5fgtb4gey5y" in output, output)
|
|
|
|
self.failUnless("storage index: nt4fwemuw7flestsezvo2eveke" in output, output)
|
|
|
|
self.failUnless("fingerprint: 737p57x6737p57x6737p57x6737p57x6737p57x6737p57x6737a" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
u = u.get_verifier()
|
|
|
|
output = self._dump_cap(u.to_string())
|
2008-02-15 02:58:01 +00:00
|
|
|
self.failUnless("Directory Verifier URI:" in output, output)
|
|
|
|
self.failUnless("storage index: nt4fwemuw7flestsezvo2eveke" in output, output)
|
2008-02-15 02:27:47 +00:00
|
|
|
self.failUnless("fingerprint: 737p57x6737p57x6737p57x6737p57x6737p57x6737p57x6737a" in output, output)
|
2008-01-14 20:43:25 +00:00
|
|
|
|