mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(core): scope name cannot contain any spaces (#3007)
This commit is contained in:
parent
3e34c51cca
commit
65f7f895fb
10 changed files with 22 additions and 0 deletions
|
@ -174,6 +174,17 @@ describe('resource routes', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('POST /resources/:id/scopes should throw with spaces in name', async () => {
|
||||
const name = 'write users';
|
||||
const description = 'description';
|
||||
|
||||
const response = await resourceRequest
|
||||
.post('/resources/foo/scopes')
|
||||
.send({ name, description });
|
||||
|
||||
expect(response.status).toEqual(400);
|
||||
});
|
||||
|
||||
it('PATCH /resources/:id/scopes/:scopeId', async () => {
|
||||
const name = 'write:users';
|
||||
const description = 'description';
|
||||
|
|
|
@ -186,6 +186,8 @@ export default function resourceRoutes<T extends AuthedRouter>(
|
|||
body,
|
||||
} = ctx.guard;
|
||||
|
||||
assertThat(!/\s/.test(body.name), 'scope.name_with_space');
|
||||
|
||||
assertThat(
|
||||
!(await findScopeByNameAndResourceId(body.name, resourceId)),
|
||||
new RequestError({
|
||||
|
@ -218,6 +220,7 @@ export default function resourceRoutes<T extends AuthedRouter>(
|
|||
} = ctx.guard;
|
||||
|
||||
if (body.name) {
|
||||
assertThat(!/\s/.test(body.name), 'scope.name_with_space');
|
||||
assertThat(
|
||||
!(await findScopeByNameAndResourceId(body.name, resourceId, scopeId)),
|
||||
new RequestError({
|
||||
|
|
|
@ -184,6 +184,7 @@ const errors = {
|
|||
},
|
||||
scope: {
|
||||
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
|
||||
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -183,6 +183,7 @@ const errors = {
|
|||
},
|
||||
scope: {
|
||||
name_exists: 'The scope name {{name}} is already in use',
|
||||
name_with_space: 'The name of the scope cannot contain any spaces.',
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -190,6 +190,7 @@ const errors = {
|
|||
},
|
||||
scope: {
|
||||
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
|
||||
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -177,6 +177,7 @@ const errors = {
|
|||
},
|
||||
scope: {
|
||||
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
|
||||
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -191,6 +191,7 @@ const errors = {
|
|||
},
|
||||
scope: {
|
||||
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
|
||||
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -185,6 +185,7 @@ const errors = {
|
|||
},
|
||||
scope: {
|
||||
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
|
||||
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -185,6 +185,7 @@ const errors = {
|
|||
},
|
||||
scope: {
|
||||
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
|
||||
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -166,6 +166,7 @@ const errors = {
|
|||
},
|
||||
scope: {
|
||||
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
|
||||
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue