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

未关闭 适合新手
#235 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
express, postgresql, typescript

调研方向

阅读 apps/http-server/src/controllers/authController.ts 和 registerInput.ts 中现有的 parseRegisterInput 实现,了解项目的输入解析模式。按说明为对象、数组、数字和缺少 body 的情况添加登录输入测试。无效输入返回明确的 400 响应,而不是导致 500,才算完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
21
派生
7
平均合并
8 小时 12 分钟
30 天内合并 PR
36

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TheCodeHeist-Coder/Rexial 的其他 Issue

查看 TheCodeHeist-Coder/Rexial 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。