2021-07-03 13:56:53 +00:00
|
|
|
import { Eltro as t, assert} from 'eltro'
|
|
|
|
import encode from '../../api/jwt/encode.mjs'
|
2021-10-11 00:21:57 +00:00
|
|
|
import decode from '../../api/jwt/decode.mjs'
|
2021-07-03 13:56:53 +00:00
|
|
|
|
|
|
|
t.describe('encode', function() {
|
|
|
|
t.test('should faile with invalid header and body', function() {
|
|
|
|
assert.throws(
|
|
|
|
function() {
|
|
|
|
encode('', '')
|
|
|
|
},
|
|
|
|
/both header and body should be of type object/
|
|
|
|
)
|
|
|
|
})
|
2021-10-11 00:21:57 +00:00
|
|
|
t.test('should faile with invalid alg type', function() {
|
2021-07-03 13:56:53 +00:00
|
|
|
assert.throws(
|
|
|
|
function() {
|
2021-10-11 00:21:57 +00:00
|
|
|
encode({ alg: 'asdf' }, {})
|
2021-07-03 13:56:53 +00:00
|
|
|
},
|
|
|
|
/Only alg HS256, HS384 and HS512 are supported/
|
|
|
|
)
|
|
|
|
})
|
2021-10-11 00:21:57 +00:00
|
|
|
t.test('should have default header options', function() {
|
|
|
|
const assertTest = '1234'
|
|
|
|
let token = encode(null, { iss: 'test', test: assertTest }, 'bla')
|
|
|
|
let decoded = decode(token, { 'test': { 'default@HS256': 'bla' } }, [])
|
|
|
|
assert.strictEqual(decoded.test, assertTest)
|
|
|
|
})
|
2021-07-03 13:56:53 +00:00
|
|
|
})
|