File: test_jwt_payload.cc

package info (click to toggle)
cpp-jwt 1.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 508 kB
  • sloc: cpp: 3,374; ansic: 33; sh: 31; makefile: 12
file content (34 lines) | stat: -rw-r--r-- 912 bytes parent folder | download | duplicates (3)
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
#include <iostream>
#include "jwt/jwt.hpp"

void basic_payload_test()
{
  jwt::jwt_payload jp;
  jp.add_claim("iss", "myself");
  jp.add_claim("exp", 1234567);
  jp.add_claim("Exp", 1234567, true);

  auto jstr = jwt::to_json_str(jp);
  std::cout << jstr << std::endl;

  auto enc = jp.base64_encode();
  std::cout << "Base64 enc: " << enc << std::endl;

  auto dec = jp.base64_decode(enc);
  std::cout << "Base64 dec: " << dec << std::endl;
  std::cout << "Base64 dec: " << jstr << std::endl;

  assert (jstr == dec && "Encoded and decoded messages do not match");
  assert (jp.has_claim("exp") && "Claim exp must exist");
  assert (jp.has_claim("Exp") && "Claim Exp must exist");

  assert (!jp.has_claim("aud") && "Claim aud does not exist");
  assert (jp.has_claim_with_value("exp", 1234567) && "Claim exp with value 1234567 does not exist");

  return;
}

int main() {
  basic_payload_test();
  return 0;
}