Files
imphnen-backend-service/tests/iam/test-auth.sh
T
MythEclipse 1ca6d8f47c Add comprehensive tests for CMS, Gacha, Hackathon, IAM, and User Management endpoints
- Implemented tests for Events and Testimonials endpoints in `test-cms.sh`
- Added common functions and variables for API testing in `test-common.sh`
- Created tests for Mentor endpoints in `test-mentors.sh`
- Developed tests for Gacha endpoints in `test-gacha.sh`
- Established tests for Hackathon endpoints in `test-hackathon.sh`
- Implemented tests for Authentication endpoints in `test-auth.sh`
- Added tests for Roles and Permissions endpoints in `test-roles-permissions.sh`
- Created tests for Teams endpoints in `test-teams.sh`
- Developed tests for User Management endpoints in `test-users.sh`
2025-10-24 10:38:21 +07:00

62 lines
2.4 KiB
Bash

#!/bin/bash
# ==============================================================================
# IAM Tests - Authentication Endpoints
# ==============================================================================
source "$(dirname "$0")/../common/test-common.sh"
test_authentication_endpoints() {
printf "\n${CYAN}=== Testing Authentication Endpoints ===${NC}\n"
# Valid login
get_auth_token
# Invalid login
local invalid_login
invalid_login=$(jq -n '{email: "invalid@example.com", password: "wrongpassword"}')
test_api_endpoint "Invalid Login Test" "POST" "/v1/auth/login" 401 "$invalid_login"
# Mentor login
local mentor_login=$(jq -n '{email: "mentor@example.com", password: "password"}')
test_api_endpoint "Mentor Login" "POST" "/v1/auth/login-mentor" 200 "$mentor_login" false
# Forgot password
local forgot_password_data
forgot_password_data=$(jq -n --arg email "admin@example.com" '{email: $email}')
test_api_endpoint "Forgot Password Test" "POST" "/v1/auth/forgot" 200 "$forgot_password_data"
# Invalid new password (invalid token)
local new_password_data
new_password_data=$(jq -n --arg token "some_reset_token" --arg pass "newpassword123!A" '{token: $token, password: $pass}')
test_api_endpoint "New Password Test (Invalid Token)" "POST" "/v1/auth/new-password" 400 "$new_password_data"
# Refresh token
local refresh_token=$(curl -s -X POST -H "Content-Type: application/json" \
-d "$(jq -n '{email: "admin@example.com", password: "password"}')" \
"$BASE_URL/v1/auth/login" | jq -r '.data.token.refresh_token // empty')
if [ -n "$refresh_token" ]; then
local refresh_data
refresh_data=$(jq -n --arg token "$refresh_token" '{refresh_token: $token}')
test_api_endpoint "Refresh Token Test" "POST" "/v1/auth/refresh" 200 "$refresh_data"
else
write_test_log "WARN" "✗ Refresh Token Test - Dilewati: Refresh token tidak tersedia dari login"
fi
# Resend OTP
local resend_data=$(jq -n '{email: "admin@example.com"}')
test_api_endpoint "Resend OTP" "POST" "/v1/auth/send-otp" 200 "$resend_data" false
# Logout (skip - endpoint may not exist)
# test_api_endpoint "Logout" "POST" "/v1/auth/logout" 200 "" true
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
get_auth_token
test_authentication_endpoints
print_test_summary
[ "$FAIL_COUNT" -eq 0 ] && exit 0 || exit 1
fi