破坏API服务器的 45 种方法 (带有示例的负面测试)

221 篇文章 0 订阅
157 篇文章 0 订阅

2024软件测试面试刷题,这个小程序(永久刷题),靠它快速找到工作了!(刷题APP的天花板)_软件测试刷题小程序-CSDN博客文章浏览阅读3k次,点赞86次,收藏13次。你知不知道有这么一个软件测试面试的刷题小程序。里面包含了面试常问的软件测试基础题,web自动化测试、app自动化测试、接口测试、性能测试、自动化测试、安全测试及一些常问到的人力资源题目。最主要的是他还收集了像阿里、华为这样的大厂面试真题,还有互动交流板块……_软件测试刷题小程序​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502​编辑https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502icon-default.png?t=N7T8https://blog.csdn.net/AI_Green/article/details/134931243?spm=1001.2014.3001.5502

作为开发人员,我们努力编写准确无误的代码,但实际上没有人这样做,因为......bug。为了在这些讨厌的bug对我们的应用程序造成严重破坏之前将其捕获,我们依赖于自动化测试。正向测试可以确保我们的代码按照预期运行,而负向测试则在验证我们的应用程序是否足够强大,在处理意外输入和边缘情况方面发挥着至关重要的作用。

我正在开发 Pythagora,这是一款开源工具,它可以自己编写自动化集成测试(当然,GPT-4 也会提供一些帮助),开发人员无需编写任何代码。基本上,你可以在 30 分钟内实现从 0 到 80% 的代码覆盖率。我们刚刚创建了一项功能,只需一条命令就能从整个测试套件中自动生成负向测试。在创建该功能时,我研究了破坏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. 以数组或对象的形式发送字段值,而不是简单的数据类型(例如,字符串,数字)
{
    "endpoint": "/api/users",
    "body": {
        "username": ["testuser"]
    },
    "method": "POST"
}

希望这份清单能为你提供测试和保护服务器的新思路。如果您觉得这篇文章很有价值,请在 Pythagora Github repo 上支持我们。如果你试用了它,请告诉我们你的反馈,我们很高兴听到你的反馈。

行动吧,在路上总比一直观望的要好,未来的你肯定会感谢现在拼搏的自己!如果想学习提升找不到资料,没人答疑解惑时,请及时加入群: 759968159,里面有各种测试开发资料和技术可以一起交流哦。

最后: 下方这份完整的软件测试视频教程已经整理上传完成,需要的朋友们可以自行领取【保证100%免费】

​​

软件测试面试文档

我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。在这里插入图片描述​​

在这里插入图片描述

​​

  • 18
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
执行测试用例的 API 请求示例: ``` POST /zentao/api/v1/case/run/{caseID} 参数: - caseID: 测试用例 ID 请求示例: POST /zentao/api/v1/case/run/123 HTTP/1.1 Host: example.com Content-Type: application/json Authorization: token xxxxxxxx { "product": "ZenTao", "branch": "master", "version": "1.0.0", "build": "123456", "platform": "Windows", "browser": "Chrome", "environment": "test" } ``` 请求参数说明: - `caseID`:必填,要执行的测试用例的 ID; - `product`:选填,被测试的产品名称; - `branch`:选填,被测试的代码分支名称; - `version`:选填,被测试的版本号; - `build`:选填,被测试的构建号; - `platform`:选填,测试运行的操作系统名称; - `browser`:选填,测试运行的浏览器名称; - `environment`:选填,测试运行的环境名称。 响应示例: ``` HTTP/1.1 200 OK Content-Type: application/json { "result": true, "message": "", "data": { "caseID": 123, "status": "pass", "logs": [ "Step 1: Open the login page", "Step 2: Enter the username and password", "Step 3: Click the Login button", "Step 4: Verify the login result" ] } } ``` 响应参数说明: - `result`:必有,布尔型,表示 API 请求是否成功; - `message`:选有,字符串型,表示 API 请求的返回信息; - `data`:必有,对象型,表示 API 请求返回的数据; - `caseID`:必有,整型,表示执行的测试用例 ID; - `status`:必有,字符串型,表示测试用例执行的结果,取值包括:pass、fail、blocked、notrun; - `logs`:必有,数组型,表示测试用例执行的日志信息。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值