How to test a REST service that uses JWT in SoapUI?

£可爱£侵袭症+ 提交于 2020-04-10 03:40:51

问题


I'm implementing some REST services. All my tests are made using SoapUI. Recently I decided to adopt JSON Web Token (JWT) for authentication but I could not find any support for this on SoapUI (native install or plugins, nothing).

I found some online generators like http://jwtbuilder.jamiekurtz.com/ but fill all fields, copy/paste on SoapUI again and again for every testcase is not productive at all.

I'm wondering if there is a way to test JWT stuff in SoapUI or if maybe I need another tool. Any advice?

Thanks!


回答1:


I've found a semi-automatic way to keep a valid JWT token across TestCases without losing too much time, using an external file containing the token.

  1. Have an external tool generating a valid JWT token into a file.
  2. Open your project in SoapUI and add a jwt variable with the value ${=new File('/path/to/token_file.txt').text}

  3. In your requests, reference your variable as a JWT header with the value ${#Project#jwt}

When the token expire, just relaunch the generator script, and SoapUI will automatically load the new token.




回答2:


SoapUI will call your authentication server and fetch the token, then it will automatically put that token into authorization header (Bearer <token>).

Add new authorization>OAuth 2>Resource owner password credential grant

Then add your username and password into both client and resource section. Finally , put your token end-point as access token url and save the authorization profile to use in other test cases.



来源:https://stackoverflow.com/questions/33534979/how-to-test-a-rest-service-that-uses-jwt-in-soapui

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!