-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve validators for captcha
- Loading branch information
1 parent
b9dfb8d
commit 711632a
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/backend/server/src/core/utils/__tests__/validators.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import test from 'ava'; | ||
|
||
import { validators } from '../validators'; | ||
|
||
test('can validate', t => { | ||
t.notThrows(() => validators.assertValidEmail('[email protected]')); | ||
t.throws(() => validators.assertValidEmail('test@example')); | ||
t.throws(() => validators.assertValidEmail('test')); | ||
|
||
t.notThrows(() => validators.assertValidPassword('password')); | ||
t.notThrows(() => validators.assertValidPassword('a')); | ||
t.throws(() => validators.assertValidPassword('')); | ||
t.throws(() => validators.assertValidPassword('aaaaaaaaaaaaaaaaaaaaa')); | ||
|
||
t.notThrows(() => | ||
validators.assertValidCredential({ | ||
email: '[email protected]', | ||
password: 'password', | ||
}) | ||
); | ||
t.notThrows(() => | ||
validators.assertValidCredential({ | ||
email: '[email protected]', | ||
password: 'password', | ||
challenge: 'challenge', | ||
}) | ||
); | ||
t.notThrows(() => | ||
validators.assertValidCredential({ | ||
email: '[email protected]', | ||
password: 'password', | ||
verifyToken: 'verifyToken', | ||
}) | ||
); | ||
// challenge and verifyToken should not be both provided | ||
t.throws(() => | ||
validators.assertValidCredential({ | ||
email: '[email protected]', | ||
password: 'password', | ||
challenge: 'challenge', | ||
verifyToken: 'verifyToken', | ||
}) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters