使用jMeter测试通过SAP ID Service认证的SAP Cloud API

简介: 使用jMeter测试通过SAP ID Service认证的SAP Cloud API

Recently I am working on a co-innovation project with one local partner in China. They will provide a Face Recognition solution which consists of a set of hardware & software. Once a person is recognized, the partner software will consume SAP S/4HANA contact creation API to create a contact instance in the system.

Since we need to deliver this demo in SAP Cloud Forum site in Shanghai, and it is assumed that there will be lots of guests who would like to try this solution which leads to the possibility that multiple contact creation request would be sent to S/4HANA system simultaneously. As a result as one of demo preparation steps, I would like to generate a large number of concurrent contact creation request using jMeter and measure its performance.


As it’s not a big deal to achieve the contact creation API in Postman, the same idea would be applied in jMeter as well: wrap two HTTP request within a Simple Controller, one request responsible for fetch XSRF token and the other for the real creation call. Once executed the jMeter project, the first call succeeds as my expectation – the token is retrieved successfully and available in HTTP response header field “x-csrf-token”.

image.pngThis error really confused me as I have already got the correct token from server, why validation still failed?


I searched in Google and found this graph from SAP website: https://cloudplatform.sap.com/scenarios/usecases/authentication.html

image.pngIt demonstrates the Orchestration among client, service provider and identify provider for the service consumption scenario. Although in the diagram it is SAP Cloud Platform which plays the role of Service provider, not S/4HANA, however the logic is exactly the same.


This picture gives me a hint so I open Chrome development tool to inspect the network roundtrip when I access S/4HANA Fiori Launchpad, and soon I realized it is exactly follows the six steps described in the architecture image above.


Step1:I try to access S/4HANA Fiori Launchpad with Chrome – the access request is sent to S/4HANA as Service provider.

Step2: S/4HANA redirects this request to IDP with a HTTP 302 redirect. In my case there is a mutual trust preconfigured between S/4HANA and SAP ID service(that is, account.sap.com).

image.pngimage.pngimage.pngThey are:

xsrfProtection

spId

spName

authenticity_token

idpSSOEndpoint

All of them are generated by SAP ID service in the server side.


Step4: After users type their user and password and click log in button, the credentials will be sent back to IDP along with the hidden fields introduced in step3. All those fields will be involved in IDP authentication in server side, and could be observed in Chrome network tab.

image.pngStep5: IDP finishes the authentication, and issues an assertion back in HTTP response header field “SAMLResponse”.

image.pngimage.pngWith this assertion, end user can access the resource from S/4HANA now as the last step in the digram.


With all above learnings in mind, I find the cure for token validation failure soon. The complete jMeter project file (.jmx) could be found from my github:

https://github.com/i042416/KnowlegeRepository/blob/master/ABAP/C4COData/jMeter/01-contact-creation.jmx

This time the construction of jMeter project exactly abides by the six steps:

image.pngCompared with my original jMeter project, two new steps are added, highlighted with red color above.


(1) Create five seperate Regular Expression Extractor to parse the five parameters necessary for IDP server authentications from hidden fields in HTTP response form body:

image.png(2) use the five hidden fields plus user name & password to submit authentication request to SAP ID service.

image.png(3) Now it’s time to fetch CSRF token. The essential point is here: for the subsequent creation API call, it is NOT enough to only submit CSRF token fetched from this step to S/4HANA, which will ends up with CSRF token validation failure introduced in the beginning of this part. Instead, the two cookies highlighted below MUST also be included within HTTP request as well.


This is the reason why I store the two cookies as jMeter variable here.

image.pngimage.pngimage.pngimage.pngIn the end I also figured out the first two HTTP requests contained in my jMeter project, that is, “get redirected Form data” and “login”, are actually optional. Only keep in mind to store cookies got from CSRF token fetch step and use them in creation API call, and that’s enough.


You can find the source code of this more simplified version here:https://github.com/i042416/KnowlegeRepository/blob/master/ABAP/C4COData/jMeter/02-contact-creation.jmx

image.pngimage.pngimage.pngI have configured the refresh interval in contact tile as 10 seconds, so once guests in the Cloud Forum on-site demo passed facial recognition, this number just increases to give all guests a hint about the total number. At that day we have totally 276 guests who tested the solution and expressed their interests with our demo

image.png

相关文章
|
16天前
|
Java BI API
SAP Cloud for Customer 里如何通过 ABSL 二次开发方式消费 SAP S/4HANA 系统的 API
SAP Cloud for Customer 里如何通过 ABSL 二次开发方式消费 SAP S/4HANA 系统的 API
14 0
|
1月前
|
安全 测试技术 API
|
1月前
|
JSON 测试技术 API
Postman Newman 实现 API 自动化测试的快速指南
Newman 是一款专为 Postman 打造的命令行工具,旨在通过自动运行 Postman 集合和环境,实现 API 测试的自动化。它使得开发者无需打开 Postman 图形界面,即可直接在命令行中执行测试用例。
|
1月前
|
存储 API 开发者
虾皮Shopee根据ID取商品详情API
在构建电商平台的第三方应用或服务时,开发者经常需要通过编程方式获取商品的详细信息。对于虾皮Shopee平台来说,其提供的API接口使得这一需求得以实现。本文将详细介绍如何调用虾皮Shopee的API接口,根据商品ID获取其商品详情。
|
1月前
|
监控 安全 API
短信服务的API秘钥认证如何防止滥用
短信服务的API秘钥认证如何防止滥用
|
1月前
|
缓存 负载均衡 Java
Python实现API接口并发测试
Python实现API接口并发测试
57 0
|
1月前
|
架构师 前端开发 测试技术
|
2月前
|
JSON JavaScript 前端开发
提升 API 测试效率:Postman Tests 详解
Postman 不仅是一个强大的 API 开发工具,它还提供了创建自动化测试脚本的能力,这些脚本可以用于检验API请求得到的响应是否符合预期。这些测试脚本被称为 “Tests”,支持使用 JavaScript 编程语言进行编写,并且 Postman 提供了一系列的断言库来帮助你检查包括但不限于状态码、响应内容以及响应时间在内的响应数据。
|
2月前
|
开发框架 JSON .NET
初学者不会写接口怎么办?微软Visual Studio 2022无脑式API接口创建——Swagger一键导入APIKit快速测试
初学者不会写接口怎么办?微软Visual Studio 2022无脑式API接口创建——Swagger一键导入APIKit快速测试
72 0
|
2月前
|
机器学习/深度学习 人工智能 监控
SAP Sales Cloud,Service Cloud 和 SAP BTP 平台上的 AI 集成场景
SAP Sales Cloud,Service Cloud 和 SAP BTP 平台上的 AI 集成场景
67 0