目前,我正在对 API 进行性能测试,需要 RSA 256 私钥的动态 JWT 令牌。我没有找到任何解决方案。谁能给我提供任何 JWT jar 文件和凹槽代码
答案 0 :(得分:0)
我相信您需要为此编写 Groovy 脚本
获取 JWT client library,例如 this guy 将是一个不错的选择并将其放到 JMeter Classpath(确保包括所有 dependencies)>
重启 JMeter 以获取 .jar
将 JSR223 Sampler 添加到您的测试计划
示例代码类似于:
def keyPayr = io.jsonwebtoken.security.Keys.keyPairFor(io.jsonwebtoken.SignatureAlgorithm.RS256)
def now = java.time.Instant.now()
def clientId = 'foo'
def jwt = io.jsonwebtoken.Jwts.builder()
.setAudience('https://example.com')
.setIssuedAt(Date.from(now))
.setExpiration(Date.from(now.plus(5L, java.time.temporal.ChronoUnit.MINUTES)))
.setIssuer(clientId)
.setSubject(clientId)
.setId(UUID.randomUUID().toString())
.signWith(keyPayr.private)
.compact()
log.info('Token: ' + jwt)
演示: