Skip to content

Commit

Permalink
Fix AppSec Findings
Browse files Browse the repository at this point in the history
Signed-off-by: Naveen Tatikonda <[email protected]>
  • Loading branch information
naveentatikonda committed Mar 13, 2024
1 parent 1303182 commit a337eeb
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public static ClusterType instance(String value) {
}

protected final ClusterType getClusterType() {
return ClusterType.instance(System.getProperty(BWCSUITE_CLUSTER));
if (System.getProperty(BWCSUITE_CLUSTER) != null) {
return ClusterType.instance(System.getProperty(BWCSUITE_CLUSTER));
}
throw new IllegalArgumentException(String.format("[%s] value is null", BWCSUITE_CLUSTER));
}

protected final boolean isFirstMixedRound() {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/opensearch/knn/indices/ModelDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,13 @@ public ModelMetadata getMetadata(String modelId) {
}

private String getMapping() throws IOException {
URL url = ModelDao.class.getClassLoader().getResource(MODEL_INDEX_MAPPING_PATH);
URL url = null;
if (ModelDao.class.getClassLoader() != null) {
url = ModelDao.class.getClassLoader().getResource(MODEL_INDEX_MAPPING_PATH);
} else {
throw new IllegalArgumentException("ClassLoader of ModelDao Class is null");

Check warning on line 473 in src/main/java/org/opensearch/knn/indices/ModelDao.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/knn/indices/ModelDao.java#L473

Added line #L473 was not covered by tests
}

if (url == null) {
throw new IllegalStateException("Unable to retrieve mapping for \"" + MODEL_INDEX_NAME + "\"");
}
Expand Down
14 changes: 9 additions & 5 deletions src/test/java/org/opensearch/knn/index/FaissIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ public class FaissIT extends KNNRestTestCase {

@BeforeClass
public static void setUpClass() throws IOException {
URL testIndexVectors = FaissIT.class.getClassLoader().getResource("data/test_vectors_1000x128.json");
URL testQueries = FaissIT.class.getClassLoader().getResource("data/test_queries_100x128.csv");
assert testIndexVectors != null;
assert testQueries != null;
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
if (FaissIT.class.getClassLoader() != null) {
URL testIndexVectors = FaissIT.class.getClassLoader().getResource("data/test_vectors_1000x128.json");
URL testQueries = FaissIT.class.getClassLoader().getResource("data/test_queries_100x128.csv");
assert testIndexVectors != null;
assert testQueries != null;
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
} else {
throw new IllegalArgumentException("ClassLoader of FaissIT Class is null");
}
}

@SneakyThrows
Expand Down
14 changes: 9 additions & 5 deletions src/test/java/org/opensearch/knn/index/NmslibIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ public class NmslibIT extends KNNRestTestCase {

@BeforeClass
public static void setUpClass() throws IOException {
URL testIndexVectors = FaissIT.class.getClassLoader().getResource("data/test_vectors_1000x128.json");
URL testQueries = FaissIT.class.getClassLoader().getResource("data/test_queries_100x128.csv");
assert testIndexVectors != null;
assert testQueries != null;
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
if (NmslibIT.class.getClassLoader() != null) {
URL testIndexVectors = NmslibIT.class.getClassLoader().getResource("data/test_vectors_1000x128.json");
URL testQueries = NmslibIT.class.getClassLoader().getResource("data/test_queries_100x128.csv");
assert testIndexVectors != null;
assert testQueries != null;
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
} else {
throw new IllegalArgumentException("ClassLoader of NmslibIT Class is null");
}
}

public void testEndToEnd() throws Exception {
Expand Down
14 changes: 9 additions & 5 deletions src/test/java/org/opensearch/knn/index/OpenSearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ public class OpenSearchIT extends KNNRestTestCase {

@BeforeClass
public static void setUpClass() throws IOException {
URL testIndexVectors = FaissIT.class.getClassLoader().getResource("data/test_vectors_1000x128.json");
URL testQueries = FaissIT.class.getClassLoader().getResource("data/test_queries_100x128.csv");
assert testIndexVectors != null;
assert testQueries != null;
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
if (OpenSearchIT.class.getClassLoader() != null) {
URL testIndexVectors = OpenSearchIT.class.getClassLoader().getResource("data/test_vectors_1000x128.json");
URL testQueries = OpenSearchIT.class.getClassLoader().getResource("data/test_queries_100x128.csv");
assert testIndexVectors != null;
assert testQueries != null;
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
} else {
throw new IllegalArgumentException("ClassLoader of OpenSearchIT Class is null");
}
}

public void testEndToEnd() throws Exception {
Expand Down
20 changes: 12 additions & 8 deletions src/test/java/org/opensearch/knn/jni/JNIServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ public class JNIServiceTests extends KNNTestCase {

@BeforeClass
public static void setUpClass() throws IOException {
URL testIndexVectors = JNIServiceTests.class.getClassLoader().getResource("data/test_vectors_1000x128.json");
URL testIndexVectorsNested = JNIServiceTests.class.getClassLoader().getResource("data/test_vectors_nested_1000x128.json");
URL testQueries = JNIServiceTests.class.getClassLoader().getResource("data/test_queries_100x128.csv");
assert testIndexVectors != null;
assert testIndexVectorsNested != null;
assert testQueries != null;
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
testDataNested = new TestUtils.TestData(testIndexVectorsNested.getPath(), testQueries.getPath());
if (JNIServiceTests.class.getClassLoader() != null) {
URL testIndexVectors = JNIServiceTests.class.getClassLoader().getResource("data/test_vectors_1000x128.json");
URL testIndexVectorsNested = JNIServiceTests.class.getClassLoader().getResource("data/test_vectors_nested_1000x128.json");
URL testQueries = JNIServiceTests.class.getClassLoader().getResource("data/test_queries_100x128.csv");
assert testIndexVectors != null;
assert testIndexVectorsNested != null;
assert testQueries != null;
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
testDataNested = new TestUtils.TestData(testIndexVectorsNested.getPath(), testQueries.getPath());
} else {
throw new IllegalArgumentException("ClassLoader of JNIServiceTests Class is null");
}
}

public void testCreateIndex_invalid_engineNotSupported() {
Expand Down
31 changes: 18 additions & 13 deletions src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,24 @@ public static void dumpCoverage() throws IOException, MalformedObjectNameExcepti
}

String serverUrl = System.getProperty("jmx.serviceUrl");
try (JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(serverUrl))) {
IProxy proxy = MBeanServerInvocationHandler.newProxyInstance(
connector.getMBeanServerConnection(),
new ObjectName("org.jacoco:type=Runtime"),
IProxy.class,
false
);

Path path = Path.of(jacocoBuildPath, "integTest.exec");
Files.write(path, proxy.getExecutionData(false));
} catch (Exception ex) {
log.error("Failed to dump coverage: ", ex);
throw new RuntimeException("Failed to dump coverage: " + ex);
if (serverUrl != null) {
try (JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(serverUrl))) {
IProxy proxy = MBeanServerInvocationHandler.newProxyInstance(
connector.getMBeanServerConnection(),
new ObjectName("org.jacoco:type=Runtime"),
IProxy.class,
false
);

Path path = Path.of(Path.of(jacocoBuildPath, "integTest.exec").toFile().getCanonicalPath());
Files.write(path, proxy.getExecutionData(false));
} catch (Exception ex) {
log.error("Failed to dump coverage: ", ex);
throw new RuntimeException("Failed to dump coverage: " + ex);
}
} else {
log.error("Failed to dump coverage because JMX Service URL is null");
throw new IllegalArgumentException("JMX Service URL is null");
}
}

Expand Down

0 comments on commit a337eeb

Please sign in to comment.