乐趣区

关于测试自动化:Postman-发送-RSA-签名请求qbit

前言

  • Postman 版本 10.13.6
  • qbit 将 RSAForPostman 压缩拷贝到了码云便于国内拜访

Postman 脚本示例

  • Pre-request Script

    if (!pm.collectionVariables.has("forgeJS")) {pm.sendRequest("https://gitee.com/qbitoy/public/raw/master/forge_rsa_min.js", function (err, res) {if (err) {console.log(err);
          } else {pm.collectionVariables.set("forgeJS", res.text());
          }
      })
    } else {var moment = require('moment');
      eval(pm.collectionVariables.get("forgeJS"));
      const prikey = pm.collectionVariables.get("prikey");
      console.log("prikey:" + prikey);
      var priv = forge.pki.privateKeyFromPem(prikey);
      const md = forge.md.sha256.create();
      var ts = moment().valueOf();
      pm.collectionVariables.set("ts", ts);
      console.log("ts:" + ts);
      var message = "/subject/eduSubject-" + ts;
      console.log("message:" + message);
      md.update(message);
      const data = md.digest().bytes();
      const sign = forge.util.encode64(priv.sign(md));
      pm.collectionVariables.set("sign", sign);
      console.log("sign:", sign);
    }

Postman 内置库

  • 官网文档:https://learning.postman.com/docs/writing-scripts/script-refe…

    ajv
    atob
    btoa
    chai
    cheerio
    crypto-js
    csv-parse/lib/sync
    lodash
    moment
    postman-collection
    tv4
    uuid
    xml2js

本文出自 qbit snap

退出移动版