mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
improve tests and minor fixes
This commit is contained in:
parent
305547b9bb
commit
bfcebc9bae
@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { env } = require('../../../utils/lib');
|
||||
|
||||
module.exports = {
|
||||
module.exports = ({ env }) => ({
|
||||
salt: env('API_TOKEN_SALT'),
|
||||
};
|
||||
});
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { trim } = require('lodash/fp');
|
||||
const { getService } = require('../utils');
|
||||
const { validateApiTokenCreationInput } = require('../validation/api-tokens');
|
||||
|
||||
@ -13,10 +14,8 @@ module.exports = {
|
||||
* - having a space at the end or start of the value.
|
||||
* - having only spaces as value;
|
||||
*/
|
||||
attributes.name = attributes.name.trim();
|
||||
if (attributes.description) {
|
||||
attributes.description = attributes.description.trim();
|
||||
}
|
||||
attributes.name = trim(attributes.name);
|
||||
attributes.description = trim(attributes.description);
|
||||
|
||||
try {
|
||||
await validateApiTokenCreationInput(attributes);
|
||||
|
||||
@ -73,7 +73,14 @@ describe('API Token', () => {
|
||||
expect(mockedConfigSet).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('It creates a new salt, appendit to the .env file and sets it in the configuration', () => {
|
||||
test('It creates a new salt, appends it to the .env file and sets it in the configuration', () => {
|
||||
const mockedApiToken = {
|
||||
randomBytes: 'api-token_test-random-bytes',
|
||||
hexedString: '6170692d746f6b656e5f746573742d72616e646f6d2d6279746573',
|
||||
};
|
||||
|
||||
crypto.randomBytes = jest.fn(() => Buffer.from(mockedApiToken.randomBytes));
|
||||
|
||||
const mockedAppendFile = jest.fn();
|
||||
const mockedConfigSet = jest.fn();
|
||||
|
||||
@ -88,7 +95,10 @@ describe('API Token', () => {
|
||||
apiTokenService.createSaltIfNotDefined();
|
||||
|
||||
expect(mockedAppendFile).toHaveBeenCalled();
|
||||
expect(mockedConfigSet).toHaveBeenCalled();
|
||||
expect(mockedConfigSet).toHaveBeenCalledWith(
|
||||
'server.admin.api-token.salt',
|
||||
mockedApiToken.hexedString
|
||||
);
|
||||
});
|
||||
|
||||
test('It throws an error if the env variable used in the config file has been changed and is empty', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user