export BASE_URL="http://localhost:8000"
export JWT_TOKEN=""python main.pyPassword Grant (Usuario)
curl -X POST "${BASE_URL}/auth/token" \
-H "Content-Type: application/json" \
-d '{
"grant_type": "password",
"username": "mrios",
"password": "admin_pass"
}'Client Credentials Grant (Servicio)
curl -X POST "${BASE_URL}/auth/token" \
-H "Content-Type: application/json" \
-d '{
"grant_type": "client_credentials",
"client_id": "test_client",
"client_secret": "test_secret",
"scope": "read write"
}'Guardar Token
export JWT_TOKEN=$(curl -s -X POST "${BASE_URL}/auth/token" \
-H "Content-Type: application/json" \
-d '{"grant_type":"password","username":"mrios","password":"admin_pass"}' \
| jq -r '.access_token')curl -X GET "${BASE_URL}/auth/me" \
-H "Authorization: Bearer ${JWT_TOKEN}"curl -X GET "${BASE_URL}/auth/health"curl -X POST "${BASE_URL}/scim/v2/Users" \
-H "Content-Type: application/json" \
-d '{
"userName": "testuser",
"name": {
"givenName": "Test",
"familyName": "User",
"formatted": "Test User"
},
"active": true,
"emails": [
{
"value": "test.user@company.com",
"primary": true,
"type": "work"
}
],
"groups": ["HR_READERS"],
"dept": "HR",
"riskScore": 25
}'curl -X GET "${BASE_URL}/scim/v2/Users/usr_jdoe"curl -X GET "${BASE_URL}/scim/v2/Users"curl -X GET "${BASE_URL}/scim/v2/Users?filter=userName%20eq%20%22jdoe%22"curl -X PATCH "${BASE_URL}/scim/v2/Users/usr_jdoe" \
-H "Content-Type: application/json" \
-d '{
"active": false,
"dept": "IT",
"riskScore": 45
}'curl -X DELETE "${BASE_URL}/scim/v2/Users/usr_testuser"curl -X POST "${BASE_URL}/scim/v2/Groups" \
-H "Content-Type: application/json" \
-d '{
"displayName": "DEVELOPERS",
"members": [
{
"value": "usr_jdoe",
"display": "jdoe"
}
]
}'curl -X GET "${BASE_URL}/scim/v2/Groups/grp_hr_readers"curl -X GET "${BASE_URL}/scim/v2/Groups"curl -X GET "${BASE_URL}/scim/v2/Groups?filter=displayName%20eq%20%22HR_READERS%22"curl -X PATCH "${BASE_URL}/scim/v2/Groups/grp_hr_readers" \
-H "Content-Type: application/json" \
-d '{
"members": [
{
"value": "usr_jdoe",
"display": "jdoe"
},
{
"value": "usr_agonzalez",
"display": "agonzalez"
}
]
}'curl -X POST "${BASE_URL}/scim/v2/Groups/grp_hr_readers/members" \
-H "Content-Type: application/json" \
-d '{
"value": "usr_mrios",
"display": "mrios"
}'curl -X DELETE "${BASE_URL}/scim/v2/Groups/grp_hr_readers/members/usr_mrios"curl -X DELETE "${BASE_URL}/scim/v2/Groups/grp_developers"Caso PERMIT: Admin accede a recurso no crítico
curl -X POST "${BASE_URL}/authz/evaluate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-Correlation-ID: test-admin-001" \
-d '{
"subject": {
"dept": "IT",
"groups": ["ADMINS"],
"riskScore": 15
},
"resource": {
"type": "user_data",
"env": "dev",
"classification": "confidential"
},
"context": {
"geo": "CL",
"deviceTrusted": true,
"timeOfDay": "10:30"
},
"action": "read"
}'Caso CHALLENGE: Usuario de alto riesgo
curl -X POST "${BASE_URL}/authz/evaluate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-Correlation-ID: test-risk-001" \
-d '{
"subject": {
"dept": "Finance",
"groups": ["FIN_USERS"],
"riskScore": 85
},
"resource": {
"type": "financial_data",
"env": "prod",
"classification": "restricted"
},
"context": {
"geo": "CL",
"deviceTrusted": true,
"timeOfDay": "10:30"
},
"action": "write"
}'Caso DENY: Acceso a producción crítica
curl -X POST "${BASE_URL}/authz/evaluate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-Correlation-ID: test-deny-001" \
-d '{
"subject": {
"dept": "IT",
"groups": ["ADMINS"],
"riskScore": 15
},
"resource": {
"type": "core_system",
"env": "prod",
"classification": "critical"
},
"context": {
"geo": "CL",
"deviceTrusted": true,
"timeOfDay": "10:30"
},
"action": "deploy"
}'curl -X GET "${BASE_URL}/authz/policies" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-Correlation-ID: debug-001" \
-d '{
"subject": {
"dept": "HR",
"groups": ["HR_READERS"],
"riskScore": 25
},
"resource": {
"type": "payroll",
"env": "prod"
},
"context": {
"geo": "CL",
"deviceTrusted": true,
"timeOfDay": "14:30"
},
"action": "read"
}'curl -X GET "${BASE_URL}/authz/health"curl -X GET "${BASE_URL}/authz/metrics" \
-H "Authorization: Bearer ${JWT_TOKEN}"curl -X POST "${BASE_URL}/authz/policies/reload" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${JWT_TOKEN}" \
-H "X-Correlation-ID: admin-reload-001"curl -X POST "${BASE_URL}/authz/evaluate" \
-H "Content-Type: application/json" \
-d '{
"subject": {"dept": "HR"},
"resource": {"type": "payroll"},
"context": {"geo": "CL"}
}'Respuesta esperada: 401 Unauthorized
curl -X POST "${BASE_URL}/authz/evaluate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer invalid-token" \
-d '{
"subject": {"dept": "HR"},
"resource": {"type": "payroll"},
"context": {"geo": "CL"}
}'Respuesta esperada: 401 Unauthorized
curl -X POST "${BASE_URL}/scim/v2/Users" \
-H "Content-Type: application/json" \
-d '{
"userName": "jdoe",
"name": {"givenName": "John", "familyName": "Doe"},
"active": true
}'Respuesta esperada: 409 Conflict
curl -X GET "${BASE_URL}/scim/v2/Users/usr_nonexistent"Respuesta esperada: 404 Not Found
#!/bin/bash
# test_all_endpoints.sh
BASE_URL="http://localhost:8000"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo "Testing Identity Microservice Endpoints"
# 1. Get JWT Token
echo -e "${YELLOW}Getting JWT Token...${NC}"
TOKEN_RESPONSE=$(curl -s -X POST "${BASE_URL}/auth/token" \
-H "Content-Type: application/json" \
-d '{"grant_type":"password","username":"mrios","password":"admin_pass"}')
JWT_TOKEN=$(echo $TOKEN_RESPONSE | jq -r '.access_token')
if [ "$JWT_TOKEN" = "null" ]; then
echo -e "${RED}Failed to get token${NC}"
exit 1
fi
echo -e "${GREEN}Token obtained successfully${NC}"
# 2. Test Authentication
echo -e "${YELLOW}Testing Authentication...${NC}"
curl -s -X GET "${BASE_URL}/auth/me" \
-H "Authorization: Bearer $JWT_TOKEN" | jq '.sub'
# 3. Test SCIM Users
echo -e "${YELLOW}Testing SCIM Users...${NC}"
curl -s -X GET "${BASE_URL}/scim/v2/Users" | jq '.totalResults'
# 4. Test SCIM Groups
echo -e "${YELLOW}Testing SCIM Groups...${NC}"
curl -s -X GET "${BASE_URL}/scim/v2/Groups" | jq '.totalResults'
# 5. Test Authorization
echo -e "${YELLOW}Testing Authorization...${NC}"
curl -s -X POST "${BASE_URL}/authz/evaluate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $JWT_TOKEN" \
-d '{
"subject": {"dept": "IT", "groups": ["ADMINS"], "riskScore": 15},
"resource": {"type": "user_data", "env": "dev"},
"context": {"geo": "CL", "deviceTrusted": true}
}' | jq '.decision'
echo -e "${GREEN}All tests completed${NC}"Para ejecutar el script de pruebas, necesitas darle permisos de ejecución y luego ejecutarlo:
# Dar permisos de ejecución
chmod +x test_all_endpoints.sh
# Ejecutar el script
./test_all_endpoints.sh#!/bin/bash
# test_rate_limiting.sh
BASE_URL="http://localhost:8000"
echo "Testing Rate Limiting (100 requests to /authz/evaluate)"
# Get token first
JWT_TOKEN=$(curl -s -X POST "${BASE_URL}/auth/token" \
-H "Content-Type: application/json" \
-d '{"grant_type":"password","username":"mrios","password":"admin_pass"}' \
| jq -r '.access_token')
# Send 105 requests to trigger rate limiting
for i in {1..105}; do
echo "Request $i"
RESPONSE=$(curl -s -X POST "${BASE_URL}/authz/evaluate" \
-H "Authorization: Bearer $JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"subject":{"dept":"HR"},"resource":{"type":"test"},"context":{"geo":"CL"}}')
echo $RESPONSE | jq '.detail // .decision'
sleep 0.5
done- mrios / admin_pass (Admin, IT, grupos: ADMINS)
- jdoe / password123 (HR, grupos: HR_READERS)
- agonzalez / finance2024 (Finance, grupos: FIN_APPROVERS)
- test_client / test_secret
- hr_app / hr_secret_2024
- HR_READERS
- FIN_APPROVERS
- ADMINS
- DEVELOPERS
- 200 OK: Operación exitosa
- 201 Created: Recurso creado
- 204 No Content: Eliminación exitosa
- 400 Bad Request: Datos inválidos
- 401 Unauthorized: Falta autenticación
- 403 Forbidden: Permisos insuficientes
- 404 Not Found: Recurso no encontrado
- 409 Conflict: Conflicto (ej: usuario ya existe)
- 429 Too Many Requests: Rate limit excedido
- 500 Internal Server Error: Error del servidor
{
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"id": "usr_jdoe",
"userName": "jdoe",
"meta": {
"resourceType": "User",
"created": "2024-01-01T10:00:00Z",
"lastModified": "2024-01-01T10:00:00Z",
"location": "/scim/v2/Users/usr_jdoe"
}
}{
"decision": "Permit|Deny|Challenge",
"reasons": ["ruleId: POLICY-ID"],
"advice": ["Human readable advice"],
"obligations": ["System obligations"]
}