Skip to content

Commit

Permalink
fix alias renaming (WebOfTrust#798)
Browse files Browse the repository at this point in the history
* fix alias renaming

* test added for renaming alias

* test added for renaming alias

* execution permission to the test script
  • Loading branch information
SabbirIrfan authored and kentbull committed Sep 3, 2024
1 parent 28b2631 commit adc2a0c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
25 changes: 25 additions & 0 deletions scripts/demo/basic/rename-alias.sh
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 6 additions & 0 deletions scripts/demo/test_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions src/keri/app/cli/commands/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", )
Expand Down

0 comments on commit adc2a0c

Please sign in to comment.