How to test CAS with jmeter?

2020-03-17 05:19发布

  • request:

    I send a "get" http request, has no parameters;
    path: http://192.168.22.139:8080/KSP

  • response:

    <input id="username" type="text" name="username" required/>
    <input id="password" type="password" name="password" required/>
    <input type="hidden" name="lt" value="LT-697-vbNmm6NKOZ0cd7Wg1ywzbMKLa0DnOc" />
    <input type="hidden" name="execution" value="e1s1" />
    <input type="hidden" name="_eventId" value="submit" />
    

And I add two XPath Extractor to get lt and execution:

  • reference name: lt;
    xPath query: //*[@id="login"]/input[3]
  • reference name: execution;
    xPath query: //*[@id="login"]/input[4]

enter image description here

Then I send another request with username/password/service/It/execution/_eventId:

enter image description here

Error: ticket and execution I get is empty, I get the xpath by chrome, so what is the problem?

4条回答
Ridiculous、
2楼-- · 2020-03-17 06:08

From the first response, can use Regular Expression Extractor to extract ticke and lt. extract ticket

Then send the second request with parameter:

username/password/It/execution/_eventId/_eventId enter image description here

By the way, you should add HTTP Cookie Manager, enter image description here

查看更多
smile是对你的礼貌
3楼-- · 2020-03-17 06:10

I didnot see parameters of your first request. At least I didnot see the lt.

The second request should be a GET request, and the parameters are: service and ticket(This is not jsessionid, the value is generated by CAS, and it is the same with the parameter lt in the first request to the CAS login ).

查看更多
劳资没心,怎么记你
4楼-- · 2020-03-17 06:13

There is a few things you need to change in the second request:

  • add execution parameter (extract it from the first request, eg. with XPath Extractor or Regular Expression Extractor),

    • the XPath expression would be something like .//*[@id='fm1']//*[@name='execution']/@value
  • add _eventId=submit parameter,

  • the lt parameter (the login ticket) should be extracted from the login form, too - it changes each time; see XPath Extractor or Regular Expression Extractor,

    • XPath expression: .//*[@id='fm1']//*[@name='lt']/@value,
  • not required, but will look nicer - change GET to POST.
查看更多
Melony?
5楼-- · 2020-03-17 06:17

If you're testing CAS login itself I can suggest using JMeter HTTP Proxy server to record login process, catch all values which are being passed, detect those, which are dynamic and deal with them via Regular Expression Extractor, XPath, Beanshell, etc. Post Processors - what you're most comfortable with.

In case if your application is behind CAS I guess that CAS login simply adds a cookie and your application considers user authenticated basing on it. In this case you can simply store cookies somewhere in CSV file and use them via HTTP Cookie Manager to simulate authenticated users.

查看更多
登录 后发表回答