Skip to content

Commit 3e56245

Browse files
fix: remove authentication check on sign up endpoint (#11560)
* Remove authentication check on sign up endpoint * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 07fa033 commit 3e56245

4 files changed

Lines changed: 371 additions & 284 deletions

File tree

src/backend/base/langflow/api/v1/users.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@
2626
async def add_user(
2727
user: UserCreate,
2828
session: DbSession,
29-
current_user: Annotated[User, Depends(get_current_active_superuser)], # noqa: ARG001
3029
) -> User:
3130
"""Add a new user to the database.
3231
33-
Requires superuser authentication to prevent unauthorized account creation.
32+
This endpoint allows public user registration (sign up).
33+
User activation is controlled by the NEW_USER_IS_ACTIVE setting.
3434
"""
35+
settings_service = get_settings_service()
36+
3537
new_user = User.model_validate(user, from_attributes=True)
3638
try:
3739
new_user.password = get_password_hash(user.password)
38-
new_user.is_active = get_settings_service().auth_settings.NEW_USER_IS_ACTIVE
40+
new_user.is_active = settings_service.auth_settings.NEW_USER_IS_ACTIVE
3941
session.add(new_user)
4042
await session.flush()
4143
await session.refresh(new_user)

src/backend/tests/unit/api/v1/test_users.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22
from httpx import AsyncClient
33

44

5+
async def test_add_user_public_signup(client: AsyncClient):
6+
"""Test public user registration (sign up) without authentication."""
7+
basic_case = {"username": "newuser", "password": "newpassword123"}
8+
response = await client.post("api/v1/users/", json=basic_case)
9+
result = response.json()
10+
11+
assert response.status_code == status.HTTP_201_CREATED
12+
assert isinstance(result, dict), "The result must be a dictionary"
13+
assert "id" in result, "The result must have an 'id' key"
14+
assert "is_active" in result, "The result must have an 'is_active' key"
15+
assert "is_superuser" in result, "The result must have an 'is_superuser' key"
16+
assert "last_login_at" in result, "The result must have an 'last_login_at' key"
17+
assert "profile_image" in result, "The result must have an 'profile_image' key"
18+
assert "store_api_key" in result, "The result must have an 'store_api_key' key"
19+
assert "updated_at" in result, "The result must have an 'updated_at' key"
20+
assert "username" in result, "The result must have an 'username' key"
21+
assert result["username"] == "newuser", "The username must match"
22+
assert result["is_superuser"] is False, "New users should not be superusers"
23+
24+
25+
async def test_add_user_duplicate_username(client: AsyncClient):
26+
"""Test that duplicate usernames are rejected."""
27+
basic_case = {"username": "duplicateuser", "password": "password123"}
28+
# Create first user
29+
response1 = await client.post("api/v1/users/", json=basic_case)
30+
assert response1.status_code == status.HTTP_201_CREATED
31+
32+
# Try to create second user with same username
33+
response2 = await client.post("api/v1/users/", json=basic_case)
34+
assert response2.status_code == status.HTTP_400_BAD_REQUEST
35+
assert "unavailable" in response2.json()["detail"].lower()
36+
37+
538
async def test_add_user(client: AsyncClient, logged_in_headers_super_user):
639
basic_case = {"username": "string", "password": "string"}
740
response = await client.post("api/v1/users/", json=basic_case, headers=logged_in_headers_super_user)

src/lfx/src/lfx/_assets/component_index.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4527,7 +4527,7 @@
45274527
},
45284528
{
45294529
"name": "anthropic",
4530-
"version": "0.77.0"
4530+
"version": "0.77.1"
45314531
}
45324532
],
45334533
"total_dependencies": 5
@@ -116031,6 +116031,6 @@
116031116031
"num_components": 355,
116032116032
"num_modules": 95
116033116033
},
116034-
"sha256": "934b201e21494ae6e11f223683ad79494bd716412b8ad697bbc27f0bb05d95aa",
116034+
"sha256": "de6edd6bb4cd0773739964b5d3264020f6be439c16bdf11db9d5ef9f9d4765ca",
116035116035
"version": "0.3.0"
116036116036
}

0 commit comments

Comments
 (0)