【LoadRunner】对摘要认证的处理
近期项目中,进行http协议的接口性能测试过程中,需要进行登录接口的摘要认证,分享一下测试经验。
测试准备
测试工具:LoadRunner11
测试类型:接口测试--某系统登录接口
步骤
根据系统接口api进行报文的拼装,api示例如下:
1 认证方式digest auth: 2 Request: 3 ContentType:application/json;charset=utf8 4 Content-Length:xxxx 5 GET /login HTTP/1.1 6 APP-Version: Platform-version 7 Parameter:{} 8 APP-Version: XX版本
主要使用web_set_user("{username}", "{password}", "{host}:{hostport}")函数进行摘要认证,拼装后的LR报文:
1 Action() 2 { 3 //设置服务器地址 4 lr_save_string("服务器地址","host"); 5 //设置服务器端口号 6 lr_save_string("端口号","hostport"); 7 //设置用户名 8 lr_save_string("用户名","username"); 9 //设置密码 10 lr_save_string("密码","password"); 11 12 13 web_add_header("Content-Type","application/json;charset=utf-8"); 14 web_set_user("{username}", "{password}", "{host}:{hostport}"); 15 web_add_header("User-Agent","baoxinshuanglu/0.2.10(iPhone; iOS 10.3.1; Scale/2.00)"); 16 web_add_header("Content-Length","xxx"); 17 18 web_custom_request("login", "Method=POST", 19 "URL=http://{host}:{hostport}/login", 20 "Resource=0","Referer=", 21 "Mode=HTTP", 22 "Body={}", 23 LAST ); 24 25 return 0; 26 }
认证成功后,服务器返回如下:
1 HTTP/1.1 200 \r\n 2 Action.c(18): X-Content-Type-Options: nosniff\r\n 3 Action.c(18): X-XSS-Protection: 1; mode=block\r\n 4 Action.c(18): Cache-Control: no-cache, no-store, max-age=0, must-revalidate\r\n 5 Action.c(18): Pragma: no-cache\r\n 6 Action.c(18): Expires: 0\r\n 7 Action.c(18): X-Frame-Options: DENY\r\n 8 Action.c(18): Set-Cookie: JSESSIONID=xxxxx; Path=/; xxx\r\n 9 Action.c(18): X-Application-Context: application:xxxx\r\n 10 Action.c(18): Content-Type: application/json;charset=UTF-8\r\n 11 Action.c(18): Transfer-Encoding: chunked\r\n 12 Action.c(18): Date: Wed, 11 Oct 2017 05:43:26 GMT\r\n 13 Action.c(18): \r\n 14 Action.c(18): t=909ms: 5-byte chunked response overhead for "http://xxx/login" (RelFrameId=1, Internal ID=1) 15 Action.c(18): 29f\r\n 16 Action.c(18): t=917ms: 7-byte chunked response overhead for "http://xxx/login" (RelFrameId=1, Internal ID=1) 17 Action.c(18): \r\n 18 Action.c(18): 0\r\n 19 Action.c(18): \r\n 20 Action.c(18): t=935ms: 671-byte chunked response body for "http://xxx/login" (RelFrameId=1, Internal ID=1) 21 Action.c(18): {"id":xx,"name":"xx","gender":x,"id_card":"xx","tel_phon 22 Action.c(18): e":"xxxxx","certification":"xxxxx","work_number":"","mail":null 23 Action.c(18): ,"area":"xxx","register_type":x,"unit_id":xxx,"unit_type":1,"unit_name":"xxx 24 Action.c(18): xxx\xB8","corporate_code":"xxx","sub_corporate_code":"xxxx","sub_type":null, 25 Action.c(18): "status":x,"create_person":x,"unit_level":x,"create_time":"xxxx","password" 26 Action.c(18): :"xxx","roles":[{"id":x,"name":"xxxx"}], 27 Action.c(18): "authorityList":["app_log_upload","org_view","product_view","task_execute","task_template_ 28 Action.c(18): view","task_view","template_view","user_view"]}
以上就是一个简单的摘要认证的过程,如有错误请大神指正!