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 367a2b6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public static ClusterType instance(String value) {
}

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

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/opensearch/knn/indices/ModelDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,11 @@ public ModelMetadata getMetadata(String modelId) {
}

private String getMapping() throws IOException {
if (ModelDao.class.getClassLoader() == null) {
throw new IllegalStateException("ClassLoader of ModelDao Class is null");

Check warning on line 470 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#L470

Added line #L470 was not covered by tests
}
URL url = ModelDao.class.getClassLoader().getResource(MODEL_INDEX_MAPPING_PATH);

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

@BeforeClass
public static void setUpClass() throws IOException {
if (FaissIT.class.getClassLoader() == null) {
throw new IllegalStateException("ClassLoader of FaissIT Class is 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;
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/org/opensearch/knn/index/NmslibIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ 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");
if (NmslibIT.class.getClassLoader() == null) {
throw new IllegalStateException("ClassLoader of NmslibIT Class is 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());
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/org/opensearch/knn/index/OpenSearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ 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");
if (OpenSearchIT.class.getClassLoader() == null) {
throw new IllegalStateException("ClassLoader of OpenSearchIT Class is 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());
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/opensearch/knn/jni/JNIServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class JNIServiceTests extends KNNTestCase {

@BeforeClass
public static void setUpClass() throws IOException {
if (JNIServiceTests.class.getClassLoader() == null) {
throw new IllegalStateException("ClassLoader of JNIServiceTests Class is 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public static void dumpCoverage() throws IOException, MalformedObjectNameExcepti
}

String serverUrl = System.getProperty("jmx.serviceUrl");
if (serverUrl == null) {
log.error("Failed to dump coverage because JMX Service URL is null");
throw new IllegalArgumentException("JMX Service URL is null");
}

try (JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(serverUrl))) {
IProxy proxy = MBeanServerInvocationHandler.newProxyInstance(
connector.getMBeanServerConnection(),
Expand All @@ -129,7 +134,7 @@ public static void dumpCoverage() throws IOException, MalformedObjectNameExcepti
false
);

Path path = Path.of(jacocoBuildPath, "integTest.exec");
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);
Expand Down

0 comments on commit 367a2b6

Please sign in to comment.