0
Fork 0
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:
wangsijie 2023-01-20 18:12:57 +08:00 committed by GitHub
parent 3e34c51cca
commit 65f7f895fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 22 additions and 0 deletions

View file

@ -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 () => { it('PATCH /resources/:id/scopes/:scopeId', async () => {
const name = 'write:users'; const name = 'write:users';
const description = 'description'; const description = 'description';

View file

@ -186,6 +186,8 @@ export default function resourceRoutes<T extends AuthedRouter>(
body, body,
} = ctx.guard; } = ctx.guard;
assertThat(!/\s/.test(body.name), 'scope.name_with_space');
assertThat( assertThat(
!(await findScopeByNameAndResourceId(body.name, resourceId)), !(await findScopeByNameAndResourceId(body.name, resourceId)),
new RequestError({ new RequestError({
@ -218,6 +220,7 @@ export default function resourceRoutes<T extends AuthedRouter>(
} = ctx.guard; } = ctx.guard;
if (body.name) { if (body.name) {
assertThat(!/\s/.test(body.name), 'scope.name_with_space');
assertThat( assertThat(
!(await findScopeByNameAndResourceId(body.name, resourceId, scopeId)), !(await findScopeByNameAndResourceId(body.name, resourceId, scopeId)),
new RequestError({ new RequestError({

View file

@ -184,6 +184,7 @@ const errors = {
}, },
scope: { scope: {
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
}, },
}; };

View file

@ -183,6 +183,7 @@ const errors = {
}, },
scope: { scope: {
name_exists: 'The scope name {{name}} is already in use', name_exists: 'The scope name {{name}} is already in use',
name_with_space: 'The name of the scope cannot contain any spaces.',
}, },
}; };

View file

@ -190,6 +190,7 @@ const errors = {
}, },
scope: { scope: {
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
}, },
}; };

View file

@ -177,6 +177,7 @@ const errors = {
}, },
scope: { scope: {
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
}, },
}; };

View file

@ -191,6 +191,7 @@ const errors = {
}, },
scope: { scope: {
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
}, },
}; };

View file

@ -185,6 +185,7 @@ const errors = {
}, },
scope: { scope: {
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
}, },
}; };

View file

@ -185,6 +185,7 @@ const errors = {
}, },
scope: { scope: {
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
}, },
}; };

View file

@ -166,6 +166,7 @@ const errors = {
}, },
scope: { scope: {
name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED name_exists: 'The scope name {{name}} is already in use', // UNTRANSLATED
name_with_space: 'The name of the scope cannot contain any spaces.', // UNTRANSLATED
}, },
}; };