Skip to content

Commit

Permalink
Merge pull request #620 from DohaRamadan/ISSUE-603_masked_secrets
Browse files Browse the repository at this point in the history
added unit test cases
  • Loading branch information
nirmalchandra authored Jan 28, 2024
2 parents 079647e + 365e9ac commit 721aeba
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.jsmart.zerocode.core.utils.TokenUtils.absolutePathOf;
import static org.jsmart.zerocode.core.utils.TokenUtils.getMaskedTokensReplaced;
import static org.jsmart.zerocode.core.utils.TokenUtils.getMasksRemoved;
import static org.jsmart.zerocode.core.utils.TokenUtils.resolveKnownTokens;
import static org.junit.Assert.*;

Expand Down Expand Up @@ -169,4 +171,48 @@ public void testAbsolutePathOf() {
assertThat(absolutePathOf("unit_test_files/jks_files/dummy_key_store.jks"),
containsString("zerocode/core/target/test-classes/unit_test_files/jks_files/dummy_key_store.jks"));
}


@Test
public void testGetMaskedTokensReplaced_multipleOccurrences(){
assertEquals("This is a ***masked*** message with ***masked*** tokens.", getMaskedTokensReplaced("This is a ${MASKED:secret} message with ${MASKED:masked} tokens."));
}

@Test
public void testGetMaskedTokensReplaced_noOccurrences(){
assertEquals("This string has no masked tokens.", getMaskedTokensReplaced("This string has no masked tokens."));
}

@Test
public void testGetMaskedTokensReplaced_emptyString(){
assertEquals("", getMaskedTokensReplaced(""));
}

@Test
public void testGetMaskedTokensReplaced_specialCharacters(){
assertEquals("***masked*** and ***masked***", getMaskedTokensReplaced("${MASKED:abc@123} and ${MASKED:!@#$%^}"));
}

@Test
public void testGetMaskedTokensRemoved_multipleOccurrences(){
assertEquals("This is a secret message with masked tokens.", getMasksRemoved("This is a ${MASKED:secret} message with ${MASKED:masked} tokens."));
}

@Test
public void testGetMaskedTokensRemoved_noOccurrences(){
assertEquals("This string has no masked tokens.", getMasksRemoved("This string has no masked tokens."));
}

@Test
public void testGetMaskedTokensRemoved_emptyString(){
assertEquals("", getMasksRemoved(""));
}

@Test
public void testGetMaskedTokensRemoved_specialCharacters(){
assertEquals("abc@123 and !@#$%^", getMasksRemoved("${MASKED:abc@123} and ${MASKED:!@#$%^}"));
}



}

0 comments on commit 721aeba

Please sign in to comment.