Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. function jwtDecode(t) {
  2. let token = {};
  3. token.raw = t;
  4. token.header = JSON.parse(atob(t.toString().split('.')[0]));
  5. token.payload = JSON.parse(atob(t.toString().split('.')[1]));
  6. return (token);
  7. }
  8.  
  9. console.log("JWT Decode");
  10. var jwt = jwtDecode(pm.response.json().access_token);
  11. console.log(jwt);
  12.  
  13. pm.test("Access token to needs to have application roles assigned and granted", function () {
  14. pm.expect(jwt.payload.roles).to.not.equal(undefined);
  15. });
  16.  
  17. pm.test("Access token must have 1 role", function () {
  18. pm.expect(jwt.payload.roles.length).to.equal(1);
  19. });
  20.  
  21. pm.test("Access token must have XYZ role", function () {
  22. pm.expect(jwt.payload.roles.includes("XYZ")).to.equal(true);
  23. });
  24.  
  25. if(jwt.payload.roles !== undefined)
  26. {
  27. pm.test("Access token - JWT Roles: " + jwt.payload.roles.join(), function(){});
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement