Skip to content

Commit

Permalink
[python] signup events on django (#4222)
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-papazian authored Feb 28, 2025
1 parent 0302064 commit 2d91268
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/appsec/test_automated_login_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,15 @@ def setup_signup_local(self):
self.r_success = weblog.post("/signup", data=login_data(context, NEW_USER, PASSWORD))

@missing_feature(context.library == "nodejs", reason="Signup events not implemented")
@missing_feature(context.library == "python", reason="Signup events not implemented")
@irrelevant(
context.library == "python" and context.weblog_variant not in ["django-poc", "python3.12", "django-py3.13"],
reason="No signup in framework",
)
@missing_feature(
context.library < "[email protected]"
and context.weblog_variant in ["django-poc", "python3.12", "django-py3.13"],
reason="Signup events not implemented yet",
)
def test_signup_local(self):
assert self.r_success.status_code == 200
for _, trace, span in interfaces.library.get_spans(request=self.r_success):
Expand Down Expand Up @@ -1818,7 +1826,15 @@ def setup_signup_local(self):
self.r_success = weblog.post("/signup", data=login_data(context, NEW_USER, PASSWORD))

@missing_feature(context.library == "nodejs", reason="Signup events not implemented")
@missing_feature(context.library == "python", reason="Signup events not implemented")
@irrelevant(
context.library == "python" and context.weblog_variant not in ["django-poc", "python3.12", "django-py3.13"],
reason="No signup in framework",
)
@missing_feature(
context.library < "[email protected]"
and context.weblog_variant in ["django-poc", "python3.12", "django-py3.13"],
reason="Signup events not implemented yet",
)
def test_signup_local(self):
assert self.r_success.status_code == 200
for _, trace, span in interfaces.library.get_spans(request=self.r_success):
Expand Down
16 changes: 16 additions & 0 deletions utils/build/docker/python/django/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,21 @@ def login(request):
return HttpResponse("login failure", status=401)


@csrf_exempt
def signup_user(request):
from app.models import CustomUser

try:
username = request.POST.get("username")
password = request.POST.get("password")
email = request.POST.get("email")
user = CustomUser.objects.create_user(username=username, email=email, password=password, id="new-user")
user.save()
return HttpResponse("OK")
except Exception as e:
return HttpResponse(f"signup failure {e!r}", status=400)


MAGIC_SESSION_KEY = "random_session_id"


Expand Down Expand Up @@ -1019,6 +1034,7 @@ def s3_multipart_upload(request):
path("login", login),
path("session/new", session_new),
path("session/user", session_user),
path("signup", signup_user),
path("custom_event", track_custom_event),
path("read_file", read_file),
path("mock_s3/put_object", s3_put_object),
Expand Down

0 comments on commit 2d91268

Please sign in to comment.