Skip to content

Commit

Permalink
P4ADEV-636 userCode obfuscated
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio.torre committed Jul 1, 2024
1 parent 64a1667 commit 70f05f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 70f05f7

Please sign in to comment.