1. 程式人生 > >soupUI解決md5加密簽名,cookie傳遞

soupUI解決md5加密簽名,cookie傳遞

() orm ack att mex onf 定義 security inf

問題詳情:

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、構建目標接口

soupUI解決md5加密簽名,cookie傳遞