Skip to content

Commit 7acf5eb

Browse files
committed
Update login handling for dev env
1 parent eb095de commit 7acf5eb

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

backend/ibutsu_server/controllers/login_controller.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,32 @@ def login(body=None):
152152

153153
def support():
154154
"""Return the authentication types that the server supports"""
155-
return {
156-
"user": current_app.config.get("USER_LOGIN_ENABLED", True),
157-
"keycloak": get_keycloak_config().get("client_id") is not None,
158-
"google": get_provider_config("google")["client_id"] is not None,
159-
"github": get_provider_config("github")["client_id"] is not None,
160-
"facebook": get_provider_config("facebook")["app_id"] is not None,
161-
"gitlab": get_provider_config("gitlab")["client_id"] is not None,
162-
}
155+
try:
156+
keycloak_config = get_keycloak_config()
157+
google_config = get_provider_config("google")
158+
github_config = get_provider_config("github")
159+
facebook_config = get_provider_config("facebook")
160+
gitlab_config = get_provider_config("gitlab")
161+
162+
return {
163+
"user": current_app.config.get("USER_LOGIN_ENABLED", True),
164+
"keycloak": keycloak_config.get("client_id") is not None,
165+
"google": google_config.get("client_id") is not None,
166+
"github": github_config.get("client_id") is not None,
167+
"facebook": facebook_config.get("app_id") is not None,
168+
"gitlab": gitlab_config.get("client_id") is not None,
169+
}
170+
except Exception as e:
171+
# Log error but return default config with user login enabled
172+
print(f"Error getting login support configuration: {e}")
173+
return {
174+
"user": current_app.config.get("USER_LOGIN_ENABLED", True),
175+
"keycloak": False,
176+
"google": False,
177+
"github": False,
178+
"facebook": False,
179+
"gitlab": False,
180+
}
163181

164182

165183
def config(provider):

backend/tests/controllers/test_login_controller.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,28 @@ def test_login_inactive_user(flask_app):
124124

125125
response_data = response.get_json()
126126
assert response_data["code"] == "INACTIVE"
127+
128+
129+
def test_login_support(flask_app):
130+
"""Test case for getting login support configuration"""
131+
client, _jwt_token = flask_app
132+
133+
headers = {"Accept": "application/json"}
134+
response = client.get("/api/login/support", headers=headers)
135+
assert response.status_code == 200, f"Response body is : {response.data.decode('utf-8')}"
136+
137+
response_data = response.get_json()
138+
# Should always return a dict with these keys
139+
assert "user" in response_data
140+
assert "keycloak" in response_data
141+
assert "google" in response_data
142+
assert "github" in response_data
143+
assert "facebook" in response_data
144+
assert "gitlab" in response_data
145+
# All values should be booleans
146+
assert isinstance(response_data["user"], bool)
147+
assert isinstance(response_data["keycloak"], bool)
148+
assert isinstance(response_data["google"], bool)
149+
assert isinstance(response_data["github"], bool)
150+
assert isinstance(response_data["facebook"], bool)
151+
assert isinstance(response_data["gitlab"], bool)

scripts/ibutsu-pod.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,13 @@ if [[ $CREATE_PROJECT = true ]]; then
393393
done
394394
fi
395395
fi
396-
RUNS_COUNT=$(curl --no-progress-meter --header "Authorization: Bearer ${LOGIN_TOKEN}" \
397-
http://127.0.0.1:8080/api/run | jq -r '.runs | length')
398-
echo "Total runs in the database: ${RUNS_COUNT}"
396+
# Get runs count from both projects
397+
RUNS_COUNT_1=$(curl --no-progress-meter --header "Authorization: Bearer ${LOGIN_TOKEN}" \
398+
"http://127.0.0.1:8080/api/run?filter=project_id=${PROJECT_ID_1}&page_size=1" 2>/dev/null | jq -r '.pagination.totalItems // 0')
399+
RUNS_COUNT_2=$(curl --no-progress-meter --header "Authorization: Bearer ${LOGIN_TOKEN}" \
400+
"http://127.0.0.1:8080/api/run?filter=project_id=${PROJECT_ID_2}&page_size=1" 2>/dev/null | jq -r '.pagination.totalItems // 0')
401+
TOTAL_RUNS=$((RUNS_COUNT_1 + RUNS_COUNT_2))
402+
echo "Total runs in the database: ${TOTAL_RUNS}"
399403
echo ""
400404
echo "Import Summary:"
401405
echo " my-project-1: ${SUCCESSFUL_IMPORTS_1} successful, ${FAILED_IMPORTS_1} failed"
@@ -510,7 +514,7 @@ if [[ $CREATE_PROJECT = true ]]; then
510514

511515
# Fallback: try to get component from first run in project
512516
local runs_data
513-
runs_data=$(api_get "/api/run?project=${project_id}&page_size=1")
517+
runs_data=$(api_get "/api/run?filter=project_id=${project_id}&page_size=1")
514518
local component
515519
component=$(echo "$runs_data" | jq -r '.runs[0].component // empty' 2>/dev/null)
516520

0 commit comments

Comments
 (0)