fix: validate types for login email and password (500 on non-string or missing body)

Đang mở Phù hợp với người mới
#235 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
express, postgresql, typescript
Lĩnh vực
api, authentication, backend

Hướng nghiên cứu

Đọc apps/http-server/src/controllers/authController.ts và phần triển khai parseRegisterInput hiện có trong registerInput.ts để nắm mẫu phân tích đầu vào của dự án. Thêm các bài kiểm thử đầu vào đăng nhập cho các trường hợp object, array, number và thiếu body như mô tả. Công việc hoàn tất khi đầu vào không hợp lệ trả về phản hồi 400 rõ ràng thay vì gây ra lỗi 500.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

userLoginController (apps/http-server/src/controllers/authController.ts) is the one auth input that is still only checked for being truthy. Register has parseRegisterInput, and join and create quiz got the same treatment in #231, but login still does const { email, password } = req.body and if (!email || !password).

What happens

From reading the code, POST /api/v1/auth/login should give a generic 500 in these cases:

  • No JSON body: the destructure throws, same as the no body case that #234 fixed for join.
  • {"email":{},"password":"x"}: gets past the check, then Prisma throws a validation error in findUnique.
  • {"email":"[email protected]","password":123}: bcrypt.compare throws on a non string.

I didn't run these against a database, the join versions behaved this way when I tested #234.

Expected behaviour

400 with a clear message for wrong types.

Proposed fix

A small parseLoginInput next to registerInput.ts, returned through the existing errorResponse(res, 400, ...), with tests for the object, array, number and no body cases.

Happy to send a PR for this, and #234 is merged so I don't have anything else open here. Labels and level are your call.

Ngôn ngữ chính
TypeScript
Star
21
Fork
7
Merge trung bình
8 giờ 12 phút
Pull request đã merge (30 ngày)
36

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TheCodeHeist-Coder/Rexial

Tất cả issue của TheCodeHeist-Coder/Rexial

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.