Skip to content

Commit

Permalink
Add more unit tests for negative scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
en-milie committed Dec 20, 2023
1 parent bf3a231 commit cc01d3d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/test/java/com/endava/cats/args/FilterArgumentsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,15 @@ void shouldIncludeWildcard(String wildcardPattern, String result) {
List<String> filteredPaths = filterArguments.getPathsToRun(openAPI);
Assertions.assertThat(filteredPaths).containsOnly(result);
}

@Test
void shouldHaveDefaultHttpMethods() {
Assertions.assertThat(filterArguments.isHttpMethodSupplied(HttpMethod.POST)).isTrue();
Assertions.assertThat(filterArguments.isHttpMethodSupplied(HttpMethod.BIND)).isFalse();
}

@Test
void shouldReturnFuzzersAsClasses() {
Assertions.assertThat(filterArguments.getFirstPhaseFuzzersAsFuzzers()).hasSize(90);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ void shouldHaveToString() {
}


@Test
void shouldNotRunWhenNoResponseHeaders() {
FuzzingData data = FuzzingData.builder().responseHeaders(Collections.emptyMap())
.requestContentTypes(Collections.singletonList("application/json")).reqSchema(new StringSchema()).build();
Mockito.doNothing().when(testCaseListener).reportResult(Mockito.any(),
Mockito.eq(data), Mockito.any(), Mockito.eq(ResponseCodeFamily.TWOXX));
Mockito.doNothing().when(testCaseListener).reportResultError(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.any());

CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).headers(Collections.emptyList()).build();
Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);

responseHeadersMatchContractHeadersFuzzer.fuzz(data);

Mockito.verifyNoInteractions(testCaseListener);
}

@Test
void shouldReportMissingHeaders() {
FuzzingData data = FuzzingData.builder().responseHeaders(Map.of("200", Set.of("missingHeader", "anotherMissingHeader")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void shouldSanitize(String input, String expected) {
}

@ParameterizedTest
@CsvSource(value = {"^\\+?[1-9]\\d{6,15}$;16", "[A-Z]+;20", "[A-Z0-9]{13,18};18", "[0-9]+;10", "^(?=[^\\s])(?=.*[^\\s]$)(?=^(?:(?!<|>|%3e|%3c).)*$).*$;2048"}, delimiterString = ";")
@CsvSource(value = {"^\\+?[1-9]\\d{6,15}$;16", "[A-Z]+;20", "[A-Z0-9]{13,18};18", "[0-9]+;10", "^(?=[^\\s])(?=.*[^\\s]$)(?=^(?:(?!<|>|%3e|%3c).)*$).*$;2048", "M|F;1"}, delimiterString = ";")
void shouldGenerateFixedLength(String pattern, int length) {
String fixedLengthGenerated = StringGenerator.generateExactLength(pattern, length);

Expand Down

0 comments on commit cc01d3d

Please sign in to comment.