@@ -3162,4 +3162,99 @@ public void testIssue_1746_headers_relative_paths() {
3162
3162
OpenAPI openAPI = parseResult .getOpenAPI ();
3163
3163
assertEquals (openAPI .getPaths ().get ("/pets" ).getGet ().getResponses ().get ("200" ).getHeaders ().get ("x-next" ).get$ref (), "#/components/headers/LocationInHeaders" );
3164
3164
}
3165
+
3166
+ @ Test (description = "Test safe resolving" )
3167
+ public void test31SafeURLResolving () {
3168
+ ParseOptions parseOptions = new ParseOptions ();
3169
+ parseOptions .setResolveFully (true );
3170
+ parseOptions .setSafelyResolveURL (true );
3171
+ List <String > allowList = Collections .emptyList ();
3172
+ List <String > blockList = Collections .emptyList ();
3173
+ parseOptions .setRemoteRefAllowList (allowList );
3174
+ parseOptions .setRemoteRefBlockList (blockList );
3175
+
3176
+ SwaggerParseResult result = new OpenAPIV3Parser ().readLocation ("safeResolving/oas30SafeUrlResolvingWithPetstore.yaml" , null , parseOptions );
3177
+ if (result .getMessages () != null ) {
3178
+ for (String message : result .getMessages ()) {
3179
+ assertTrue (message .contains ("Server returned HTTP response code: 403" ));
3180
+ }
3181
+ }
3182
+ }
3183
+
3184
+ @ Test (description = "Test safe resolving with blocked URL" )
3185
+ public void test31SafeURLResolvingWithBlockedURL () {
3186
+ ParseOptions parseOptions = new ParseOptions ();
3187
+ parseOptions .setResolveFully (true );
3188
+ parseOptions .setSafelyResolveURL (true );
3189
+ List <String > allowList = Collections .emptyList ();
3190
+ List <String > blockList = Arrays .asList ("petstore3.swagger.io" );
3191
+ parseOptions .setRemoteRefAllowList (allowList );
3192
+ parseOptions .setRemoteRefBlockList (blockList );
3193
+
3194
+ SwaggerParseResult result = new OpenAPIV3Parser ().readLocation ("safeResolving/oas30SafeUrlResolvingWithPetstore.yaml" , null , parseOptions );
3195
+
3196
+ if (result .getMessages () != null ) {
3197
+ for (String message : result .getMessages ()) {
3198
+ assertTrue (
3199
+ message .contains ("Server returned HTTP response code: 403" ) ||
3200
+ message .contains ("URL is part of the explicit denylist. URL [https://petstore3.swagger.io/api/v3/openapi.json]" ));
3201
+ }
3202
+ }
3203
+ }
3204
+
3205
+ @ Test (description = "Test safe resolving with turned off safelyResolveURL option" )
3206
+ public void test31SafeURLResolvingWithTurnedOffSafeResolving () {
3207
+ ParseOptions parseOptions = new ParseOptions ();
3208
+ parseOptions .setResolveFully (true );
3209
+ parseOptions .setSafelyResolveURL (false );
3210
+ List <String > allowList = Collections .emptyList ();
3211
+ List <String > blockList = Arrays .asList ("petstore3.swagger.io" );
3212
+ parseOptions .setRemoteRefAllowList (allowList );
3213
+ parseOptions .setRemoteRefBlockList (blockList );
3214
+
3215
+ SwaggerParseResult result = new OpenAPIV3Parser ().readLocation ("safeResolving/oas30SafeUrlResolvingWithPetstore.yaml" , null , parseOptions );
3216
+ if (result .getMessages () != null ) {
3217
+ for (String message : result .getMessages ()) {
3218
+ assertTrue (message .contains ("Server returned HTTP response code: 403" ));
3219
+ }
3220
+ }
3221
+ }
3222
+
3223
+ @ Test (description = "Test safe resolving with localhost and blocked url" )
3224
+ public void test31SafeURLResolvingWithLocalhostAndBlockedURL () {
3225
+ ParseOptions parseOptions = new ParseOptions ();
3226
+ parseOptions .setResolveFully (true );
3227
+ parseOptions .setSafelyResolveURL (true );
3228
+
3229
+ SwaggerParseResult result = new OpenAPIV3Parser ().readLocation ("safeResolving/oas30SafeUrlResolvingWithLocalhost.yaml" , null , parseOptions );
3230
+ if (result .getMessages () != null ) {
3231
+ for (String message : result .getMessages ()) {
3232
+ assertTrue (
3233
+ message .contains ("Server returned HTTP response code: 403" ) ||
3234
+ message .contains ("IP is restricted" ));
3235
+ }
3236
+ }
3237
+ }
3238
+
3239
+ @ Test (description = "Test safe resolving with localhost url" )
3240
+ public void test31SafeURLResolvingWithLocalhost () {
3241
+ ParseOptions parseOptions = new ParseOptions ();
3242
+ parseOptions .setResolveFully (true );
3243
+ parseOptions .setSafelyResolveURL (true );
3244
+ List <String > blockList = Arrays .asList ("petstore.swagger.io" );
3245
+ parseOptions .setRemoteRefBlockList (blockList );
3246
+
3247
+ String error = "URL is part of the explicit denylist. URL [https://petstore.swagger.io/v2/swagger.json]" ;
3248
+ SwaggerParseResult result = new OpenAPIV3Parser ().readLocation ("safeResolving/oas30SafeUrlResolvingWithLocalhost.yaml" , null , parseOptions );
3249
+
3250
+ if (result .getMessages () != null ) {
3251
+ for (String message : result .getMessages ()) {
3252
+ assertTrue (
3253
+ message .contains ("Server returned HTTP response code: 403" ) ||
3254
+ message .contains ("IP is restricted" ) ||
3255
+ message .contains (error )
3256
+ );
3257
+ }
3258
+ }
3259
+ }
3165
3260
}
0 commit comments