mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(core): add support email & website url format guard (#6790)
add support email and website url format guard
This commit is contained in:
parent
1cee704939
commit
ae4b65bc26
3 changed files with 59 additions and 1 deletions
|
@ -184,4 +184,52 @@ describe('PATCH /sign-in-exp', () => {
|
|||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should guard support email field format', async () => {
|
||||
const exception = await signInExperienceRequester
|
||||
.patch('/sign-in-exp')
|
||||
.send({ supportEmail: 'invalid' });
|
||||
|
||||
expect(exception).toMatchObject({
|
||||
status: 400,
|
||||
});
|
||||
|
||||
const supportEmail = 'support@logto.io';
|
||||
|
||||
const response = await signInExperienceRequester.patch('/sign-in-exp').send({
|
||||
supportEmail,
|
||||
});
|
||||
|
||||
expect(response).toMatchObject({
|
||||
status: 200,
|
||||
body: {
|
||||
...mockSignInExperience,
|
||||
supportEmail,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should guard support website URL field format', async () => {
|
||||
const exception = await signInExperienceRequester
|
||||
.patch('/sign-in-exp')
|
||||
.send({ supportWebsiteUrl: 'invalid' });
|
||||
|
||||
expect(exception).toMatchObject({
|
||||
status: 400,
|
||||
});
|
||||
|
||||
const supportWebsiteUrl = 'https://logto.io';
|
||||
|
||||
const response = await signInExperienceRequester.patch('/sign-in-exp').send({
|
||||
supportWebsiteUrl,
|
||||
});
|
||||
|
||||
expect(response).toMatchObject({
|
||||
status: 200,
|
||||
body: {
|
||||
...mockSignInExperience,
|
||||
supportWebsiteUrl,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -49,11 +49,19 @@ export default function signInExperiencesRoutes<T extends ManagementApiRouter>(
|
|||
koaGuard({
|
||||
query: z.object({ removeUnusedDemoSocialConnector: z.string().optional() }),
|
||||
body: SignInExperiences.createGuard
|
||||
.omit({ id: true, termsOfUseUrl: true, privacyPolicyUrl: true })
|
||||
.omit({
|
||||
id: true,
|
||||
termsOfUseUrl: true,
|
||||
privacyPolicyUrl: true,
|
||||
supportEmail: true,
|
||||
supportWebsiteUrl: true,
|
||||
})
|
||||
.merge(
|
||||
object({
|
||||
termsOfUseUrl: string().url().optional().nullable().or(literal('')),
|
||||
privacyPolicyUrl: string().url().optional().nullable().or(literal('')),
|
||||
supportEmail: string().email().optional().nullable().or(literal('')),
|
||||
supportWebsiteUrl: string().url().optional().nullable().or(literal('')),
|
||||
})
|
||||
)
|
||||
.partial(),
|
||||
|
|
|
@ -36,6 +36,8 @@ describe('admin console sign-in experience', () => {
|
|||
factors: [],
|
||||
},
|
||||
singleSignOnEnabled: true,
|
||||
supportEmail: 'contact@logto.io',
|
||||
supportWebsiteUrl: 'https://logto.io',
|
||||
};
|
||||
|
||||
const updatedSignInExperience = await updateSignInExperience(newSignInExperience);
|
||||
|
|
Loading…
Reference in a new issue