test: fix authentication tests to use new token saving utility functions

isekai-main
Julian Lam 2 years ago
parent 4f524e9f94
commit f42b636adc

@ -7,8 +7,6 @@ const winston = require('winston');
const db = require('../database');
const pubsub = require('../pubsub');
const plugins = require('../plugins');
const utils = require('../utils');
const Meta = require('./index');
const cacheBuster = require('./cacheBuster');
const defaults = require('../../install/data/defaults.json');

@ -10,7 +10,6 @@ const request = require('request-promise-native');
const user = require('../user');
const posts = require('../posts');
const meta = require('../meta');
const { pluginNamePattern, themeNamePattern, paths } = require('../constants');

@ -6,7 +6,6 @@ const passportLocal = require('passport-local').Strategy;
const BearerStrategy = require('passport-http-bearer').Strategy;
const winston = require('winston');
const meta = require('../meta');
const controllers = require('../controllers');
const helpers = require('../controllers/helpers');
const plugins = require('../plugins');

@ -15,6 +15,7 @@ const utils = require('../src/utils');
const meta = require('../src/meta');
const plugins = require('../src/plugins');
const privileges = require('../src/privileges');
const api = require('../src/api');
const helpers = require('./helpers');
describe('authentication', () => {
@ -596,24 +597,14 @@ describe('authentication', () => {
let masterToken;
before(async () => {
newUid = await user.create({ username: 'apiUserTarget' });
const settings = await meta.settings.get('core.api');
settings.tokens = settings.tokens || [];
userToken = {
token: utils.generateUUID(),
userToken = await api.utils.tokens.generate({
uid: newUid,
description: `api token for uid ${newUid}`,
timestamp: Date.now(),
};
settings.tokens.push(userToken);
masterToken = {
token: utils.generateUUID(),
});
masterToken = await api.utils.tokens.generate({
uid: 0,
description: 'api master token',
timestamp: Date.now(),
};
settings.tokens.push(masterToken);
await meta.settings.set('core.api', settings);
});
});
it('should fail with invalid token', async () => {
@ -635,7 +626,7 @@ describe('authentication', () => {
const { res, body } = await helpers.request('get', `/api/self`, {
json: true,
headers: {
Authorization: `Bearer ${userToken.token}`,
Authorization: `Bearer ${userToken}`,
},
});
@ -648,7 +639,7 @@ describe('authentication', () => {
form: {},
json: true,
headers: {
Authorization: `Bearer ${masterToken.token}`,
Authorization: `Bearer ${masterToken}`,
},
});
@ -663,7 +654,7 @@ describe('authentication', () => {
},
json: true,
headers: {
Authorization: `Bearer ${masterToken.token}`,
Authorization: `Bearer ${masterToken}`,
},
});

Loading…
Cancel
Save