-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hindrer logging av FNR når Nav-Consumer-Id ikke er satt. (#1392)
- Loading branch information
Showing
5 changed files
with
49 additions
and
17 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
felles/log/src/main/java/no/nav/vedtak/log/mdc/FnrUtils.java
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,14 @@ | ||
package no.nav.vedtak.log.mdc; | ||
|
||
public class FnrUtils { | ||
private FnrUtils() { | ||
// hide construktor | ||
} | ||
|
||
public static String maskFnr(String userId) { | ||
if (userId.matches("^\\d{11}$")) { | ||
return userId.replaceAll("\\d{5}$", "*****"); | ||
} | ||
return userId; | ||
} | ||
} |
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
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
31 changes: 31 additions & 0 deletions
31
felles/log/src/test/java/no/nav/vedtak/log/mdc/FnrUtilsTest.java
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,31 @@ | ||
package no.nav.vedtak.log.mdc; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class FnrUtilsTest { | ||
|
||
@Test | ||
void maskerFnrTest() { | ||
var fdato = "122314"; | ||
var pnr = "55555"; | ||
var fakeTestFnr = fdato + pnr; | ||
var maskertFnr = FnrUtils.maskFnr(fakeTestFnr); | ||
assertThat(maskertFnr).isNotBlank().startsWith(fdato).doesNotContain(pnr).endsWith("*****"); | ||
} | ||
|
||
@Test | ||
void ikkeMaskerVanligTekst() { | ||
var ikkeFnr = "dev-fss:teamforeldrepenger:fpsak"; | ||
var ikkeMaskert = FnrUtils.maskFnr(ikkeFnr); | ||
assertThat(ikkeMaskert).isEqualTo(ikkeFnr); | ||
} | ||
|
||
@Test | ||
void ikkeMaskerOrgnr() { | ||
var fakeOrgnr9siffer = "123456789"; | ||
var ikkeMaskert = FnrUtils.maskFnr(fakeOrgnr9siffer); | ||
assertThat(ikkeMaskert).isEqualTo(fakeOrgnr9siffer); | ||
} | ||
} |