如何在SoapUI中测试使用JWT的REST服务? [英] How to test a REST service that uses JWT in SoapUI?

查看:121
本文介绍了如何在SoapUI中测试使用JWT的REST服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一些REST服务.我所有的测试都是使用SoapUI进行的. 最近,我决定采用JSON Web令牌(JWT)进行身份验证,但是我在SoapUI上找不到对此的任何支持(本机安装或插件,什么也没有).

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).

我找到了一些在线生成器,例如 http://jwtbuilder.jamiekurtz.com/,但填写了所有字段,对于每个测试用例,一次又一次地在SoapUI上复制/粘贴操作根本无效.

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.

我想知道是否有一种方法可以在SoapUI中测试JWT东西,或者是否需要其他工具.有什么建议吗?

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

谢谢!

推荐答案

我发现了一种半自动方法,可以使用包含令牌的外部文件在TestCases上保留有效的JWT令牌,而不会浪费太多时间.

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. 具有一个外部工具,可将有效的JWT令牌生成到文件中.
  2. 在SoapUI中打开您的项目,并添加一个带有值的jwt变量 ${=new File('/path/to/token_file.txt').text}

  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}

在您的请求中,将变量作为带有值的JWT标头引用 ${#Project#jwt}

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

当令牌过期时,只需重新启动生成器脚本,SoapUI将自动加载新令牌.

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

这篇关于如何在SoapUI中测试使用JWT的REST服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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