From f0d81fac2313a86f95653efd7b835ac04f72aec9 Mon Sep 17 00:00:00 2001 From: SabbirIrfan <50948678+SabbirIrfan@users.noreply.github.com> Date: Thu, 27 Jun 2024 23:17:08 +0600 Subject: [PATCH] fix alias renaming (#798) * fix alias renaming * test added for renaming alias * test added for renaming alias * execution permission to the test script --- scripts/demo/basic/rename-alias.sh | 25 +++++++++++++++++++++++++ scripts/demo/test_scripts.sh | 6 ++++++ src/keri/app/cli/commands/rename.py | 9 ++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100755 scripts/demo/basic/rename-alias.sh diff --git a/scripts/demo/basic/rename-alias.sh b/scripts/demo/basic/rename-alias.sh new file mode 100755 index 000000000..5867aa174 --- /dev/null +++ b/scripts/demo/basic/rename-alias.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# CREATE DATABASE AND KEYSTORE +kli init --name rename-test --base "${KERI_TEMP_DIR}" --nopasscode + +# Incept with the initial alias "sabbir" +kli incept --name rename-test --base "${KERI_TEMP_DIR}" --alias sabbir --file ${KERI_DEMO_SCRIPT_DIR}/data/transferable-sample.json + +# Rename the alias from "sabbir" to "irfan" +kli rename --name rename-test --base "${KERI_TEMP_DIR}" --alias sabbir irfan + +# Extract alias from status +irfan_alias=$(kli status --name rename-test --base "${KERI_TEMP_DIR}" --alias irfan | grep -Eo 'Alias:\s+(.+)' | awk '{print $2}') + + + +# Check if the extracted alias is "irfan" +if [ "$irfan_alias" = "irfan" ]; then + echo "Alias successfully changed to 'irfan'." +else + echo "Alias did not change !" + +fi + +echo 'Test Complete' \ No newline at end of file diff --git a/scripts/demo/test_scripts.sh b/scripts/demo/test_scripts.sh index dd2c3cc88..6cce74d38 100755 --- a/scripts/demo/test_scripts.sh +++ b/scripts/demo/test_scripts.sh @@ -76,3 +76,9 @@ printf "Running multisig-join.sh" printf "\n************************************\n" "${script_dir}/basic/multisig-join.sh" isSuccess + +printf "\n************************************\n" +printf "Running rename.sh" +printf "\n************************************\n" +"${script_dir}/basic/rename-alias.sh" +isSuccess \ No newline at end of file diff --git a/src/keri/app/cli/commands/rename.py b/src/keri/app/cli/commands/rename.py index 10bcc54d8..b14b2f6a5 100644 --- a/src/keri/app/cli/commands/rename.py +++ b/src/keri/app/cli/commands/rename.py @@ -48,16 +48,19 @@ def rename(tymth, tock=0.0, **opts): if hby.habByName(newAlias) is not None: print(f"{newAlias} is already in use") - if (pre := hab.db.names.get(keys=("", name))) is not None: + if (pre := hab.db.names.get(keys=("", alias))) is not None: habord = hab.db.habs.get(keys=pre) - habord.name = name + habord.name = newAlias hab.db.habs.pin(keys=habord.hid, val=habord) - hab.db.names.pin(keys=("", name), val=pre) + hab.db.names.pin(keys=("", newAlias), val=pre) hab.db.names.rem(keys=("", alias)) print(f"Hab {alias} renamed to {newAlias}") + else: + raise ConfigurationError(f"No AID with name {alias} found") + except ConfigurationError as e: print(f"identifier prefix for {name} does not exist, incept must be run first", )