un-writable directory test

This commit is contained in:
meejah 2021-01-04 15:39:08 -07:00
parent 613a6f80aa
commit 30e3cd23da
2 changed files with 26 additions and 3 deletions

View File

@ -194,10 +194,16 @@ def sign(ctx, name, expiry_days):
next_serial = 0
f = None
while f is None:
fname = "{}.cert.{}".format(name, next_serial)
try:
f = fp.child("{}.cert.{}".format(name, next_serial)).create()
except OSError:
f = fp.child(fname).create()
except OSError as e:
if e.errno == 17: # file exists
f = None
else:
raise click.ClickException(
"{}: {}".format(fname, e)
)
next_serial += 1
with f:
f.write(certificate_data)

View File

@ -164,6 +164,23 @@ class GridManagerCommandLine(SyncTestCase):
result.output,
)
def test_sign_bad_perms(self):
"""
Error reported if we can't create certificate file
"""
pubkey = "pub-v0-cbq6hcf3pxcz6ouoafrbktmkixkeuywpcpbcomzd3lqbkq4nmfga"
with self.runner.isolated_filesystem():
self.runner.invoke(grid_manager, ["--config", "foo", "create"])
self.runner.invoke(grid_manager, ["--config", "foo", "add", "storage0", pubkey])
# make the directory un-writable (so we can't create a new cert)
os.chmod("foo", 0o550)
result = self.runner.invoke(grid_manager, ["--config", "foo", "sign", "storage0", "42"])
self.assertEquals(result.exit_code, 1)
self.assertIn(
"Permission denied",
result.output,
)
class TahoeAddGridManagerCert(AsyncTestCase):
"""