Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: swagger-api/swagger-parser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 78849f1d05fa7f8142cf5847e6148c14bcbaf805
Choose a base ref
..
head repository: swagger-api/swagger-parser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1b1fa85017aa80c76a2192b4b169cc7b229da3d8
Choose a head ref
Showing with 33 additions and 13 deletions.
  1. +33 −13 modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OAI31DeserializationTest.java
Original file line number Diff line number Diff line change
@@ -1046,8 +1046,11 @@ public void test31SafeURLResolving() {
parseOptions.setRemoteRefBlockList(blockList);

SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithPetstore.yaml", null, parseOptions);

assertTrue(result.getMessages().isEmpty());
if (result.getMessages() != null) {
for (String message : result.getMessages()) {
assertTrue(message.contains("Server returned HTTP response code: 403"));
}
}
}

@Test(description = "Test safe resolving with blocked URL")
@@ -1060,11 +1063,15 @@ public void test31SafeURLResolvingWithBlockedURL() {
parseOptions.setRemoteRefAllowList(allowList);
parseOptions.setRemoteRefBlockList(blockList);

List<String> errorList = Arrays.asList("URL is part of the explicit denylist. URL [https://petstore3.swagger.io/api/v3/openapi.json]");
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithPetstore.yaml", null, parseOptions);

assertEquals(result.getMessages(), errorList);
assertEquals(result.getMessages().size(), 1);
if (result.getMessages() != null) {
for (String message : result.getMessages()) {
assertTrue(
message.contains("Server returned HTTP response code: 403") ||
message.contains("URL is part of the explicit denylist. URL [https://petstore3.swagger.io/api/v3/openapi.json]"));
}
}
}

@Test(description = "Test safe resolving with turned off safelyResolveURL option")
@@ -1078,8 +1085,11 @@ public void test31SafeURLResolvingWithTurnedOffSafeResolving() {
parseOptions.setRemoteRefBlockList(blockList);

SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithPetstore.yaml", null, parseOptions);

assertTrue(result.getMessages().isEmpty());
if (result.getMessages() != null) {
for (String message : result.getMessages()) {
assertTrue(message.contains("Server returned HTTP response code: 403"));
}
}
}

@Test(description = "Test safe resolving with localhost and blocked url")
@@ -1089,9 +1099,13 @@ public void test31SafeURLResolvingWithLocalhostAndBlockedURL() {
parseOptions.setSafelyResolveURL(true);

SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithLocalhost.yaml", null, parseOptions);

assertTrue(result.getMessages().get(0).contains("IP is restricted"));
assertEquals(result.getMessages().size(), 1);
if (result.getMessages() != null) {
for (String message : result.getMessages()) {
assertTrue(
message.contains("Server returned HTTP response code: 403") ||
message.contains("IP is restricted"));
}
}
}

@Test(description = "Test safe resolving with localhost url")
@@ -1105,8 +1119,14 @@ public void test31SafeURLResolvingWithLocalhost() {
String error = "URL is part of the explicit denylist. URL [https://petstore.swagger.io/v2/swagger.json]";
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("3.1.0/resolve/safeResolving/safeUrlResolvingWithLocalhost.yaml", null, parseOptions);

assertTrue(result.getMessages().get(0).contains("IP is restricted"));
assertEquals(result.getMessages().get(1), error);
assertEquals(result.getMessages().size(), 2);
if (result.getMessages() != null) {
for (String message : result.getMessages()) {
assertTrue(
message.contains("Server returned HTTP response code: 403") ||
message.contains("IP is restricted") ||
message.contains(error)
);
}
}
}
}