线上第七期_接口测试进阶_20190105

实战环境

数据提取

参见github

企业微信api

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.HashMap;

import static io.restassured.RestAssured.given;

public class WorkTest {
    public static String token=null;
    @BeforeClass
    public static void beforeClass(){
        RestAssured.useRelaxedHTTPSValidation();
    }

    @Before
    public void getToken() {
        token = given()
                .param("corpid", "wwd6da61649bd66fea")
                .param("corpsecret", "8KEGhmql2Tj9stLV14mwCCR6POfphQpcOuqYQitrAMo")
                .when().get("https://qyapi.weixin.qq.com/cgi-bin/gettoken").prettyPeek()
                .then()
                .statusCode(200)
                .extract().path("access_token");

        System.out.println(token);
    }

    @Test
    public void sendMsg(){
        HashMap<String, String> content=new HashMap<String, String>();
        content.put("content", "你的快递已到,请携带工卡前往邮件中心领取。\\n出发前可查看<a href=\\"http://work.weixin.qq.com\\">邮件中心视频实况</a>,聪明避开排队。");
        HashMap<String, Object> msg=new HashMap<String, Object>();
        msg.put("touser", "sihan");
        msg.put("msgtype", "text");
        msg.put("agentid", "1000004");
        msg.put("text", content);

        given().queryParam("access_token", token).contentType(ContentType.JSON).body(msg)
        .when().post("https://qyapi.weixin.qq.com/cgi-bin/message/send").prettyPeek()
        .then().statusCode(200);

    }
}

![](/uploads/photo/2019/ede328f7-2a1e-4b18-8ff7-7a234173d760.png!large =300x)

认证体系

  • http basic
  • oauth2

接口解密

Filter的机制
given + when -> filter -> alter request -> server -> origin response -> filter -> alter response -> then

SessionFilter

  • 当认证的时候,如果响应的cookie里带有sessionId,那么就把sessionId对应的value保存
  • 当下次请求的时候,如果发现请求体的cookie中带有sessionId,那么就自动把sessionId的值修改为上次保存的session值

作业1

完成github的oauth2的认证测试用例,/search/repositories

作业2

利用filter完成对 http://jenkins.testing-studio.com:9001/base64base64.json 的解密

作业3

创建自己的企业微信机构,不需要认证,用于后续的实战。

#未登录
Cookie: screenResolution=1440x900; version=1.1; uid=rBIABVwwJ6Y0rAAGAwRLAg==; JSESSIONID.dd4a903c=node01n5b2c081pw02294yoszrnhy3865.node
#登陆
Cookie: screenResolution=1440x900; version=1.1; uid=rBIABVwwJ6Y0rAAGAwRLAg==; JSESSIONID.dd4a903c=node0153de7wky4a6u10djp6dqn7bh6866.node0
#退出
Cookie: screenResolution=1440x900; version=1.1; uid=rBIABVwwJ6Y0rAAGAwRLAg==; JSESSIONID.dd4a903c=node01lwnoejquomlf1tgo6fhi7zf9d867.node0
#从新登陆
Cookie: screenResolution=1440x900; version=1.1; uid=rBIABVwwJ6Y0rAAGAwRLAg==; JSESSIONID.dd4a903c=node04u82cpfkk2gdx3uuw923qvp1868.node0

实战准备

  • 企业微信接口测试实战
  • 测试用例管理
  • 测试用例报告
  • 持续集成

TODO

  • dubbo
  • pb
关闭