@@ -43,30 +43,67 @@ describe('pii guardrail', () => {
4343 await expect ( pii ( { } , '' , config ) ) . rejects . toThrow ( 'Text cannot be empty or null' ) ;
4444 } ) ;
4545
46- it ( 'detects Korean Resident Registration Number (KR_RRN)' , async ( ) => {
46+ it ( 'detects valid Korean Resident Registration Number (KR_RRN)' , async ( ) => {
4747 const config = PIIConfig . parse ( {
4848 entities : [ PIIEntity . KR_RRN ] ,
4949 block : false ,
5050 } ) ;
51- const text = 'Korean RRN: 123456-1234567' ;
51+ // Valid format: YYMMDD-GNNNNNN (900101 = Jan 1, 1990, gender digit 1)
52+ const text = 'Korean RRN: 900101-1234567' ;
5253
5354 const result = await pii ( { } , text , config ) ;
5455
5556 expect ( result . tripwireTriggered ) . toBe ( false ) ;
56- expect ( ( result . info ?. detected_entities as Record < string , string [ ] > ) ?. KR_RRN ) . toEqual ( [ '123456 -1234567' ] ) ;
57+ expect ( ( result . info ?. detected_entities as Record < string , string [ ] > ) ?. KR_RRN ) . toEqual ( [ '900101 -1234567' ] ) ;
5758 expect ( result . info ?. checked_text ) . toBe ( 'Korean RRN: <KR_RRN>' ) ;
5859 } ) ;
5960
61+ it ( 'detects multiple valid KR_RRN formats' , async ( ) => {
62+ const config = PIIConfig . parse ( {
63+ entities : [ PIIEntity . KR_RRN ] ,
64+ block : false ,
65+ } ) ;
66+ // Testing different valid date ranges and gender digits (1-4)
67+ const text = 'RRNs: 850315-2345678, 001231-3456789, 750628-4123456' ;
68+
69+ const result = await pii ( { } , text , config ) ;
70+
71+ expect ( result . tripwireTriggered ) . toBe ( false ) ;
72+ expect ( ( result . info ?. detected_entities as Record < string , string [ ] > ) ?. KR_RRN ) . toHaveLength ( 3 ) ;
73+ expect ( ( result . info ?. detected_entities as Record < string , string [ ] > ) ?. KR_RRN ) . toContain ( '850315-2345678' ) ;
74+ expect ( ( result . info ?. detected_entities as Record < string , string [ ] > ) ?. KR_RRN ) . toContain ( '001231-3456789' ) ;
75+ expect ( ( result . info ?. detected_entities as Record < string , string [ ] > ) ?. KR_RRN ) . toContain ( '750628-4123456' ) ;
76+ } ) ;
77+
78+ it ( 'does not detect invalid KR_RRN patterns (false positives)' , async ( ) => {
79+ const config = PIIConfig . parse ( {
80+ entities : [ PIIEntity . KR_RRN ] ,
81+ block : false ,
82+ } ) ;
83+ // Invalid patterns that should NOT be detected:
84+ // - Invalid month (13)
85+ // - Invalid day (00, 32)
86+ // - Invalid gender digit (0, 5, 9)
87+ // - Random tracking numbers
88+ const text = 'Invalid: 901301-1234567, 900100-1234567, 900132-1234567, 900101-0234567, 900101-5234567, 123456-7890123' ;
89+
90+ const result = await pii ( { } , text , config ) ;
91+
92+ expect ( result . tripwireTriggered ) . toBe ( false ) ;
93+ expect ( result . info ?. detected_entities ) . toEqual ( { } ) ;
94+ expect ( result . info ?. checked_text ) . toBe ( text ) ; // No masking should occur
95+ } ) ;
96+
6097 it ( 'triggers tripwire for KR_RRN when block=true' , async ( ) => {
6198 const config = PIIConfig . parse ( {
6299 entities : [ PIIEntity . KR_RRN ] ,
63100 block : true ,
64101 } ) ;
65- const text = 'Korean RRN: 123456 -1234567' ;
102+ const text = 'Korean RRN: 900101 -1234567' ;
66103
67104 const result = await pii ( { } , text , config ) ;
68105
69106 expect ( result . tripwireTriggered ) . toBe ( true ) ;
70- expect ( ( result . info ?. detected_entities as Record < string , string [ ] > ) ?. KR_RRN ) . toEqual ( [ '123456 -1234567' ] ) ;
107+ expect ( ( result . info ?. detected_entities as Record < string , string [ ] > ) ?. KR_RRN ) . toEqual ( [ '900101 -1234567' ] ) ;
71108 } ) ;
72109} ) ;
0 commit comments