当前位置:网站首页>接口测试框架中的鉴权处理
接口测试框架中的鉴权处理
2022-07-01 16:00:00 【码同学软件测试】
图片
接口自动化测试中通常都有鉴权机制,就是判断是否在登录状态下,已登录方可调用接口,未登录则不可调用。本文将带领大家学习使用rest-assured框架实现基于cookies和token的鉴权关联,实现接口自动化测试。
1
基于cookies的鉴权关联
业务接口熟悉
码同学全栈接口项目中有基于cookies的查询余额接口,必须先调用登录接口获取cookie并传递给查询余额接口,两个接口的信息如下
通过抓包查看cookies
在页面上登录银行系统,通过Chrome开发者工具抓包,可以看到登录成功以后接口返回中产生了cookie信息
- 使用rest-assured框架实现cookie关联
首先,使用脚本调用登录接口,并从返回信息中获取cookie,代码如下,该方法执行完成后会将登录后的cookies存储在代码中的cookies对象中
其次,调用查询余额接口,并在请求信息中添加cookies对象,这样做就可以让查询余额接口在请求时带上有效cookies,代码如下
2
基于token的鉴权关联
业务接口熟悉
码同学全栈接口项目中有基于token的查询余额接口,必须先调用登录接口获取token并传递给查询余额接口,两个接口的信息如下
- 抓包分析token的产生和传递
在页面上登录银行系统,通过fiddler工具抓包,可以看到登录成功以后接口返回中产生的data信息就是token的值
那我们再分析下查询余额的接口在发起时token信息是如何传递的,依然是fidder工具抓包,我们可以发现在请求的header中有一个字段叫做testfan-token,对应的值就是登录接口返回的token值
- 使用rest-assured框架实现token关联
首先,使用脚本调用登录接口,并从返回信息中获取token,代码如下,该方法执行完成后会将登录后的token值存储在代码中的token变量中
其次,调用查询余额接口,并在请求信息中增加header信息,这样做就可以让查询余额接口在请求时带上有效token,代码如下
好了,不管是cookies还是token,我们都已经有了在rest-assured框架的关联使用,赶紧去试试吧
边栏推荐
- Seate中用了shardingjdbc 就不能用全局事务了吗?
- [daily news]what happened to the corresponding author of latex
- 表格存储中tablestore 目前支持mysql哪些函数呢?
- C#/VB. Net merge PDF document
- [每日一氵]Latex 的通讯作者怎么搞
- Introduction to RT thread env tool (learning notes)
- MySQL的零拷贝技术
- 自动、智能、可视!深信服SSLO方案背后的八大设计
- 最新NLP赛事实践总结!
- ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
猜你喜欢
Five years after graduation, I became a test development engineer with an annual salary of 30w+
【Hot100】20. Valid parentheses
周少剑,很少见
Zero copy technology of MySQL
高端程序员上班摸鱼指南
Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知
Crypto Daily:孙宇晨在MC12上倡议用数字化技术解决全球问题
Detailed explanation of stm32adc analog / digital conversion
Malaysia's Star: Sun Yuchen is still adhering to the dream of digital economy in WTO MC12
Introduction to RT thread env tool (learning notes)
随机推荐
Where should older test / development programmers go? Will it be abandoned by the times?
[200 opencv routines] 216 Draw polylines and polygons
工厂高精度定位管理系统,数字化安全生产管理
[video memory optimization] deep learning video memory optimization method
Summer Challenge harmonyos canvas realize clock
从 MLPerf 谈起:如何引领 AI 加速器的下一波浪潮
SQLServer查询: a.id与b.id相同时,a.id对应的a.p在b.id对应的b.p里找不到的话,就显示出这个a.id和a.p
Tanabata confession introduction: teach you to use your own profession to say love words, the success rate is 100%, I can only help you here ~ (programmer Series)
搜索框和按钮缩放时会有缝隙的bug
部门来了个拿25k出来的00后测试卷王,老油条表示真干不过,已被...
Programming examples of stm32f1 and stm32subeide - production melody of PWM driven buzzer
Overview | slam of laser and vision fusion
Preorder, inorder, follow-up of binary tree (non recursive version)
picgo快捷键 绝了这人和我的想法 一模一样
Do280 management application deployment - pod scheduling control
[open source data] open source data set for cross modal (MRI, Meg, eye movement) human spatial memory research based on virtual reality scenes
大龄测试/开发程序员该何去何从?是否会被时代抛弃?
表格存储中tablestore 目前支持mysql哪些函数呢?
嵌入式开发:5个修订控制最佳实践
求求你们,别再刷 Star 了!这跟“爱国”没关系!