forked from karatelabs/karate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jwt.feature
36 lines (32 loc) · 1.03 KB
/
jwt.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@ignore
Feature: jwt test
Background:
* url demoBaseUrl
* def parseJwtPayload =
"""
function(token) {
var base64Url = token.split('.')[1];
var base64Str = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var Base64 = Java.type('java.util.Base64');
var decoded = Base64.getDecoder().decode(base64Str);
var String = Java.type('java.lang.String');
return new String(decoded);
}
"""
Scenario: jwt flow
Given path 'echo', 'jwt'
And request { username: 'john', password: 'secret' }
When method POST
Then status 200
And json accessToken = parseJwtPayload(response)
And match accessToken == { user: '[email protected]', role: 'editor', exp: '#number', iss: 'klingman' }
Given path 'echo', 'jwt', 'resource'
And header Authorization = 'Bearer ' + accessToken
When method get
Then status 200
And match response == 'success'
Scenario: access denied
Given path 'echo', 'jwt'
And request { username: 'john', password: 'wrong' }
When method POST
Then status 403