zoukankan      html  css  js  c++  java
  • soupUI解决md5加密签名,cookie传递

    问题详情:

    1、接口调用需要前提状态:登录状态(cookie)

    2、接口请求需要签名,签名规则为:MD5(TokenKey+apikey+timestamp+nonc)

    其中

    1、TokenKey、apikey为接口构造方提供(永久不变);

    2、nonc为随机数,自定义

    3、timestamp 为 时间戳(百度百科)

    对应解决办法:

    1、登录获取cookie;

    1. 登录接口
    2. meiad type :application/x-www-form-urlencoded; charset=UTF-8
    3. 获取response data (cookie);test steps 中添加 Groovy Script ,其内容如下:

      """

      import com.eviware.soapui.support.types.StringToStringMap

      def cookiesList = testRunner.testCase.getTestStepByName("Login - Request 1").testRequest.response.responseHeaders["Set-Cookie"][0]

      cookiesList = cookiesList[0..-29] +"IsClosePwdWeak=0"
      log.info cookiesList

      return cookiesList

      """

    4. 外部引用方法:${(Groovy Script 命名)#result}  eg:${cookie_data#result}

    2、获取时间戳timestamp;

    1. test steps 中添加Groovy Script ,其内容如下:

      """

      time = (new Date().time / 1000).intValue()
      log.info time
      return time

      """

    2. 外部引用方法:${(Groovy Script 命名)#result}  eg:${timestamp#result}

    3、获取签名sign;

    1. 签名关键点为MD5加密,先构建加密方式;test steps 中添加 Groovy Script ,其内容如下:

      """


      import java.security.MessageDigest;
      import java.security.NoSuchAlgorithmException

      public static String md5Password(String password) {

      try {

      MessageDigest digest = MessageDigest.getInstance("md5");
      byte[] result = digest.digest(password.getBytes());
      StringBuffer buffer = new StringBuffer();

      for (byte b : result) {

      int number = b & 0xff;
      String str = Integer.toHexString(number);
      if (str.length() == 1) {
      buffer.append("0");
      }
      buffer.append(str);
      }


      return buffer.toString();
      } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      return "";
      }
      }

      def apiKey = context.expand( '${Properties#apiKey}' ) 
      def tokenKey = context.expand( '${Properties#TokenKey}' )
      def nonc = context.expand( '${Properties#nonc}' )
      def timestamp = context.expand( '${time#result}' )

      md5_data= md5Password(tokenKey+apiKey+timestamp+nonc) //按照开发人员提供的签名组成规则,组成签名
      log.info md5_data
      return md5_data

      """

    2. 固定值TokenKey、apikey以及自定义值nonc的存放于参与签名组成;
      1. test steps 中添加 Properties;添加对应key,value;

      2.  Groovy Script 脚本引用方法:
      3. 外部引用方法${(Properties命名)#(key)} eg:${Properties#apiKey}

    4、构建目标接口

  • 相关阅读:
    改动文件名称
    十五周 项目1 工资数据的输入
    通过YAJL获取json中的值
    图数据库之Pregel
    hdu 1028 Ignatius and the Princess III
    iOS使用ffmpeg播放rstp实时监控视频数据流
    Android的Bitmap和BitmapDrawable类解析-android学习之旅(六十)
    MAC中在eclipse luna上搭建移动平台自己主动化測试框架(UIAutomator/Appium/Robotium/MonkeyRunner)关键点记录
    QCustomPlot使用手冊(三)
    Mac下搭建react native开发环境
  • 原文地址:https://www.cnblogs.com/testwjr/p/10156461.html
Copyright © 2011-2022 走看看