如何在JMETER的一部分xml上计算HASH256 [英] how to calculate HASH256 on just a part of xml in JMETER

查看:71
本文介绍了如何在JMETER的一部分xml上计算HASH256的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我正在使用Jmeter3.1进行API测试. [初级测试人员和新手]
  • 我有一个测试,我必须迭代地发送xml请求. 每次迭代时,都会在原始xml中添加一个不同的xml块. 接收系统将进一步评估此xml块,并将值存储在DB中.这将以Hash-256的形式存储在db表中. 现在我需要:
  • I'm doing API testing using Jmeter3.1. [im junior tester and new]
  • I have a test where i have to send an xml in request iteratively. with each iteration a different xml block is added in original xml. This xml block will be further evaluated by the recieving system and values will be stored in DB. This will be stored in form of Hash-256 in db tables. Now i need to :

[A]-首先为每个请求为此xml块计算Hash256.[*请参见图像中突出显示的黄色部分

[A] - first calculate the Hash256 for this block of xml for each request.[*see yellow highlighted part in image]

[B]-然后使用jdbc sampler登录到数据库之后,进行第二次比较. [对于这一部分,我将从开发人员处获得查询.] 但是我不明白如何仅针对xml代码块而不是完整的xml计算hash-256. 请参见下面的示例- 图像中的黄色背景xml块,我需要转换为hash-256,然后与db进行比较

[B]- then secondly compare it after logging into the DB using jdbc sampler. [for this part i will get a query from developers.] But i dont understand how to calculate the hash-256 for just the block of xml code and not the complete xml. please see example below- in the image- the yellow background xml block i need to convert to hash-256 and then compare with db

<?xml version="1.0" encoding="UTF-8" ?><r:Document SchemaVersion="1.0" xmlns:r="http://www.qqq.ddqn.qqqv.qe/XSD/qq9/qqSchema" Status="000">
<r:DateTime>2020-09-02T09:28:15</r:DateTime>    <r:FileInfo Language="nl"><r:cSecurityNumbers><r:Legal Type="200" Structure="A1">
            <r:Date><r:Century>20</r:Century>
                <r:Year>20</r:Year>
                <r:Month>09</r:Month>
                <r:Day>21</r:Day>
            </r:Date>
            <r:Legal>06999996</r:Legal></r:Legal><r:Legal Type="200" Structure="A1">
            <r:Date>
                <r:Century>20</r:Century>
                <r:Year>20</r:Year>
                <r:Month>12</r:Month>
                <r:Day>1</r:Day>
            </r:Date>
            <r:Legal>06999996</r:Legal></r:Legal><r:Legal Type="200" Structure="A1">
            <r:Date>
                <r:Century>20</r:Century>
                <r:Year>20</r:Year>
                <r:Month>11</r:Month>
                <r:Day>3</r:Day>
            </r:Date>
            <r:Legal>06999996</r:Legal></r:Legal></r:cSecurityNumbers></r:FileInfo Language="nl"></r:Document>

推荐答案

  1. 我不知道什么是HASH256
  2. 据我所知,您的XML格式不正确,此位:</r:FileInfo Language="nl">应该看起来像</r:FileInfo>
  1. I don't know what is HASH256
  2. As far as I can see your XML is malformed, this bit: </r:FileInfo Language="nl"> should look like </r:FileInfo>

无论如何,您都应该使用 JSR223 PostProcessor 和Groovy语言这样您就可以:

In any case you should be looking at JSR223 PostProcessor and Groovy language so you would be able to:

  • 解析先前的采样器响应
  • 获取第一个<Legal>标签值
  • 从其中计算出 SHA256 Hex
  • Parse previous sampler response
  • Fetch first <Legal> tag value
  • Calculate SHA256 Hex out of it

示例代码:

def data = new groovy.xml.XmlSlurper().parseText(prev.getResponseDataAsString())
def firstLegal = new groovy.xml.StreamingMarkupBuilder().bindNode(data.FileInfo.cSecurityNumbers.'*'[0]) as String
def hash256 = org.apache.commons.codec.digest.DigestUtils.sha256Hex(firstLegal) 

演示:

更多信息:

  • Apache Groovy - Processing XML
  • Apache Groovy - Why and How You Should Use It
  • StreamingMarkupBuilder
  • DigestUtils

由于上述两点,我不能保证上面的代码能按您的预期工作,但是它应该指导您正确的方向

I cannot guarantee the above code will work as you expect due to the aforementioned 2 points, but it should guide you to the proper direction

这篇关于如何在JMETER的一部分xml上计算HASH256的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆