You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

token.js 1.4 KiB

8 jaren geleden
1234567891011121314151617181920212223242526272829
  1. import test from 'ava';
  2. import moment from 'moment';
  3. import Token from '../src/api/token';
  4. test('token is near the end', t => {
  5. const token = new Token('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MzcwMTg1ODIsImV4cCI6MTQzNzAxODU4M30.NmMv7sXjM1dW0eALNXud8LoXknZ0mH14GtnFclwJv0s');
  6. t.true(token.expiresIn(15, 'minutes', moment(1437018283 * 1000)));
  7. t.false(token.expiresIn(5, 'minutes', moment(1437018283 * 1000)));
  8. });
  9. test('token still valid', t => {
  10. const token = new Token('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MzcwMTg1ODIsImV4cCI6MTc1NzkyODQzNH0.KzEBhVgm3xa51jsBklB0Ib9DDwAkvynOnkwLLJoD5AU');
  11. t.true(token.stillValid());
  12. });
  13. test('token still valid check payload date', t => {
  14. const token = new Token('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MzcwMTg1ODIsImV4cCI6MTQzNzAxODU4M30.NmMv7sXjM1dW0eALNXud8LoXknZ0mH14GtnFclwJv0s');
  15. t.true(token.stillValid(moment(1437018283 * 1000)));
  16. });
  17. test('token expired', t => {
  18. const token = new Token('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MzcwMTg1ODIsImV4cCI6MTQzNzAxODU4M30.NmMv7sXjM1dW0eALNXud8LoXknZ0mH14GtnFclwJv0s');
  19. t.false(token.stillValid());
  20. });
  21. test('token invalid does not raise an error', t => {
  22. const token = new Token('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9');
  23. t.false(token.stillValid());
  24. });