API相关的一些异常测试学习

API相关的一些异常测试

1. 必填字段为空或缺失
{
    "endpoint": "/api/users",
    "body": {
        "username": "",
        "email": ""
    },
    "method": "POST"
}
2. 无效字段值 - 超过字符限制
{
    "endpoint": "/api/users",
    "body": {
        "username": "ThisIsAnIncrediblyLongUsernameThatExceedsTheCharacterLimit"
    },
    "method": "POST"
3. 无效字段值-数据格式错误
{
    "endpoint": "/api/users",
    "body": {
        "email": "invalid-email@"
    },
    "method": "POST"
}
4. 有效负载中多余的或不相关的键
{
    "endpoint": "/api/users",
    "body": {
        "username": "validuser",
        "extra_key": "irrelevant_value"
    },
    "method": "POST"
}
5. 不正确或无效的HTTP方法
{
    "endpoint": "/api/users/123",
    "body": {},
    "method": "POST"
}
6. 无效终端路径
{
    "endpoint": "/api/nonexistent_endpoint",
    "body": {},
    "method": "GET"
}
7. 在 POST 请求中使用查询参数而不是请求正文
{
    "endpoint": "/api/users?username=testuser",
    "body": {},
    "method": "POST"
}
8. 缺失或无效的身份验证标头(如 API 密钥)
{
    "endpoint": "/api/users",
    "body": {},
    "method": "GET",
    "headers": {
        "Authorization": "Invalid API_KEY"
    }
}
9. 不正确的数据结构 - 数组而非对象
{
    "endpoint": "/api/users",
    "body": [
        "username": "testuser",
        "email": "test@example.com"
    ],
    "method": "POST"
}
10. 不正确的数据结构 - 对象而非数组
{
    "endpoint": "/api/users",
    "body": {
        "users": {
            "username": "testuser",
            "email": "test@example.com"
        }
    },
    "method": "POST"
}
11. JSON格式问题-无效的Unicode字符
{
    "endpoint": "/api/users",
    "body": {
        "username": "test\uFFFFuser"
    },
    "method": "POST"
}
12. 有效负载中的重复键
{
    "endpoint": "/api/users",
    "body": {
        "username": "testuser",
        "username": "duplicate"
    },
    "method": "POST"
}
13. 无效或不支持的内容类型(例如,发送XML而不是JSON)
{
    "endpoint": "/api/users",
    "body": "<user><username>testuser</username><email>test@example.com</email></user>",
    "method": "POST",
    "headers": {
        "Content-Type": "application/xml"
    }
}
14. 超过有效载荷大小限制
{
    "endpoint": "/api/users",
    "body": {
        "large_data": "A very large data string that exceeds the server's payload size limit..."
    },
    "method": "POST"
}
15. 无效或过期的身份验证令牌
{
    "endpoint": "/api/users",
    "body": {},
    "method": "GET",
    "headers": {
        "Authorization": "Bearer expired_token"
    }
}
16. 在字段值中使用特殊字符
{
    "endpoint": "/api/users",
    "body": {
        "username": "test!@#$%^&*()-user"
    },
    "method": "POST"
}
17. 发送嵌套对象而不是简单的键值对
{
    "endpoint": "/api/users",
    "body": {
        "user": {
            "username": "testuser",
            "email": "test@example.com"
        }
    },
    "method": "POST"
}
18. 以错误的数据类型(如字符串而非整数)发送数据
{
    "endpoint": "/api/users",
    "body": {
        "age": "25"
    },
    "method": "POST"
}
19. 为必需的字段发送空值
{
    "endpoint": "/api/users",
    "body": {
        "username": null
    },
    "method": "POST"
}
20. 在字段名中使用保留关键字
{
    "endpoint": "/api/users",
    "body": {
        "class": "user"
    },
    "method": "POST"
}
21. 发送不完整或格式错误的多部分上传文件
{
    "endpoint": "/api/upload",
    "body": {
        "file": "incomplete_file_data"
    },
    "method": "POST",
    "headers": {
        "Content-Type": "multipart/form-data"
    }
}
22. 特殊字符的URL编码不正确或缺失
{
    "endpoint": "/api/users?username=test user",
    "body": {},
    "method": "GET"
}
23. 在 GET 请求中发送请求内容
{
    "endpoint": "/api/users",
    "body": {
        "username": "testuser"
    },
    "method": "GET"
}
24. 无效的日期或时间格式
{
    "endpoint": "/api/users",
    "body": {
        "birthdate": "01-25-1990"
    },
    "method": "POST"
}
25. 在字段名中使用非 ASCII 字符
{
    "endpoint": "/api/users",
    "body": {
        "üsername": "testuser"
    },
    "method": "POST"
}
26. 发送深度嵌套对象
{
    "endpoint": "/api/users",
    "body": {
        "user": {
            "profile": {
                "details": {
                    "nested": "too_deep"
                }
            }
        }
    },
    "method": "POST"
}
27. 在字段值中使用不可打印字符或控制字符
{
    "endpoint": "/api/users",
    "body": {
        "username": "test\u0008user"
    },
    "method": "POST"
}
28. 用不同的值多次发送相同的字段
{
    "endpoint": "/api/users",
    "body": {
        "username": "testuser",
        "username": "different"
    },
    "method": "POST"
}
29. 请求正文的内容长度标头缺失或无效
{
    "endpoint": "/api/users",
    "body": {
        "username": "testuser"
    },
    "method": "POST",
    "headers": {
        "Content-Length": "invalid"
    }
}
30. 在字段名称中使用空格或特殊字符
{
    "endpoint": "/api/users",
    "body": {
        "user name": "testuser"
    },
    "method": "POST"
}
31. 发送无效或格式错误的JSONP回调
{
    "endpoint": "/api/users?callback=invalid(callback)",
    "body": {},
    "method": "GET"
}
32. 以单个字符串而不是键值对的形式发送有效载荷
{
    "endpoint": "/api/users",
    "body": "username=testuser&email=test@example.com",
    "method": "POST"
}
33. 以字符串形式发送布尔值(例如,以 "true "代替 true)
{
    "endpoint": "/api/users",
    "body": {
        "active": "true"
    },
    "method": "POST"
}
34. 使用非标准 HTTP 方法(例如 PATCH、CONNECT)
{
    "endpoint": "/api/users/123",
    "body": {
        "username": "updateduser"
    },
    "method": "PATCH"
}
35. 发送不受支持的 HTTP 版本编号
{
    "endpoint": "/api/users",
    "body": {},
    "method": "GET",
    "httpVersion": "HTTP/3.0"
}
36. 发送多个验证标头(如 API 密钥和令牌)
{
    "endpoint": "/api/users",
    "body": {},
    "method": "GET",
    "headers": {
        "Authorization": "Bearer token_value",
        "API-Key": "api_key_value"
    }
}
37. 发送不必要或无效的CORS标头
{
    "endpoint": "/api/users",
    "body": {},
    "method": "GET",
    "headers": {
        "Access-Control-Allow-Origin": "*"
    }
}
38. 发送相互矛盾的查询参数和请求正文数据
{
    "endpoint": "/api/users?username=testuser",
    "body": {
        "username": "different_user"
    },
    "method": "POST"
}
39. 在身份验证头值中使用非标准字符
{
    "endpoint": "/api/users",
    "body": {},
    "method": "GET",
    "headers": {
        "Authorization": "Bearer t@ken_value"
    }
}
40. 为只能接受正值的字段发送负数
{
    "endpoint": "/api/users",
    "body": {
        "age": -25
    },
    "method": "POST"
}
41. 发送超出预期范围的未来或过去的时间戳
{
    "endpoint": "/api/users",
    "body": {
        "birthdate": "01-25-1800"
    },
    "method": "POST"
}
42. 在字段值中使用HTML、JavaScript或SQL代码来尝试代码注入
{
    "endpoint": "/api/users",
    "body": {
        "username": "<script>alert('test')</script>"
    },
    "method": "POST"
}
43. 在有效载荷中使用不同的字符编码(例如,UTF-8, UTF-16)
{
    "endpoint": "/api/users",
    "body": {
        "username": "téstuser"
    },
    "method": "POST",
    "headers": {
        "Content-Type": "application/json; charset=UTF-16"
    }
}
44. 发送混合数据类型的数组
{
    "endpoint": "/api/users",
    "body": {
        "values": [1, "string", true]
    },
    "method": "POST"
}
45. 以数组或对象的形式发送字段值,而不是简单的数据类型(例如,字符串,数字)希望这份清单能为你提供测试和保护服务器的新思路。
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值