mirror of
https://github.com/directus/directus.git
synced 2026-02-07 22:25:11 -05:00
* Add "authenticate" filter hook that allows custom auth check * Start on test * Update Jest, restructure API tests, start implementing authenticate test * Move access token verify to util function * Ensure jest can show inline warnings on correct lines * Update is-directus-jwt to use jsonwebtoken decode + add tests * Remove unused package * Tweak and finish + test authenticate * Tweak test * Add authenticate filter to docs * Don't scan tests for codeql * No seriously, ignore tests
26 lines
836 B
TypeScript
26 lines
836 B
TypeScript
import isDirectusJWT from '../../src/utils/is-directus-jwt';
|
|
import jwt from 'jsonwebtoken';
|
|
|
|
test('Returns false for non JWT string', () => {
|
|
const result = isDirectusJWT('test');
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('Returns false for JWTs with text payload', () => {
|
|
const token = jwt.sign('plaintext', 'secret');
|
|
const result = isDirectusJWT(token);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test(`Returns false if token issuer isn't "directus"`, () => {
|
|
const token = jwt.sign({ payload: 'content' }, 'secret', { issuer: 'rijk' });
|
|
const result = isDirectusJWT(token);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test(`Returns true if token is valid JWT and issuer is "directus"`, () => {
|
|
const token = jwt.sign({ payload: 'content' }, 'secret', { issuer: 'directus' });
|
|
const result = isDirectusJWT(token);
|
|
expect(result).toBe(true);
|
|
});
|