Skip to content

Commit 6b980ed

Browse files
fix: add support for deserializing zoned expressions (#153)
* fix: add support for deserializing zoned expressions * chore: suppression update
1 parent beeb208 commit 6b980ed

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/schema/typefunctions/DateTimeScalar.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.lang.reflect.AnnotatedType;
1313
import java.time.DateTimeException;
1414
import java.time.Instant;
15+
import java.time.OffsetDateTime;
1516
import java.time.temporal.TemporalAccessor;
1617
import java.util.function.Function;
1718

@@ -45,10 +46,10 @@ private <E extends GraphqlErrorException> Instant toInstant(
4546
return Instant.from((TemporalAccessor) instantInput);
4647
}
4748
if (instantInput instanceof CharSequence) {
48-
return Instant.parse((CharSequence) instantInput);
49+
return parse((CharSequence) instantInput);
4950
}
5051
if (instantInput instanceof StringValue) {
51-
return Instant.parse(((StringValue) instantInput).getValue());
52+
return parse(((StringValue) instantInput).getValue());
5253
}
5354
} catch (DateTimeException exception) {
5455
throw errorWrapper.apply(exception);
@@ -75,4 +76,8 @@ public GraphQLScalarType buildType(
7576
ProcessingElementsContainer container) {
7677
return DATE_TIME_SCALAR;
7778
}
79+
80+
private static Instant parse(CharSequence charSequence) {
81+
return OffsetDateTime.parse(charSequence).toInstant();
82+
}
7883
}

hypertrace-core-graphql-common-schema/src/test/java/org/hypertrace/core/graphql/common/schema/scalars/DateTimeScalarTest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
@ExtendWith(MockitoExtension.class)
2020
class DateTimeScalarTest {
2121

22-
private static final String TEST_DATE_TIME_STRING = "2019-10-29T21:30:12.871Z";
23-
private static final Instant TEST_DATE_TIME_INSTANT = Instant.parse(TEST_DATE_TIME_STRING);
22+
private static final String TEST_UTC_DATE_TIME_STRING = "2019-10-29T21:30:12.871Z";
23+
private static final String TEST_ZONED_DATE_TIME_STRING = "2019-10-30T03:00:12.871+05:30";
24+
private static final Instant TEST_DATE_TIME_INSTANT = Instant.parse(TEST_UTC_DATE_TIME_STRING);
2425
private DateTimeScalar dateTimeFunction;
2526
private GraphQLScalarType dateTimeType;
2627
@Mock AnnotatedType mockAnnotatedType;
@@ -45,18 +46,24 @@ void canDetermineIfConvertible() {
4546
@Test
4647
void canConvertFromLiteral() {
4748
assertEquals(
48-
TEST_DATE_TIME_INSTANT, dateTimeType.getCoercing().parseLiteral(TEST_DATE_TIME_STRING));
49+
TEST_DATE_TIME_INSTANT, dateTimeType.getCoercing().parseLiteral(TEST_UTC_DATE_TIME_STRING));
50+
assertEquals(
51+
TEST_DATE_TIME_INSTANT,
52+
dateTimeType.getCoercing().parseLiteral(TEST_ZONED_DATE_TIME_STRING));
4953
}
5054

5155
@Test
5256
void canSerialize() {
5357
assertEquals(
54-
TEST_DATE_TIME_STRING, dateTimeType.getCoercing().serialize(TEST_DATE_TIME_INSTANT));
58+
TEST_UTC_DATE_TIME_STRING, dateTimeType.getCoercing().serialize(TEST_DATE_TIME_INSTANT));
5559
assertEquals(
56-
TEST_DATE_TIME_STRING, dateTimeType.getCoercing().serialize(TEST_DATE_TIME_STRING));
60+
TEST_UTC_DATE_TIME_STRING, dateTimeType.getCoercing().serialize(TEST_UTC_DATE_TIME_STRING));
61+
assertEquals(
62+
TEST_UTC_DATE_TIME_STRING,
63+
dateTimeType.getCoercing().serialize(TEST_ZONED_DATE_TIME_STRING));
5764

5865
assertEquals(
59-
TEST_DATE_TIME_STRING,
66+
TEST_UTC_DATE_TIME_STRING,
6067
dateTimeType
6168
.getCoercing()
6269
.serialize(TEST_DATE_TIME_INSTANT.atOffset(ZoneOffset.ofHoursMinutes(12, 30))));
@@ -68,6 +75,11 @@ void canConvertFromValue() {
6875
TEST_DATE_TIME_INSTANT,
6976
dateTimeType
7077
.getCoercing()
71-
.parseValue(StringValue.newStringValue().value(TEST_DATE_TIME_STRING).build()));
78+
.parseValue(StringValue.newStringValue().value(TEST_UTC_DATE_TIME_STRING).build()));
79+
assertEquals(
80+
TEST_DATE_TIME_INSTANT,
81+
dateTimeType
82+
.getCoercing()
83+
.parseValue(StringValue.newStringValue().value(TEST_ZONED_DATE_TIME_STRING).build()));
7284
}
7385
}

owasp-suppressions.xml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@
88
<cpe>cpe:/a:grpc:grpc</cpe>
99
<cpe>cpe:/a:utils_project:utils</cpe>
1010
</suppress>
11-
<suppress>
12-
<notes><![CDATA[
13-
file name: graphql-java-annotations-9.1.jar
14-
]]></notes>
15-
<packageUrl regex="true">^pkg:maven/io\.github\.graphql\-java/graphql\-java\-annotations@.*$</packageUrl>
16-
<cpe>cpe:/a:graphql-java:graphql-java</cpe>
17-
</suppress>
18-
<suppress until="2023-11-30Z">
11+
<suppress until="2023-12-31Z">
1912
<notes><![CDATA[
2013
This vulnerability is disputed, with the argument that SSL configuration is the responsibility of the client rather
2114
than the transport. The change in default is under consideration for the next major Netty release, revisit then.
@@ -27,7 +20,7 @@
2720
<packageUrl regex="true">^pkg:maven/io\.netty/netty.*@.*$</packageUrl>
2821
<vulnerabilityName>CVE-2023-4586</vulnerabilityName>
2922
</suppress>
30-
<suppress until="2023-11-30Z">
23+
<suppress until="2023-12-31Z">
3124
<notes><![CDATA[
3225
This CVE is declared fixed from 9.4.52, but the vuln db is not reflecting that. Suppress that specific version until
3326
db is updated.
@@ -37,7 +30,7 @@
3730
<packageUrl regex="true">^pkg:maven/org\.eclipse\.jetty/jetty\[email protected]\..*$</packageUrl>
3831
<vulnerabilityName>CVE-2023-36479</vulnerabilityName>
3932
</suppress>
40-
<suppress until="2023-11-30Z">
33+
<suppress until="2023-12-31Z">
4134
<notes><![CDATA[
4235
file name: jackson-databind-2.15.2.jar
4336
]]></notes>

0 commit comments

Comments
 (0)