Skip to content

Validate the ZoneId of the DateTime with ZoneId #961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/bolt-connection/src/bolt/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/

import { structure } from '../packstream'
import { internal } from 'neo4j-driver-core'

const { util } = internal

/**
* Class responsible for applying the expected {@link TypeTransformer} to
Expand All @@ -43,11 +46,15 @@ export default class Transformer {
* @returns {<T>|structure.Structure} The driver object or the structure if the transformer was not found.
*/
fromStructure (struct) {
if (struct instanceof structure.Structure && this._transformersPerSignature.has(struct.signature)) {
const { fromStructure } = this._transformersPerSignature.get(struct.signature)
return fromStructure(struct)
try {
if (struct instanceof structure.Structure && this._transformersPerSignature.has(struct.signature)) {
const { fromStructure } = this._transformersPerSignature.get(struct.signature)
return fromStructure(struct)
}
return struct
} catch (error) {
return util.createBrokenObject(error)
}
return struct
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Nod

exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 5"`;

exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`;
exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`;

exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`;
exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`;

exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`;

Expand Down
5 changes: 3 additions & 2 deletions packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ describe('#unit BoltProtocolV1', () => {

buffer.reset()

expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot()
const unpacked = protocol.unpack(buffer)
expect(() => unpacked instanceof structure.Structure).toThrowErrorMatchingSnapshot()
})

it.each([
Expand All @@ -580,7 +581,7 @@ describe('#unit BoltProtocolV1', () => {
['Date', new structure.Structure(0x44, [1])],
['LocalDateTime', new structure.Structure(0x64, [1, 2])],
['DateTimeWithZoneOffset', new structure.Structure(0x46, [1, 2, 3])],
['DateTimeWithZoneId', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo'])]
['DateTimeWithZoneId', new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo'])]
])('should unpack future structs as structs (%s)', (_, struct) => {
const buffer = alloc(256)
const protocol = new BoltProtocolV1(
Expand Down
11 changes: 6 additions & 5 deletions packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('#unit BoltProtocolV2', () => {
['Time', new Time(1, 1, 1, 1, 1)],
['Date', new Date(1, 1, 1)],
['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao_Paulo')],
['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)],
['Point2D', new Point(1, 1, 1)],
['Point3D', new Point(1, 1, 1, 1)]
Expand Down Expand Up @@ -380,7 +380,7 @@ describe('#unit BoltProtocolV2', () => {
],
[
'DateTimeWithZoneId with more fields',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil'])
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo', 'Brasil'])
]
])('should not unpack with wrong size (%s)', (_, struct) => {
const buffer = alloc(256)
Expand All @@ -396,7 +396,8 @@ describe('#unit BoltProtocolV2', () => {

buffer.reset()

expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot()
const unpacked = protocol.unpack(buffer)
expect(() => unpacked instanceof structure.Structure).toThrowErrorMatchingSnapshot()
})

it.each([
Expand Down Expand Up @@ -442,8 +443,8 @@ describe('#unit BoltProtocolV2', () => {
],
[
'DateTimeWithZoneId',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo')
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao_Paulo')
]
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
const buffer = alloc(256)
Expand Down
11 changes: 6 additions & 5 deletions packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe('#unit BoltProtocolV3', () => {
['Time', new Time(1, 1, 1, 1, 1)],
['Date', new Date(1, 1, 1)],
['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao_Paulo')],
['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)],
['Point2D', new Point(1, 1, 1)],
['Point3D', new Point(1, 1, 1, 1)]
Expand Down Expand Up @@ -585,7 +585,7 @@ describe('#unit BoltProtocolV3', () => {
],
[
'DateTimeWithZoneId with more fields',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil'])
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo', 'Brasil'])
]
])('should not unpack with wrong size (%s)', (_, struct) => {
const buffer = alloc(256)
Expand All @@ -601,7 +601,8 @@ describe('#unit BoltProtocolV3', () => {

buffer.reset()

expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot()
const unpacked = protocol.unpack(buffer)
expect(() => unpacked instanceof structure.Structure).toThrowErrorMatchingSnapshot()
})

it.each([
Expand Down Expand Up @@ -647,8 +648,8 @@ describe('#unit BoltProtocolV3', () => {
],
[
'DateTimeWithZoneId',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo')
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao_Paulo')
]
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
const buffer = alloc(256)
Expand Down
11 changes: 6 additions & 5 deletions packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ describe('#unit BoltProtocolV4x0', () => {
['Time', new Time(1, 1, 1, 1, 1)],
['Date', new Date(1, 1, 1)],
['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao_Paulo')],
['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)],
['Point2D', new Point(1, 1, 1)],
['Point3D', new Point(1, 1, 1, 1)]
Expand Down Expand Up @@ -503,7 +503,7 @@ describe('#unit BoltProtocolV4x0', () => {
],
[
'DateTimeWithZoneId with more fields',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil'])
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo', 'Brasil'])
]
])('should not unpack with wrong size (%s)', (_, struct) => {
const buffer = alloc(256)
Expand All @@ -519,7 +519,8 @@ describe('#unit BoltProtocolV4x0', () => {

buffer.reset()

expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot()
const unpacked = protocol.unpack(buffer)
expect(() => unpacked instanceof structure.Structure).toThrowErrorMatchingSnapshot()
})

it.each([
Expand Down Expand Up @@ -565,8 +566,8 @@ describe('#unit BoltProtocolV4x0', () => {
],
[
'DateTimeWithZoneId',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo')
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao_Paulo')
]
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
const buffer = alloc(256)
Expand Down
11 changes: 6 additions & 5 deletions packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('#unit BoltProtocolV4x1', () => {
['Time', new Time(1, 1, 1, 1, 1)],
['Date', new Date(1, 1, 1)],
['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao_Paulo')],
['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)],
['Point2D', new Point(1, 1, 1)],
['Point3D', new Point(1, 1, 1, 1)]
Expand Down Expand Up @@ -377,7 +377,7 @@ describe('#unit BoltProtocolV4x1', () => {
],
[
'DateTimeWithZoneId with more fields',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil'])
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo', 'Brasil'])
]
])('should not unpack with wrong size (%s)', (_, struct) => {
const buffer = alloc(256)
Expand All @@ -393,7 +393,8 @@ describe('#unit BoltProtocolV4x1', () => {

buffer.reset()

expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot()
const unpacked = protocol.unpack(buffer)
expect(() => unpacked instanceof structure.Structure).toThrowErrorMatchingSnapshot()
})

it.each([
Expand Down Expand Up @@ -439,8 +440,8 @@ describe('#unit BoltProtocolV4x1', () => {
],
[
'DateTimeWithZoneId',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo')
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao_Paulo')
]
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
const buffer = alloc(256)
Expand Down
11 changes: 6 additions & 5 deletions packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('#unit BoltProtocolV4x2', () => {
['Time', new Time(1, 1, 1, 1, 1)],
['Date', new Date(1, 1, 1)],
['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao_Paulo')],
['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)],
['Point2D', new Point(1, 1, 1)],
['Point3D', new Point(1, 1, 1, 1)]
Expand Down Expand Up @@ -376,7 +376,7 @@ describe('#unit BoltProtocolV4x2', () => {
],
[
'DateTimeWithZoneId with more fields',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil'])
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo', 'Brasil'])
]
])('should not unpack with wrong size (%s)', (_, struct) => {
const buffer = alloc(256)
Expand All @@ -392,7 +392,8 @@ describe('#unit BoltProtocolV4x2', () => {

buffer.reset()

expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot()
const unpacked = protocol.unpack(buffer)
expect(() => unpacked instanceof structure.Structure).toThrowErrorMatchingSnapshot()
})

it.each([
Expand Down Expand Up @@ -438,8 +439,8 @@ describe('#unit BoltProtocolV4x2', () => {
],
[
'DateTimeWithZoneId',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo')
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao_Paulo')
]
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
const buffer = alloc(256)
Expand Down
26 changes: 14 additions & 12 deletions packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ describe('#unit BoltProtocolV4x3', () => {
['Time', new Time(1, 1, 1, 1, 1)],
['Date', new Date(1, 1, 1)],
['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao_Paulo')],
['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)],
['Point2D', new Point(1, 1, 1)],
['Point3D', new Point(1, 1, 1, 1)]
Expand Down Expand Up @@ -589,7 +589,7 @@ describe('#unit BoltProtocolV4x3', () => {
],
[
'DateTimeWithZoneId with more fields',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil'])
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo', 'Brasil'])
]
])('should not unpack with wrong size (%s)', (_, struct) => {
const buffer = alloc(256)
Expand All @@ -605,7 +605,8 @@ describe('#unit BoltProtocolV4x3', () => {

buffer.reset()

expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot()
const unpacked = protocol.unpack(buffer)
expect(() => unpacked instanceof structure.Structure).toThrowErrorMatchingSnapshot()
})

it.each([
Expand Down Expand Up @@ -651,8 +652,8 @@ describe('#unit BoltProtocolV4x3', () => {
],
[
'DateTimeWithZoneId',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo')
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao_Paulo')
]
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
const buffer = alloc(256)
Expand Down Expand Up @@ -848,7 +849,7 @@ describe('#unit BoltProtocolV4x3', () => {
],
[
'DateTimeWithZoneId with more fields',
new structure.Structure(0x69, [1, 2, 'America/Sao Paulo', 'Brasil'])
new structure.Structure(0x69, [1, 2, 'America/Sao_Paulo', 'Brasil'])
]
])('should not unpack with wrong size (%s)', (_, struct) => {
const packable = protocol.packable(struct)
Expand All @@ -857,7 +858,8 @@ describe('#unit BoltProtocolV4x3', () => {

buffer.reset()

expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot()
const unpacked = protocol.unpack(buffer)
expect(() => unpacked instanceof structure.Structure).toThrowErrorMatchingSnapshot()
})

it.each([
Expand Down Expand Up @@ -900,7 +902,7 @@ describe('#unit BoltProtocolV4x3', () => {
],
[
'DateTimeWithZoneId/0x66',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo'])
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo'])
]
])('should unpack deprecated temporal types as unknown structs (%s)', (_, struct) => {
const packable = protocol.packable(struct)
Expand Down Expand Up @@ -948,7 +950,7 @@ describe('#unit BoltProtocolV4x3', () => {
],
[
'DateTimeWithZoneId/0x69',
new structure.Structure(0x69, [1, 2, 'America/Sao Paulo'])
new structure.Structure(0x69, [1, 2, 'America/Sao_Paulo'])
]
])('should unpack utc temporal types as unknown structs (%s)', (_, struct) => {
const packable = protocol.packable(struct)
Expand All @@ -969,8 +971,8 @@ describe('#unit BoltProtocolV4x3', () => {
],
[
'DateTimeWithZoneId',
new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo')
new structure.Structure(0x66, [1, 2, 'America/Sao_Paulo']),
new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao_Paulo')
]
])('should unpack temporal types without utc fix (%s)', (_, struct, object) => {
const packable = protocol.packable(struct)
Expand All @@ -984,7 +986,7 @@ describe('#unit BoltProtocolV4x3', () => {
})

it.each([
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')],
['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao_Paulo')],
['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)]
])('should pack temporal types (no utc) (%s)', (_, object) => {
const packable = protocol.packable(object)
Expand Down
Loading