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.

33 lines
1016 B

  1. var jwt = require('../index');
  2. var expect = require('chai').expect;
  3. var JsonWebTokenError = require('../lib/JsonWebTokenError');
  4. describe('non_object_values values', function() {
  5. it('should work with string', function () {
  6. var token = jwt.sign('hello', '123');
  7. var result = jwt.verify(token, '123');
  8. expect(result).to.equal('hello');
  9. });
  10. //v6 version will throw in this case:
  11. it('should throw with expiresIn', function () {
  12. expect(function () {
  13. jwt.sign('hello', '123', { expiresIn: '12h' });
  14. }).to.throw(/invalid expiresIn option for string payload/);
  15. });
  16. it('should fail to validate audience when the payload is string', function () {
  17. var token = jwt.sign('hello', '123');
  18. expect(function () {
  19. jwt.verify(token, '123', { audience: 'foo' });
  20. }).to.throw(JsonWebTokenError);
  21. });
  22. it('should work with number', function () {
  23. var token = jwt.sign(123, '123');
  24. var result = jwt.verify(token, '123');
  25. expect(result).to.equal('123');
  26. });
  27. });