diff --git a/ops/gitea-token-rotation.sh b/ops/gitea-token-rotation.sh index d100925..55930fe 100644 --- a/ops/gitea-token-rotation.sh +++ b/ops/gitea-token-rotation.sh @@ -49,17 +49,19 @@ read_env_token() { validate_token() { local token="$1" - local response + local response status result=1 response="$(mktemp /tmp/gitea-token-validation.XXXXXX)" - trap 'rm -f "${response}"' RETURN - local status - status="$(curl -sS -o "${response}" -w '%{http_code}' -H "Authorization: token ${token}" "${GITEA_URL}/api/v1/user")" - [[ "${status}" == "200" ]] || return 1 - grep -q '"login":"manus-admin"' "${response}" - status="$(curl -sS -o "${response}" -w '%{http_code}' -H "Authorization: token ${token}" "${GITEA_URL}/api/v1/repos/${GITEA_USER}/manus-dashboard")" - [[ "${status}" == "200" ]] || return 1 - status="$(curl -sS -o "${response}" -w '%{http_code}' -H "Authorization: token ${token}" "${GITEA_URL}/api/v1/repos/${GITEA_USER}/referentiel-ia")" - [[ "${status}" == "200" ]] + if status="$(curl -sS -o "${response}" -w '%{http_code}' -H "Authorization: token ${token}" "${GITEA_URL}/api/v1/user")" \ + && [[ "${status}" == "200" ]] \ + && grep -q '"login":"manus-admin"' "${response}" \ + && status="$(curl -sS -o "${response}" -w '%{http_code}' -H "Authorization: token ${token}" "${GITEA_URL}/api/v1/repos/${GITEA_USER}/manus-dashboard")" \ + && [[ "${status}" == "200" ]] \ + && status="$(curl -sS -o "${response}" -w '%{http_code}' -H "Authorization: token ${token}" "${GITEA_URL}/api/v1/repos/${GITEA_USER}/referentiel-ia")" \ + && [[ "${status}" == "200" ]]; then + result=0 + fi + rm -f "${response}" + return "${result}" } rotation_due() { diff --git a/src/backend/test/token-rotation.test.js b/src/backend/test/token-rotation.test.js index 3f99f32..3f01e51 100644 --- a/src/backend/test/token-rotation.test.js +++ b/src/backend/test/token-rotation.test.js @@ -13,6 +13,7 @@ assert.match(rotation, /GITEA_ROTATION_APPLIED/); assert.match(rotation, /chmod 0600/); assert.match(rotation, /rollback/); assert.doesNotMatch(rotation, /GITEA_PASSWORD/); +assert.doesNotMatch(rotation, /trap .*RETURN/); assert.match(timer, /OnCalendar=\*-01,04,07,10-01 07:00:00/); assert.match(timer, /Persistent=true/); assert.match(approvalPath, /PathExists=.*approval\.request/);