如何使用jMeter对需要CSRF token验证的OData服务进行并发性能测试

本文涉及的产品
性能测试 PTS,5000VUM额度
简介: 如何使用jMeter对需要CSRF token验证的OData服务进行并发性能测试

In my previous blog JMeter beginner – how to use JMeter to measure performance of OData service accessed parallelly I have demonstrate the way how to generate a large number of parallel request to a given OData service endpoint to measure the performance how this OData service implementation behaves via:


Write a Java program by yourself, using standard API HttpClientBuilder provided by JDK.

Use Open source tool JMeter

In that blog, the type of HTTP request I perform is “GET”, in that simple case no XSRF token generation and validation is necessary.

Now in this blog we will deal with more complex stuff: initiate a large number of Service request creation request via HTTP post. In this case it is necessary to:


get a valid XSRF token from server

send the actual HTTP post request to server by appending the XSRF token in request header field which is got from previous step

I will show two different approaches to achieve the goal.

Develop a Java Program to send HTTP post request

In the past I have once developed a ABAP program to create Opportunity via OData service. The main logic is still very clear as already explained above:


get a valid XSRF token from server

send the actual HTTP post request to server by appending the XSRF token in request header field which is got from previous step

The source code of that ABAP program could be found from my blog Consume standard C4C OData service via ABAP code.

Now I just simply translate the code using Java language, and enhance it a little bit so that a given number of parallel HTTP request could be sent via separate thread to perform the Service request creation via OData service


image.png

image.pngIn my example, I send three parallel request to server and could see the average response time printed out in console.image.pngAnd since in my Java code, I use “Jerry OData Ticket” plus uuid as postfix for Service Request Name:image.pngSo finally I could find the created Service Requests with given name in UI:image.pngUse JMeter to handle with XSRF Token stuff

First let us have a look how JMeter could archive the same without even one line of programming.


My project in JMeter is displayed with the following hierarchy. I have configured with “Number of 5 threads” in my thread group, so once executed, the response time of these 5 threads are displayed in result table together with average response time.


image.png

image.pngSome key points for this JMeter project creation

(1) Since now one thread should cover both XSRF token fetch via HTTP get and Service request creation via HTTP post, so a transaction controller is necessary to include both request.


image.png

image.png(2) Create the first HTTP request to fetch XSRF token. The setting could be found below: adding a http header field with name as

x-csrf-token and value as “fetch”:


image.pngimage.png

image.pngCreate a Regular Expression Extractor to parse the XSRF token from response header and stored it to a variable named “jerrycsrftoken”.

image.pngBefore you continue, please make sure that the XSRF token is correctly parsed from request header, which could be confirmed by printing it out in a debug sample:


image.png

image.png(3) Create another HTTP request with type POST.image.pngJust paste the following text to the tab “Body Data”:

--batch_1
Content-Type: multipart/mixed; boundary=changeset_1
--changeset_1
Content-Type: application/http
Content-Transfer-Encoding: binary
POST ServiceRequestCollection HTTP/1.1
Content-Length: 5000
Accept: application/json
Content-Type: application/json
{
   "ServicePriorityCode": "2",
  "Name": {"content": "Jerry Testing ticket creation via JMeter ${uuid} "},
  "ServiceRequestDescription": [
    {
      "Text": "Piston Rattling 1 - Generic OData Test Create", 
      "TypeCode": "10004"
    }, 
    {
      "Text": "Piston Rattling 2 - Generic OData Test Create", 
      "TypeCode": "10007"
    }
  ]
}
--changeset_1--
--batch_1--

In the body text I use a user-defined variable ${uuid} which we could create it in last step. And for this post request, use the XSRF token fetched from previous HTTP get request.



image.png

image.png(4) As the last step, create a user variable by using JMeter built-in function __Random, to create a random number between 1 ~ 100 as a fragment of created Service Request description.



image.png

image.pngNow execute the Thread group, and the execution detail for these three HTTP request could be reviewed separately in tree view:image.pngFor example, the XSRF token is successfully fetched in the first request: rdPy7zNj_uKDYvQLgfQCFA==

And used as one header field in second HTTP Post request as expected:


image.png

image.pngAnd finally in UI we could find the created Service request with random number between 1 ~ 100 as postfix:image.pngFurther reading

You can find a list of all other blogs related to OData written by Jerry.


Consume standard C4C OData service via ABAP code

Leverage C4C Odata notification to monitor C4C Opportunity change in CRM system

OData Service backend implementation in C4C, CRM and S4 HANA

JMeter beginner – how to use JMeter to measure performance of OData service accessed parallelly

Regarding cookie manipulation in CL_HTTP_CLIENT to avoid CSRF token validation failure issue

OData service parallel performance measurement – how to deal with XSRF token in Java Program and JMeter

Expose TextCollection data belonging to a Custom BO via OData service


相关实践学习
通过性能测试PTS对云服务器ECS进行规格选择与性能压测
本文为您介绍如何利用性能测试PTS对云服务器ECS进行规格选择与性能压测。
相关文章
|
2月前
|
存储 监控 Java
近亿级用户体量高并发实战:大促前压测干崩近百个服务引起的深度反思!
几年前,数百个服务,将堆内存从28GB升配到36GB,引发系统全面OOM的事件。
84 12
|
2月前
|
缓存 Java Maven
SpringCloud基于Eureka的服务治理架构搭建与测试:从服务提供者到消费者的完整流程
Spring Cloud微服务框架中的Eureka是一个用于服务发现和注册的基础组件,它基于RESTful风格,为微服务架构提供了关键的服务注册与发现功能。以下是对Eureka的详细解析和搭建举例。
百万并发连接的实践测试02
百万并发连接的实践测试02
|
2月前
|
网络协议 Ubuntu
百万并发连接的实践测试01
百万并发连接的实践测试01
|
4月前
|
数据可视化 数据挖掘 定位技术
在服务中收集和测试数据
【6月更文挑战第16天】本文讨论了数据收集和测试的重要性,指出样本量应根据时间和预算调整。数据分析涉及比较结果与假设,可视化数据以增强理解,并通过统计测试确认显著性。设计的持续优化是关键,适应变化的业务、技术和用户需求,数据驱动的方法能提供最佳用户体验。
46 5
在服务中收集和测试数据
|
3月前
|
测试技术 Linux
linux 服务器运行jmeter 进行服务性能压测
linux 服务器运行jmeter 进行服务性能压测
137 0
|
3月前
|
Java 测试技术
用代码模拟调用接口方式压测现网服务器的服务性能
用代码模拟调用接口方式压测现网服务器的服务性能
30 0
|
4月前
|
SQL 监控 中间件
【应急响应】拒绝服务&钓鱼指南&DDOS压力测试&邮件反制分析&应用日志
【应急响应】拒绝服务&钓鱼指南&DDOS压力测试&邮件反制分析&应用日志
|
3月前
|
运维 监控 大数据
部署-Linux01,后端开发,运维开发,大数据开发,测试开发,后端软件,大数据系统,运维监控,测试程序,网页服务都要在Linux中进行部署
部署-Linux01,后端开发,运维开发,大数据开发,测试开发,后端软件,大数据系统,运维监控,测试程序,网页服务都要在Linux中进行部署
|
3月前
|
JSON 数据格式
postman 实用教程(含带 token 访问需登录权限的接口、测试文件上传接口、测试文件下载接口)
postman 实用教程(含带 token 访问需登录权限的接口、测试文件上传接口、测试文件下载接口)
177 0
下一篇
无影云桌面