diff --git a/hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/schema/typefunctions/DateTimeScalar.java b/hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/schema/typefunctions/DateTimeScalar.java index c3429f8d..3b60ebaf 100644 --- a/hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/schema/typefunctions/DateTimeScalar.java +++ b/hypertrace-core-graphql-common-schema/src/main/java/org/hypertrace/core/graphql/common/schema/typefunctions/DateTimeScalar.java @@ -12,6 +12,7 @@ import java.lang.reflect.AnnotatedType; import java.time.DateTimeException; import java.time.Instant; +import java.time.OffsetDateTime; import java.time.temporal.TemporalAccessor; import java.util.function.Function; @@ -45,10 +46,10 @@ private Instant toInstant( return Instant.from((TemporalAccessor) instantInput); } if (instantInput instanceof CharSequence) { - return Instant.parse((CharSequence) instantInput); + return parse((CharSequence) instantInput); } if (instantInput instanceof StringValue) { - return Instant.parse(((StringValue) instantInput).getValue()); + return parse(((StringValue) instantInput).getValue()); } } catch (DateTimeException exception) { throw errorWrapper.apply(exception); @@ -75,4 +76,8 @@ public GraphQLScalarType buildType( ProcessingElementsContainer container) { return DATE_TIME_SCALAR; } + + private static Instant parse(CharSequence charSequence) { + return OffsetDateTime.parse(charSequence).toInstant(); + } } diff --git a/hypertrace-core-graphql-common-schema/src/test/java/org/hypertrace/core/graphql/common/schema/scalars/DateTimeScalarTest.java b/hypertrace-core-graphql-common-schema/src/test/java/org/hypertrace/core/graphql/common/schema/scalars/DateTimeScalarTest.java index 5f5953c5..e78f5e7c 100644 --- a/hypertrace-core-graphql-common-schema/src/test/java/org/hypertrace/core/graphql/common/schema/scalars/DateTimeScalarTest.java +++ b/hypertrace-core-graphql-common-schema/src/test/java/org/hypertrace/core/graphql/common/schema/scalars/DateTimeScalarTest.java @@ -19,8 +19,9 @@ @ExtendWith(MockitoExtension.class) class DateTimeScalarTest { - private static final String TEST_DATE_TIME_STRING = "2019-10-29T21:30:12.871Z"; - private static final Instant TEST_DATE_TIME_INSTANT = Instant.parse(TEST_DATE_TIME_STRING); + private static final String TEST_UTC_DATE_TIME_STRING = "2019-10-29T21:30:12.871Z"; + private static final String TEST_ZONED_DATE_TIME_STRING = "2019-10-30T03:00:12.871+05:30"; + private static final Instant TEST_DATE_TIME_INSTANT = Instant.parse(TEST_UTC_DATE_TIME_STRING); private DateTimeScalar dateTimeFunction; private GraphQLScalarType dateTimeType; @Mock AnnotatedType mockAnnotatedType; @@ -45,18 +46,24 @@ void canDetermineIfConvertible() { @Test void canConvertFromLiteral() { assertEquals( - TEST_DATE_TIME_INSTANT, dateTimeType.getCoercing().parseLiteral(TEST_DATE_TIME_STRING)); + TEST_DATE_TIME_INSTANT, dateTimeType.getCoercing().parseLiteral(TEST_UTC_DATE_TIME_STRING)); + assertEquals( + TEST_DATE_TIME_INSTANT, + dateTimeType.getCoercing().parseLiteral(TEST_ZONED_DATE_TIME_STRING)); } @Test void canSerialize() { assertEquals( - TEST_DATE_TIME_STRING, dateTimeType.getCoercing().serialize(TEST_DATE_TIME_INSTANT)); + TEST_UTC_DATE_TIME_STRING, dateTimeType.getCoercing().serialize(TEST_DATE_TIME_INSTANT)); assertEquals( - TEST_DATE_TIME_STRING, dateTimeType.getCoercing().serialize(TEST_DATE_TIME_STRING)); + TEST_UTC_DATE_TIME_STRING, dateTimeType.getCoercing().serialize(TEST_UTC_DATE_TIME_STRING)); + assertEquals( + TEST_UTC_DATE_TIME_STRING, + dateTimeType.getCoercing().serialize(TEST_ZONED_DATE_TIME_STRING)); assertEquals( - TEST_DATE_TIME_STRING, + TEST_UTC_DATE_TIME_STRING, dateTimeType .getCoercing() .serialize(TEST_DATE_TIME_INSTANT.atOffset(ZoneOffset.ofHoursMinutes(12, 30)))); @@ -68,6 +75,11 @@ void canConvertFromValue() { TEST_DATE_TIME_INSTANT, dateTimeType .getCoercing() - .parseValue(StringValue.newStringValue().value(TEST_DATE_TIME_STRING).build())); + .parseValue(StringValue.newStringValue().value(TEST_UTC_DATE_TIME_STRING).build())); + assertEquals( + TEST_DATE_TIME_INSTANT, + dateTimeType + .getCoercing() + .parseValue(StringValue.newStringValue().value(TEST_ZONED_DATE_TIME_STRING).build())); } } diff --git a/owasp-suppressions.xml b/owasp-suppressions.xml index bd273df4..fcf5e046 100644 --- a/owasp-suppressions.xml +++ b/owasp-suppressions.xml @@ -8,14 +8,7 @@ cpe:/a:grpc:grpc cpe:/a:utils_project:utils - - - ^pkg:maven/io\.github\.graphql\-java/graphql\-java\-annotations@.*$ - cpe:/a:graphql-java:graphql-java - - + ^pkg:maven/io\.netty/netty.*@.*$ CVE-2023-4586 - + ^pkg:maven/org\.eclipse\.jetty/jetty\-servlets@9.4.53\..*$ CVE-2023-36479 - +