diff --git a/src/main/java/it/gov/pagopa/payhub/auth/service/user/registration/FiscalCodeObfuscatorService.java b/src/main/java/it/gov/pagopa/payhub/auth/service/user/registration/FiscalCodeObfuscatorService.java index 53964ad0..5ad99a06 100644 --- a/src/main/java/it/gov/pagopa/payhub/auth/service/user/registration/FiscalCodeObfuscatorService.java +++ b/src/main/java/it/gov/pagopa/payhub/auth/service/user/registration/FiscalCodeObfuscatorService.java @@ -5,6 +5,19 @@ @Service public class FiscalCodeObfuscatorService { public String obfuscate(String fiscalCode){ - return fiscalCode; + char[] arr = fiscalCode.toCharArray(); + if(arr.length >= 6){ + arr[1]='X'; + arr[4]='X'; + } + if(arr.length >= 16){ + arr[7]='X'; + arr[11]='X'; + arr[12]='X'; + arr[13]='X'; + arr[14]='X'; + arr[15]='X'; + } + return new String(arr); } } diff --git a/src/test/java/it/gov/pagopa/payhub/auth/service/user/registration/FiscalCodeObfuscatorServiceTest.java b/src/test/java/it/gov/pagopa/payhub/auth/service/user/registration/FiscalCodeObfuscatorServiceTest.java index e424199c..7ce5f3dd 100644 --- a/src/test/java/it/gov/pagopa/payhub/auth/service/user/registration/FiscalCodeObfuscatorServiceTest.java +++ b/src/test/java/it/gov/pagopa/payhub/auth/service/user/registration/FiscalCodeObfuscatorServiceTest.java @@ -14,14 +14,26 @@ void init(){ } @Test - void whenObfuscateThenOk(){ + void givenShortStringWhenObfuscateThenOk(){ //Given - String fiscalCode = "FISCALCODE"; + String fiscalCode = "A"; // When String result = service.obfuscate(fiscalCode); // Then - Assertions.assertSame(fiscalCode, result); + Assertions.assertEquals(fiscalCode, result); + } + + @Test + void givenCompleteCfWhenObfuscateThenOk(){ + //Given + String fiscalCode = "AAAAAA00A00A000A"; + + // When + String result = service.obfuscate(fiscalCode); + + // Then + Assertions.assertEquals("AXAAXA0XA00XXXXX", result); } }