fix: add change-password handler to smoke test docker mock (#665)
The mock docker in smoke-init.sh only handled 'admin user create' and 'admin user list'. Add a 'change-password' handler that PATCHes the user via the Forgejo admin API to clear must_change_password. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e411eb224c
commit
48185108af
1 changed files with 37 additions and 0 deletions
|
|
@ -168,6 +168,43 @@ if [ "${1:-}" = "exec" ]; then
|
||||||
echo "New user '${username}' has been successfully created!"
|
echo "New user '${username}' has been successfully created!"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$subcmd" = "change-password" ]; then
|
||||||
|
shift 4 # skip 'forgejo admin user change-password'
|
||||||
|
username="" password=""
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--username) username="$2"; shift 2 ;;
|
||||||
|
--password) password="$2"; shift 2 ;;
|
||||||
|
--must-change-password*) shift ;;
|
||||||
|
--config*) shift ;;
|
||||||
|
*) shift ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$username" ]; then
|
||||||
|
echo "mock-docker: change-password missing --username" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# PATCH user via Forgejo admin API to clear must_change_password
|
||||||
|
patch_body="{\"must_change_password\":false,\"login_name\":\"${username}\",\"source_id\":0"
|
||||||
|
if [ -n "$password" ]; then
|
||||||
|
patch_body="${patch_body},\"password\":\"${password}\""
|
||||||
|
fi
|
||||||
|
patch_body="${patch_body}}"
|
||||||
|
|
||||||
|
if ! curl -sf -X PATCH \
|
||||||
|
-u "$BOOTSTRAP_CREDS" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
"${FORGE_URL}/api/v1/admin/users/${username}" \
|
||||||
|
-d "${patch_body}" \
|
||||||
|
>/dev/null 2>&1; then
|
||||||
|
echo "mock-docker: failed to change-password for '${username}'" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "mock-docker: unhandled exec: $*" >&2
|
echo "mock-docker: unhandled exec: $*" >&2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue