Skip to content

Commit c935467

Browse files
committed
Disable remote access in JSON schema test
Signed-off-by: Piotr P. Karwasz <[email protected]>
1 parent 08e3851 commit c935467

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

tools/src/test/java/org/cyclonedx/schema/JsonSchemaVerificationTest.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
package org.cyclonedx.schema;
1515

16-
import static java.util.Objects.requireNonNull;
1716
import static org.junit.jupiter.api.Assertions.assertFalse;
1817
import static org.junit.jupiter.api.Assertions.assertTrue;
1918

@@ -29,10 +28,12 @@
2928
import com.networknt.schema.JsonSchemaFactory;
3029
import com.networknt.schema.NonValidationKeyword;
3130
import com.networknt.schema.SchemaId;
31+
import com.networknt.schema.SchemaLocation;
3232
import com.networknt.schema.SchemaValidatorsConfig;
33+
import com.networknt.schema.resource.ClasspathSchemaLoader;
34+
import com.networknt.schema.resource.DisallowSchemaLoader;
3335
import java.io.IOException;
3436
import java.io.InputStream;
35-
import java.net.URISyntaxException;
3637
import java.util.ArrayList;
3738
import java.util.Collection;
3839
import java.util.List;
@@ -44,6 +45,9 @@ class JsonSchemaVerificationTest extends BaseSchemaVerificationTest {
4445

4546
private static final ObjectMapper MAPPER = new JsonMapper();
4647

48+
private static final String JSF_NAMESPACE = "http://cyclonedx.org/schema/jsf-0.82.schema.json";
49+
private static final String SPDX_NAMESPACE = "http://cyclonedx.org/schema/spdx.schema.json";
50+
4751
private static final JsonSchema VERSION_12;
4852
private static final JsonSchema VERSION_13;
4953
private static final JsonSchema VERSION_14;
@@ -62,22 +66,15 @@ public JsonMetaSchema getMetaSchema(
6266
.defaultMetaSchemaIri(SchemaId.V7)
6367
.metaSchema(addCustomKeywords(JsonMetaSchema.getV7()))
6468
.metaSchemaFactory(metaSchemaFactory)
69+
.schemaLoaders(b -> b.add(new ClasspathSchemaLoader()).add(DisallowSchemaLoader.getInstance()))
70+
.schemaMappers(b -> b.mapPrefix(SPDX_NAMESPACE, "classpath:spdx.schema.json")
71+
.mapPrefix(JSF_NAMESPACE, "classpath:jsf-0.82.schema.json"))
6572
.build();
66-
ClassLoader cl = JsonSchemaVerificationTest.class.getClassLoader();
67-
try {
68-
VERSION_12 = factory.getSchema(
69-
requireNonNull(cl.getResource("bom-1.2-strict.schema.json")).toURI());
70-
VERSION_13 = factory.getSchema(
71-
requireNonNull(cl.getResource("bom-1.3-strict.schema.json")).toURI());
72-
VERSION_14 = factory.getSchema(
73-
requireNonNull(cl.getResource("bom-1.4.schema.json")).toURI());
74-
VERSION_15 = factory.getSchema(
75-
requireNonNull(cl.getResource("bom-1.5.schema.json")).toURI());
76-
VERSION_16 = factory.getSchema(
77-
requireNonNull(cl.getResource("bom-1.6.schema.json")).toURI());
78-
} catch (URISyntaxException e) {
79-
throw new IllegalStateException(e);
80-
}
73+
VERSION_12 = factory.getSchema(SchemaLocation.of("classpath:bom-1.2-strict.schema.json"));
74+
VERSION_13 = factory.getSchema(SchemaLocation.of("classpath:bom-1.3-strict.schema.json"));
75+
VERSION_14 = factory.getSchema(SchemaLocation.of("classpath:bom-1.4.schema.json"));
76+
VERSION_15 = factory.getSchema(SchemaLocation.of("classpath:bom-1.5.schema.json"));
77+
VERSION_16 = factory.getSchema(SchemaLocation.of("classpath:bom-1.6.schema.json"));
8178
}
8279

8380
private static JsonMetaSchema addCustomKeywords(JsonMetaSchema metaSchema) {

0 commit comments

Comments
 (0)