diff --git a/recog-verify/src/test/java/com/rapid7/recog/verify/RecogVerifierTest.java b/recog-verify/src/test/java/com/rapid7/recog/verify/RecogVerifierTest.java index 3b1baa6..eebe587 100644 --- a/recog-verify/src/test/java/com/rapid7/recog/verify/RecogVerifierTest.java +++ b/recog-verify/src/test/java/com/rapid7/recog/verify/RecogVerifierTest.java @@ -6,7 +6,7 @@ import java.io.StringReader; import org.apache.commons.io.output.NullOutputStream; import org.junit.jupiter.api.Test; -import static com.rapid7.recog.TestGenerators.anyString; +import static com.rapid7.recog.TestGenerators.anyUTF8String; import static org.junit.jupiter.api.Assertions.assertEquals; public class RecogVerifierTest { @@ -22,7 +22,7 @@ public void verifyNoExampleNoParamsWarnCount() throws ParseException { // when RecogParser recogParser = new RecogParser(true); - RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyString()); + RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyUTF8String()); VerifierOptions verifierOpts = new VerifierOptions(); RecogVerifier verifier = RecogVerifier.create(verifierOpts, matchers, NullOutputStream.NULL_OUTPUT_STREAM); verifier.verify(); @@ -47,7 +47,7 @@ public void verifyNoExampleZeroPositionParamsWarnCount() throws ParseException { // when RecogParser recogParser = new RecogParser(true); - RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyString()); + RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyUTF8String()); VerifierOptions verifierOpts = new VerifierOptions(); RecogVerifier verifier = RecogVerifier.create(verifierOpts, matchers, NullOutputStream.NULL_OUTPUT_STREAM); verifier.verify(); @@ -75,7 +75,7 @@ public void verifyNoExampleNonZeroPositionParamsWarnCount() throws ParseExceptio // when RecogParser recogParser = new RecogParser(true); - RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyString()); + RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyUTF8String()); VerifierOptions verifierOpts = new VerifierOptions(); RecogVerifier verifier = RecogVerifier.create(verifierOpts, matchers, NullOutputStream.NULL_OUTPUT_STREAM); verifier.verify(); @@ -104,7 +104,7 @@ public void verifySuccessfulExample() throws ParseException { // when RecogParser recogParser = new RecogParser(true); - RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyString()); + RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyUTF8String()); VerifierOptions verifierOpts = new VerifierOptions(); RecogVerifier verifier = RecogVerifier.create(verifierOpts, matchers, NullOutputStream.NULL_OUTPUT_STREAM); verifier.verify(); @@ -134,7 +134,7 @@ public void verify1FailureAnd1SuccessfulExamples() throws ParseException { // when RecogParser recogParser = new RecogParser(true); - RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyString()); + RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyUTF8String()); VerifierOptions verifierOpts = new VerifierOptions(); RecogVerifier verifier = RecogVerifier.create(verifierOpts, matchers, NullOutputStream.NULL_OUTPUT_STREAM); verifier.verify(); @@ -163,7 +163,7 @@ public void verifySuccessfulExampleUntestedParamsFailCount() throws ParseExcepti // when RecogParser recogParser = new RecogParser(true); - RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyString()); + RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyUTF8String()); VerifierOptions verifierOpts = new VerifierOptions(); RecogVerifier verifier = RecogVerifier.create(verifierOpts, matchers, NullOutputStream.NULL_OUTPUT_STREAM); verifier.verify(); @@ -193,7 +193,7 @@ public void verify2FailureExamples() throws ParseException { // when RecogParser recogParser = new RecogParser(true); - RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyString()); + RecogMatchers matchers = recogParser.parse(new StringReader(xml), anyUTF8String()); VerifierOptions verifierOpts = new VerifierOptions(); RecogVerifier verifier = RecogVerifier.create(verifierOpts, matchers, NullOutputStream.NULL_OUTPUT_STREAM); verifier.verify(); diff --git a/recog/src/test/java/com/rapid7/recog/FingerprintMatcherTest.java b/recog/src/test/java/com/rapid7/recog/FingerprintMatcherTest.java index a5680c8..8315099 100644 --- a/recog/src/test/java/com/rapid7/recog/FingerprintMatcherTest.java +++ b/recog/src/test/java/com/rapid7/recog/FingerprintMatcherTest.java @@ -5,7 +5,7 @@ import java.util.regex.Pattern; import org.junit.jupiter.api.Test; import static com.rapid7.recog.RecogMatcher.pattern; -import static com.rapid7.recog.TestGenerators.anyString; +import static com.rapid7.recog.TestGenerators.anyUTF8String; import static java.util.regex.Pattern.CASE_INSENSITIVE; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.apache.commons.lang3.RandomUtils.nextInt; @@ -25,12 +25,12 @@ public void matcherWithNullPattern() { @Test public void valueNameMustNotBeNull() { - assertThrows(NullPointerException.class, () -> new RecogMatcher(anyPattern()).addValue(null, anyString())); + assertThrows(NullPointerException.class, () -> new RecogMatcher(anyPattern()).addValue(null, anyUTF8String())); } @Test public void parameterPositionMustBeGreaterThanZero() { - assertThrows(IllegalArgumentException.class, () -> new RecogMatcher(anyPattern()).addParam(nextInt(Integer.MIN_VALUE, 0), anyString())); + assertThrows(IllegalArgumentException.class, () -> new RecogMatcher(anyPattern()).addParam(nextInt(Integer.MIN_VALUE, 0), anyUTF8String())); } @Test diff --git a/recog/src/test/java/com/rapid7/recog/FingerprintMatchersTest.java b/recog/src/test/java/com/rapid7/recog/FingerprintMatchersTest.java index 27b6ea1..36a8f62 100644 --- a/recog/src/test/java/com/rapid7/recog/FingerprintMatchersTest.java +++ b/recog/src/test/java/com/rapid7/recog/FingerprintMatchersTest.java @@ -5,7 +5,7 @@ import java.util.List; import org.junit.jupiter.api.Test; import static com.rapid7.recog.RecogMatcher.pattern; -import static com.rapid7.recog.TestGenerators.anyString; +import static com.rapid7.recog.TestGenerators.anyUTF8String; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -31,7 +31,7 @@ public void matchesNullInput() { @Test public void matchesNoMatchers() { // given - String fingerprint = anyString(); + String fingerprint = anyUTF8String(); RecogMatchers matchers = new RecogMatchers(); // when @@ -44,7 +44,7 @@ public void matchesNoMatchers() { @Test public void matchesNoMatches() { // given - String fingerprint = anyString(); + String fingerprint = anyUTF8String(); RecogMatchers matchers = new RecogMatchers(); matchers.add(new RecogMatcher(pattern("foo"))); matchers.add(new RecogMatcher(pattern("bar"))); diff --git a/recog/src/test/java/com/rapid7/recog/TestGenerators.java b/recog/src/test/java/com/rapid7/recog/TestGenerators.java index 4e9f9a3..33e08e4 100644 --- a/recog/src/test/java/com/rapid7/recog/TestGenerators.java +++ b/recog/src/test/java/com/rapid7/recog/TestGenerators.java @@ -7,8 +7,11 @@ public class TestGenerators { private static Random random = new Random(); - public static String anyString() { - return RandomStringUtils.random(16); + public static String anyUTF8String() { + return anyUTF8String(16); + } + public static String anyUTF8String(int length) { + return RandomStringUtils.random(length, 0, 0x10ffff, true, true); } public static > E anyEnum(Class enumType) { diff --git a/recog/src/test/java/com/rapid7/recog/parser/FingerprintMatcherParserTest.java b/recog/src/test/java/com/rapid7/recog/parser/FingerprintMatcherParserTest.java index 733e96f..8a8232d 100644 --- a/recog/src/test/java/com/rapid7/recog/parser/FingerprintMatcherParserTest.java +++ b/recog/src/test/java/com/rapid7/recog/parser/FingerprintMatcherParserTest.java @@ -12,7 +12,7 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; import static com.rapid7.recog.RecogMatcher.pattern; -import static com.rapid7.recog.TestGenerators.anyString; +import static com.rapid7.recog.TestGenerators.anyUTF8String; import static java.util.regex.Pattern.CASE_INSENSITIVE; import static java.util.regex.Pattern.DOTALL; import static java.util.regex.Pattern.MULTILINE; @@ -34,7 +34,7 @@ public void noFingerprintsAreReadWhenInputIsEmpty() throws ParseException { String xml = ""; // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(0)); @@ -46,7 +46,7 @@ public void invalidXmlInputCausesExceptionToBeThrown() throws ParseException { String xml = "foo"; // when - assertThrows(ParseException.class, () -> new RecogParser().parse(new StringReader(xml), anyString())); + assertThrows(ParseException.class, () -> new RecogParser().parse(new StringReader(xml), anyUTF8String())); // then - throws exception } @@ -68,7 +68,7 @@ public void validFingerprint() throws ParseException { + ""; // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(1)); @@ -99,7 +99,7 @@ public void twoValidFingerprints() throws ParseException { + ""; // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(2)); @@ -127,7 +127,7 @@ public void validFingerprintBase64EncodedExample() throws ParseException { + "", exServiceVersion, exBase64); // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(1)); @@ -141,7 +141,7 @@ public void validFingerprintExternalExampleFile() throws ParseException { // given int exServiceVersion = 1; String exText = String.format("Apache %d", exServiceVersion); - String exFilename = anyString(); + String exFilename = anyUTF8String(); String xml = String.format("\n" + "" + " \n" @@ -159,7 +159,7 @@ public void validFingerprintExternalExampleFile() throws ParseException { .thenReturn(exText.getBytes(StandardCharsets.US_ASCII)); // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(1)); @@ -199,7 +199,7 @@ public void invalidFingerprintsIgnored() throws ParseException { + ""; // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(2)); @@ -222,7 +222,7 @@ public void patternIsRequired() throws ParseException { + ""; // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(0)); @@ -245,7 +245,7 @@ public void patternMustBeValid() throws ParseException { + ""; // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(0)); @@ -268,7 +268,7 @@ public void emptyFlagsIgnored() throws ParseException { + ""; // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(1)); @@ -292,7 +292,7 @@ public void unknownFlagIgnored() throws ParseException { + ""; // when - RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyString()); + RecogMatchers patterns = new RecogParser().parse(new StringReader(xml), anyUTF8String()); // then assertThat(patterns.size(), is(1)); @@ -318,7 +318,7 @@ public void paramZeroPositionWithNoValueFailsWhenStrict() { // when Exception exception = assertThrows(ParseException.class, () -> { - new RecogParser(true).parse(new StringReader(xml), anyString()); + new RecogParser(true).parse(new StringReader(xml), anyUTF8String()); }, expectedMessage); // then @@ -346,7 +346,7 @@ public void paramNonZeroPositionWithValueFailsWhenStrict() { // when Exception exception = assertThrows(ParseException.class, () -> { - new RecogParser(true).parse(new StringReader(xml), anyString()); + new RecogParser(true).parse(new StringReader(xml), anyUTF8String()); }, expectedMessage); // then @@ -375,7 +375,7 @@ public void invalidFingerprintBase64EncodedExampleFailsWhenStrict() { // when Exception exception = assertThrows(IllegalArgumentException.class, () -> { - new RecogParser(true).parse(new StringReader(xml), anyString()); + new RecogParser(true).parse(new StringReader(xml), anyUTF8String()); }); // then @@ -385,7 +385,7 @@ public void invalidFingerprintBase64EncodedExampleFailsWhenStrict() { @Test public void missingExternalExampleFileFailsWhenStrict() { // given - String exFilename = anyString(); + String exFilename = anyUTF8String(); String xml = String.format("\n" + "" + " \n" @@ -397,7 +397,7 @@ public void missingExternalExampleFileFailsWhenStrict() { + " \n" + " \n" + "", exFilename); - String name = anyString(); + String name = anyUTF8String(); String expectedMessage = String.format("Unable to process fingerprint example file '%s'", Paths.get(name, exFilename)); // when diff --git a/recog/src/test/java/com/rapid7/recog/provider/CompositeFingerprintMatchersProviderTest.java b/recog/src/test/java/com/rapid7/recog/provider/CompositeFingerprintMatchersProviderTest.java index 7da7433..1f0b3a9 100644 --- a/recog/src/test/java/com/rapid7/recog/provider/CompositeFingerprintMatchersProviderTest.java +++ b/recog/src/test/java/com/rapid7/recog/provider/CompositeFingerprintMatchersProviderTest.java @@ -5,7 +5,7 @@ import com.rapid7.recog.RecogType; import org.junit.jupiter.api.Test; import static com.rapid7.recog.TestGenerators.anyEnum; -import static com.rapid7.recog.TestGenerators.anyString; +import static com.rapid7.recog.TestGenerators.anyUTF8String; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -18,7 +18,7 @@ public class CompositeFingerprintMatchersProviderTest { @Test public void getMatchersNoProviders() { // given - String name = anyString(); + String name = anyUTF8String(); RecogType type = anyEnum(RecogType.class); CompositeRecogMatchersProvider provider = new CompositeRecogMatchersProvider(); @@ -32,7 +32,7 @@ public void getMatchersNoProviders() { @Test public void getMatchersSingleProviderNoMatch() { // given - String name = anyString(); + String name = anyUTF8String(); RecogType type = anyEnum(RecogType.class); IRecogMatchersProvider provider = mock(IRecogMatchersProvider.class); given(provider.getMatchers(name, type)).willReturn(null); @@ -48,7 +48,7 @@ public void getMatchersSingleProviderNoMatch() { @Test public void getMatchersSingleProviderMatch() { // given - String name = anyString(); + String name = anyUTF8String(); RecogType type = anyEnum(RecogType.class); IRecogMatchersProvider provider = mock(IRecogMatchersProvider.class); RecogMatchers result = mock(RecogMatchers.class); @@ -65,7 +65,7 @@ public void getMatchersSingleProviderMatch() { @Test public void getMatchersMultipleProviderNoMatch() { // given - String name = anyString(); + String name = anyUTF8String(); RecogType type = anyEnum(RecogType.class); IRecogMatchersProvider provider1 = mock(IRecogMatchersProvider.class); IRecogMatchersProvider provider2 = mock(IRecogMatchersProvider.class); @@ -85,7 +85,7 @@ public void getMatchersMultipleProviderNoMatch() { @Test public void getMatchersMultipleProviderSingleMatchFirst() { // given - String name = anyString(); + String name = anyUTF8String(); RecogType type = anyEnum(RecogType.class); IRecogMatchersProvider provider1 = mock(IRecogMatchersProvider.class); IRecogMatchersProvider provider2 = mock(IRecogMatchersProvider.class); @@ -106,7 +106,7 @@ public void getMatchersMultipleProviderSingleMatchFirst() { @Test public void getMatchersMultipleProviderSingleMatchLast() { // given - String name = anyString(); + String name = anyUTF8String(); RecogType type = anyEnum(RecogType.class); IRecogMatchersProvider provider1 = mock(IRecogMatchersProvider.class); IRecogMatchersProvider provider2 = mock(IRecogMatchersProvider.class); @@ -127,7 +127,7 @@ public void getMatchersMultipleProviderSingleMatchLast() { @Test public void getMatchersMultipleProviderMultipleMatchesFirstIsReturned() { // given - String name = anyString(); + String name = anyUTF8String(); RecogType type = anyEnum(RecogType.class); IRecogMatchersProvider provider1 = mock(IRecogMatchersProvider.class); IRecogMatchersProvider provider2 = mock(IRecogMatchersProvider.class); @@ -156,7 +156,7 @@ public void getMatchersMultipleProviderMultipleMatchesFirstIsReturned() { @Test public void getMatchersMultipleProviderMultipleMatchesFirstIsReturnedWhenNotFirst() { // given - String name = anyString(); + String name = anyUTF8String(); RecogType type = anyEnum(RecogType.class); IRecogMatchersProvider provider1 = mock(IRecogMatchersProvider.class); IRecogMatchersProvider provider2 = mock(IRecogMatchersProvider.class);