Skip to content
Snippets Groups Projects
Commit 4df5d044 authored by Moul's avatar Moul
Browse files

Use one option -af/--auth-file, AUTH_FILE_PATH context (#420)

For CLI options clarity
Remove default auth file path for security reasons
Adapt test_checksum
parent 9e546c3d
No related branches found
No related tags found
1 merge request!240Drop auth-file default path #420, Use click.prompt(), click_context testing
Pipeline #32208 passed
......@@ -33,7 +33,7 @@ PUBSEC_SIGNKEY_PATTERN = "sec: ([1-9A-HJ-NP-Za-km-z]{87,90})"
def auth_method(ctx: click.Context) -> SigningKey:
if "AUTH_SEED" in ctx.obj and ctx.obj["AUTH_SEED"]:
return auth_by_seed()
if "AUTH_FILE" in ctx.obj and ctx.obj["AUTH_FILE"]:
if "AUTH_FILE_PATH" in ctx.obj and ctx.obj["AUTH_FILE_PATH"]:
return auth_by_auth_file()
if "AUTH_WIF" in ctx.obj and ctx.obj["AUTH_WIF"]:
return auth_by_wif()
......@@ -44,7 +44,7 @@ def auth_method(ctx: click.Context) -> SigningKey:
def has_auth_method(ctx: click.Context) -> bool:
return (
("AUTH_SCRYPT" in ctx.obj and ctx.obj["AUTH_SCRYPT"])
or ("AUTH_FILE" in ctx.obj and ctx.obj["AUTH_FILE"])
or ("AUTH_FILE_PATH" in ctx.obj and ctx.obj["AUTH_FILE_PATH"])
or ("AUTH_SEED" in ctx.obj and ctx.obj["AUTH_SEED"])
or ("AUTH_WIF" in ctx.obj and ctx.obj["AUTH_WIF"])
)
......
......@@ -69,14 +69,7 @@ from silkaj.wot.status import status
@option(
"--auth-file",
"-af",
is_flag=True,
help="Authentication file. Defaults to: './authfile'",
)
@option(
"--file",
default="authfile",
show_default=True,
help="Path file specification with '--auth-file'",
help="Authentication file path",
)
@option("--auth-seed", "--seed", is_flag=True, help="Seed hexadecimal authentication")
@option("--auth-wif", "--wif", is_flag=True, help="WIF and EWIF authentication methods")
......@@ -100,8 +93,7 @@ def cli(
gtest: bool,
auth_scrypt: bool,
nrp: str,
auth_file: bool,
file: str,
auth_file: str,
auth_seed: bool,
auth_wif: bool,
display: bool,
......@@ -116,8 +108,7 @@ def cli(
ctx.obj["GTEST"] = gtest
ctx.obj["AUTH_SCRYPT"] = auth_scrypt
ctx.obj["AUTH_SCRYPT_PARAMS"] = nrp
ctx.obj["AUTH_FILE"] = auth_file
ctx.obj["AUTH_FILE_PATH"] = file
ctx.obj["AUTH_FILE_PATH"] = auth_file
ctx.obj["AUTH_SEED"] = auth_seed
ctx.obj["AUTH_WIF"] = auth_wif
ctx.obj["DISPLAY_DOCUMENT"] = display
......
......@@ -27,6 +27,7 @@ pubkey_checksum = f"{pubkey}:{checksum}"
pubkey_seedhex_authfile = (
"3bc6f2484e441e40562155235cdbd8ce04c25e7df35bf5f87c067bf239db8511"
)
AUTH_FILE = "auth_file.txt"
@pytest.mark.parametrize(
......@@ -37,12 +38,12 @@ pubkey_seedhex_authfile = (
(["checksum", pubkey], pubkey_checksum),
(["checksum", "uid"], "Error: Wrong public key format"),
(["checksum"], MESSAGE),
(["--auth-file", "checksum"], pubkey_checksum),
(["--auth-file", "checksum", "pubkey"], pubkey_checksum),
(["--auth-file", AUTH_FILE, "checksum"], pubkey_checksum),
(["--auth-file", AUTH_FILE, "checksum", "pubkey"], pubkey_checksum),
],
)
def test_checksum_command(command, excepted_output):
with CliRunner().isolated_filesystem():
Path("authfile").write_text(pubkey_seedhex_authfile, encoding="utf-8")
Path(AUTH_FILE).write_text(pubkey_seedhex_authfile, encoding="utf-8")
result = CliRunner().invoke(cli, args=command)
assert result.output == f"{excepted_output}\n"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment