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.

57 lines
1.8 KiB

  1. var jwt = require('../index');
  2. var expect = require('chai').expect;
  3. var assert = require('chai').assert;
  4. describe('invalid expiration', function() {
  5. it('should fail with string', function (done) {
  6. var broken_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxMjMiLCJmb28iOiJhZGFzIn0.cDa81le-pnwJMcJi3o3PBwB7cTJMiXCkizIhxbXAKRg';
  7. jwt.verify(broken_token, '123', function (err, decoded) {
  8. expect(err.name).to.equal('JsonWebTokenError');
  9. done();
  10. });
  11. });
  12. it('should fail with 0', function (done) {
  13. var broken_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjAsImZvbyI6ImFkYXMifQ.UKxix5T79WwfqAA0fLZr6UrhU-jMES2unwCOFa4grEA';
  14. jwt.verify(broken_token, '123', function (err) {
  15. expect(err.name).to.equal('TokenExpiredError');
  16. done();
  17. });
  18. });
  19. it('should fail with false', function (done) {
  20. var broken_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOmZhbHNlLCJmb28iOiJhZGFzIn0.iBn33Plwhp-ZFXqppCd8YtED77dwWU0h68QS_nEQL8I';
  21. jwt.verify(broken_token, '123', function (err) {
  22. expect(err.name).to.equal('JsonWebTokenError');
  23. done();
  24. });
  25. });
  26. it('should fail with true', function (done) {
  27. var broken_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOnRydWUsImZvbyI6ImFkYXMifQ.eOWfZCTM5CNYHAKSdFzzk2tDkPQmRT17yqllO-ItIMM';
  28. jwt.verify(broken_token, '123', function (err) {
  29. expect(err.name).to.equal('JsonWebTokenError');
  30. done();
  31. });
  32. });
  33. it('should fail with object', function (done) {
  34. var broken_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOnt9LCJmb28iOiJhZGFzIn0.1JjCTsWLJ2DF-CfESjLdLfKutUt3Ji9cC7ESlcoBHSY';
  35. jwt.verify(broken_token, '123', function (err) {
  36. expect(err.name).to.equal('JsonWebTokenError');
  37. done();
  38. });
  39. });
  40. });