Skip to content

Commit 7685575

Browse files
[FME-10341] fix vulns, update versions and add shutdown
1 parent 11acec0 commit 7685575

File tree

5 files changed

+47
-31
lines changed

5 files changed

+47
-31
lines changed

pom.xml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@
4949
<artifactId>java-client</artifactId>
5050
<version>4.18.1</version>
5151
</dependency>
52-
<dependency>
53-
<groupId>org.apache.httpcomponents</groupId>
54-
<artifactId>httpclient</artifactId>
55-
<version>4.5.14</version>
56-
</dependency>
5752
<dependency>
5853
<groupId>org.mockito</groupId>
5954
<artifactId>mockito-core</artifactId>
@@ -65,16 +60,6 @@
6560
<artifactId>sdk</artifactId>
6661
<version>1.18.1</version>
6762
</dependency>
68-
<dependency>
69-
<groupId>com.fasterxml.jackson.core</groupId>
70-
<artifactId>jackson-core</artifactId>
71-
<version>2.20.0</version>
72-
</dependency>
73-
<dependency>
74-
<groupId>com.fasterxml.jackson.core</groupId>
75-
<artifactId>jackson-databind</artifactId>
76-
<version>2.20.0</version>
77-
</dependency>
7863
</dependencies>
7964
<build>
8065
<pluginManagement>
@@ -85,6 +70,22 @@
8570
<artifactId>maven-clean-plugin</artifactId>
8671
<version>3.5.0</version>
8772
</plugin>
73+
<plugin>
74+
<groupId>org.owasp</groupId>
75+
<artifactId>dependency-check-maven</artifactId>
76+
<version>12.1.6</version>
77+
<configuration>
78+
<nvdApiKey>41aa3456-48f3-466a-a8ea-db1e84caba36</nvdApiKey>
79+
<failBuildOnCVSS>7</failBuildOnCVSS>
80+
</configuration>
81+
<executions>
82+
<execution>
83+
<goals>
84+
<goal>check</goal>
85+
</goals>
86+
</execution>
87+
</executions>
88+
</plugin>
8889
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
8990
<plugin>
9091
<artifactId>maven-resources-plugin</artifactId>

src/main/java/io/split/openfeature/SplitProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ public Map<String, Object> transformContext(EvaluationContext context) {
158158
return context.asObjectMap();
159159
}
160160

161+
@Override
162+
public void shutdown() {
163+
client.destroy();
164+
}
165+
161166
private SplitResult evaluateTreatment(String key, EvaluationContext evaluationContext) {
162167
String id = evaluationContext.getTargetingKey();
163168
if (id == null || id.isEmpty()) {

src/main/java/io/split/openfeature/utils/Serialization.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package io.split.openfeature.utils;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
4-
import com.fasterxml.jackson.databind.DeserializationFeature;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
3+
import java.util.Map;
4+
65
import dev.openfeature.sdk.ErrorCode;
76
import dev.openfeature.sdk.exceptions.ParseError;
8-
9-
import java.util.Map;
7+
import io.split.client.utils.Json;
108

119
public class Serialization {
1210

@@ -15,10 +13,8 @@ private Serialization() {
1513

1614
public static Map<String, Object> stringToMap(final String obj) {
1715
try {
18-
return new ObjectMapper()
19-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
20-
.readValue(obj, Map.class);
21-
} catch (JsonProcessingException e) {
16+
return Json.fromJson(obj, Map.class);
17+
} catch (Exception e) {
2218
throw new ParseError(ErrorCode.PARSE_ERROR.name());
2319
}
2420
}

src/test/java/io/split/openfeature/ClientTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
public class ClientTest {
3131
OpenFeatureAPI openFeatureAPI;
3232
Client client;
33+
SplitClient splitClient;
3334

3435
@BeforeEach
3536
public void init() {
3637
openFeatureAPI = OpenFeatureAPI.getInstance();
3738
try {
3839
SplitClientConfig config = SplitClientConfig.builder().splitFile("src/test/resources/split.yaml").build();
39-
SplitClient client = SplitFactoryBuilder.build("localhost", config).client();
40-
openFeatureAPI.setProviderAndWait(new SplitProvider(client));
40+
splitClient = SplitFactoryBuilder.build("localhost", config).client();
41+
openFeatureAPI.setProviderAndWait(new SplitProvider(splitClient));
4142
} catch (URISyntaxException | IOException e) {
4243
System.out.println("Unexpected Exception occurred initializing Split Provider.");
4344
}
@@ -267,6 +268,13 @@ public void getObjectFailTest() {
267268
assertNull(details.getVariant());
268269
}
269270

271+
@Test
272+
public void destroySplitClientTest() {
273+
assertEquals("32", splitClient.getTreatment("key","int_feature"));
274+
openFeatureAPI.shutdown();
275+
assertEquals("control", splitClient.getTreatment("key","int_feature"));
276+
}
277+
270278
private Value mapToValue(Map<String, Value> map) {
271279
return new Value(new MutableStructure(map));
272280
}

src/test/java/io/split/openfeature/SplitProviderTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,27 +420,26 @@ public void evalStructureComplexTest() {
420420
Instant instant = Instant.ofEpochMilli(1665698754828L);
421421
Value treatment = mapToValue(Map.of(
422422
"string", new Value("blah"),
423-
"int", new Value(10),
423+
"int", new Value(10D),
424424
"double", new Value(100D),
425425
"bool", new Value(true),
426426
"struct", mapToValue(Map.of(
427427
"foo", new Value("bar"),
428-
"baz", new Value(10),
428+
"baz", new Value(10D),
429429
"innerMap", mapToValue(Map.of(
430430
"aa", new Value("bb"))))),
431431
"list", new Value(
432432
List.of(
433-
new Value(1),
434433
new Value(true),
435434
mapToValue(Map.of(
436435
"cc", new Value("dd")
437436
)),
438437
mapToValue(Map.of(
439-
"ee", new Value(1)
438+
"ee", new Value(1D)
440439
)))),
441440
"dateTime", new Value(instant)
442441
));
443-
String treatmentAsString = "{\"string\":\"blah\",\"int\":10,\"double\":100.0,\"bool\":true, \"struct\":{\"foo\":\"bar\",\"baz\":10,\"innerMap\":{\"aa\":\"bb\"}},\"list\":[1,true,{\"cc\":\"dd\"},{\"ee\":1}],\"dateTime\":\"2022-10-13T22:05:54.828Z\"}";
442+
String treatmentAsString = "{\"string\":\"blah\",\"int\":10,\"double\":100.0,\"bool\":true, \"struct\":{\"foo\":\"bar\",\"baz\":10,\"innerMap\":{\"aa\":\"bb\"}},\"list\":[true,{\"cc\":\"dd\"},{\"ee\":1}],\"dateTime\":\"2022-10-13T22:05:54.828Z\"}";
444443

445444
when(mockSplitClient.getTreatmentWithConfig(eq(key), eq(flagName), anyMap())).thenReturn(new SplitResult(treatmentAsString,""));
446445

@@ -525,6 +524,13 @@ public void trackTrafficTypeErrorTest() {
525524
verifyNoInteractions(mockSplitClient);
526525
}
527526

527+
@Test
528+
public void destroySplitClientTest() {
529+
SplitProvider provider = new SplitProvider(mockSplitClient);
530+
provider.shutdown();
531+
verify(mockSplitClient).destroy();
532+
}
533+
528534
private Value mapToValue(Map<String, Value> map) {
529535
return new Value(new MutableStructure(map));
530536
}

0 commit comments

Comments
 (0)