File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/**
22 * ユーザー名の検証
3- * @param username
3+ * @param displayName
44 */
5- export default function isValidDisplayname ( username : string ) {
6- return username . length >= 1 && username . length <= 50 ;
5+ export default function isValidDisplayname ( displayName : string ) {
6+ return displayName . length >= 1 && displayName . length <= 50 ;
77}
Original file line number Diff line number Diff line change 1+ /**
2+ * パスワードの検証
3+ * @param password
4+ */
5+ export default function isValidPassword ( password : string ) {
6+ // 半角文字のみ許可
7+ const pattern = / ^ [ \x20 - \x7E ] { 6 , 128 } $ / ;
8+ return pattern . test ( password ) ;
9+ }
Original file line number Diff line number Diff line change 1+ import isValidPassword from '@/util/isValidPassword' ;
2+
3+ describe ( 'isValidPassword' , ( ) => {
4+ it ( '6文字以上の半角文字のパスワードは有効' , ( ) => {
5+ expect ( isValidPassword ( 'abcdef' ) ) . toBe ( true ) ;
6+ expect ( isValidPassword ( 'a1b2c3' ) ) . toBe ( true ) ;
7+ expect ( isValidPassword ( '!@#abc' ) ) . toBe ( true ) ;
8+ } ) ;
9+
10+ it ( '128文字以下の半角文字のパスワードは有効' , ( ) => {
11+ const password128 = 'a' . repeat ( 128 ) ;
12+ expect ( isValidPassword ( password128 ) ) . toBe ( true ) ;
13+ } ) ;
14+
15+ it ( '5文字以下のパスワードは無効' , ( ) => {
16+ expect ( isValidPassword ( '' ) ) . toBe ( false ) ;
17+ expect ( isValidPassword ( 'abcd5' ) ) . toBe ( false ) ;
18+ } ) ;
19+
20+ it ( '129文字以上のパスワードは無効' , ( ) => {
21+ const password129 = 'a' . repeat ( 129 ) ;
22+ expect ( isValidPassword ( password129 ) ) . toBe ( false ) ;
23+ } ) ;
24+
25+ it ( '全角文字を含むパスワードは無効' , ( ) => {
26+ expect ( isValidPassword ( 'abcdefA' ) ) . toBe ( false ) ;
27+ expect ( isValidPassword ( '@abcde' ) ) . toBe ( false ) ;
28+ } ) ;
29+ } ) ;
You can’t perform that action at this time.
0 commit comments