接口自动化(三):filter机制自动加解密

利用filter机制实现自动解密

filter是什么

  • 拦截请求与响应
  • 面向切面编程
  • 应用于自定义认证、session认证、logging
  • 需要使用 io.restassured.filter.Filter接口

利用filter机制请求自动带上cookie机制

修改response[base64]
修改request

Base64加密

public class JsonBase64Filter implements Filter {
    @Override
    public Response filter(FilterableRequestSpecification filterableRequestSpecification, FilterableResponseSpecification filterableResponseSpecification, FilterContext filterContext) {
            Response resOrigin = filterContext.next(filterableRequestSpecification,filterableResponseSpecification);
            ResponseBuilder responseBuilder = new ResponseBuilder().clone(resOrigin);
            String decodeContent = new String(
                    Base64.getDecoder().decode(
                            resOrigin.body().asString().trim()
                    )
            );
        responseBuilder.setBody(decodeContent);
        Response resNew = responseBuilder.build();
        return resNew;
    }
}

你可能感兴趣的:(接口自动化)