0
Fork 0
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:
simeng-li 2024-11-12 10:13:19 +08:00 committed by GitHub
parent 1cee704939
commit ae4b65bc26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 1 deletions

View file

@ -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,
},
});
});
});

View file

@ -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(),

View file

@ -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);