Skip to content

Commit ad79bb3

Browse files
Peter Wilhelmsson2hdddg
authored andcommitted
Makes it possible to run tests against a 4.0 database
Added environment variable to specify if encryption should be used or not when connecting to test database. 3.5 databases has encryption on by default, 4.0 defaults to off. Range of spatial y values changed, fix random range. Downgraded an error print to debug to avoid flooding the log (especially during tests).
1 parent c4301fa commit ad79bb3

File tree

10 files changed

+70
-28
lines changed

10 files changed

+70
-28
lines changed

neo4j/internal/bolt/bolt3.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,12 @@ func (b *bolt3) Next(shandle db.Handle) (*db.Record, *db.Summary, error) {
546546
return nil, sum, nil
547547
case *db.DatabaseError:
548548
b.state = bolt3_failed
549-
b.log.Error(b.logId, x)
549+
if x.IsClient() {
550+
// These could include potentially large cypher statement, only log to debug
551+
b.log.Debugf(b.logId, "%s", x)
552+
} else {
553+
b.log.Error(b.logId, x)
554+
}
550555
return nil, nil, x
551556
default:
552557
b.state = bolt3_dead

neo4j/test-integration/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var _ = Describe("Authentication", func() {
5353

5454
verifyConnect := func(token neo4j.AuthToken) func() {
5555
return func() {
56-
driver, err := neo4j.NewDriver(server.BoltURI(), token)
56+
driver, err := neo4j.NewDriver(server.BoltURI(), token, server.Config())
5757
Expect(err).To(BeNil())
5858
defer driver.Close()
5959

neo4j/test-integration/bookmark_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,8 @@ var _ = Describe("Bookmark", func() {
403403

404404
Expect(tx).To(BeNil())
405405
Expect(neo4j.IsTransientError(err)).To(BeTrue())
406-
//Expect(err).To(ContainMessage("Database not up to the requested version"))
407406
errDesc := err.Error()
408-
Expect(errDesc).To(ContainSubstring("Database not up to the requested version"))
407+
Expect(errDesc).To(ContainSubstring("not up to the requested version"))
409408
})
410409
})
411410

neo4j/test-integration/control/causal-cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func newCluster(path string) (*Cluster, error) {
156156

157157
authToken := neo4j.BasicAuth(username, password, "")
158158
config := func(config *neo4j.Config) {
159+
config.Encrypted = useEncryption()
159160
config.Log = neo4j.ConsoleLogger(logLevel())
160161
}
161162

neo4j/test-integration/control/constants.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
)
2727

2828
const (
29-
communityEdition = "community"
3029
enterpriseEdition = "enterprise"
3130

3231
defaultVersionAndEdition = "-e 3.5"

neo4j/test-integration/control/single-instance.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func newSingleInstance(path string) (*SingleInstance, error) {
9999

100100
authToken := neo4j.BasicAuth(username, password, "")
101101
config := func(config *neo4j.Config) {
102+
config.Encrypted = useEncryption()
102103
config.Log = neo4j.ConsoleLogger(logLevel())
103104
}
104105

neo4j/test-integration/control/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ func logLevel() neo4j.LogLevel {
6868
return defaultLogLevel
6969
}
7070

71+
func useEncryption() bool {
72+
// We will be able infer this by the URI scheme later on
73+
switch os.Getenv("NEOENCRYPTION") {
74+
case "False", "FALSE", "false":
75+
return false
76+
default:
77+
return true
78+
}
79+
}
80+
81+
func IsTlsEnabled() bool {
82+
return useEncryption()
83+
}
84+
7185
func resolveServerPath(isCluster bool) string {
7286
var serverPath = os.TempDir()
7387

neo4j/test-integration/examples_test.go

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ var _ = Describe("Examples", func() {
3636

3737
Context("Single Instance", func() {
3838
var (
39-
uri string
40-
username string
41-
password string
39+
uri string
40+
username string
41+
password string
42+
encrypted bool
4243
)
4344

4445
BeforeEach(func() {
@@ -52,10 +53,11 @@ var _ = Describe("Examples", func() {
5253
uri = singleInstance.BoltURI()
5354
username = singleInstance.Username()
5455
password = singleInstance.Password()
56+
encrypted = control.IsTlsEnabled()
5557
})
5658

5759
Specify("Hello World", func() {
58-
greeting, err := helloWorld(uri, username, password)
60+
greeting, err := helloWorld(uri, username, password, encrypted)
5961

6062
Expect(err).To(BeNil())
6163
Expect(greeting).To(ContainSubstring("hello, world"))
@@ -98,7 +100,7 @@ var _ = Describe("Examples", func() {
98100
})
99101

100102
Specify("Config - With Max Retry Time", func() {
101-
driver, err := createDriverWithMaxRetryTime(uri, username, password)
103+
driver, err := createDriverWithMaxRetryTime(uri, username, password, encrypted)
102104
Expect(err).To(BeNil())
103105
Expect(driver).NotTo(BeNil())
104106

@@ -139,7 +141,7 @@ var _ = Describe("Examples", func() {
139141
*/
140142

141143
Specify("Session", func() {
142-
driver, err := createDriverWithMaxRetryTime(uri, username, password)
144+
driver, err := createDriverWithMaxRetryTime(uri, username, password, encrypted)
143145
Expect(err).To(BeNil())
144146
Expect(driver).NotTo(BeNil())
145147
defer driver.Close()
@@ -152,7 +154,7 @@ var _ = Describe("Examples", func() {
152154
})
153155

154156
Specify("Autocommit Transaction", func() {
155-
driver, err := createDriverWithMaxRetryTime(uri, username, password)
157+
driver, err := createDriverWithMaxRetryTime(uri, username, password, encrypted)
156158
Expect(err).To(BeNil())
157159
Expect(driver).NotTo(BeNil())
158160
defer driver.Close()
@@ -165,7 +167,7 @@ var _ = Describe("Examples", func() {
165167
})
166168

167169
Specify("Pass Bookmarks", func() {
168-
driver, err := createDriverWithMaxRetryTime(uri, username, password)
170+
driver, err := createDriverWithMaxRetryTime(uri, username, password, encrypted)
169171
Expect(err).To(BeNil())
170172
Expect(driver).NotTo(BeNil())
171173
defer driver.Close()
@@ -191,7 +193,7 @@ var _ = Describe("Examples", func() {
191193
})
192194

193195
Specify("Read/Write Transaction", func() {
194-
driver, err := createDriverWithMaxRetryTime(uri, username, password)
196+
driver, err := createDriverWithMaxRetryTime(uri, username, password, encrypted)
195197
Expect(err).To(BeNil())
196198
Expect(driver).NotTo(BeNil())
197199
defer driver.Close()
@@ -202,7 +204,7 @@ var _ = Describe("Examples", func() {
202204
})
203205

204206
Specify("Get People", func() {
205-
driver, err := createDriverWithMaxRetryTime(uri, username, password)
207+
driver, err := createDriverWithMaxRetryTime(uri, username, password, encrypted)
206208
Expect(err).To(BeNil())
207209
Expect(driver).NotTo(BeNil())
208210
defer driver.Close()
@@ -222,7 +224,7 @@ var _ = Describe("Examples", func() {
222224
})
223225

224226
Specify("Result Retain", func() {
225-
driver, err := createDriverWithMaxRetryTime(uri, username, password)
227+
driver, err := createDriverWithMaxRetryTime(uri, username, password, encrypted)
226228
Expect(err).To(BeNil())
227229
Expect(driver).NotTo(BeNil())
228230
defer driver.Close()
@@ -243,10 +245,11 @@ var _ = Describe("Examples", func() {
243245

244246
Context("Causal Cluster", func() {
245247
var (
246-
err error
247-
cluster *control.Cluster
248-
username string
249-
password string
248+
err error
249+
cluster *control.Cluster
250+
username string
251+
password string
252+
encrypted bool
250253
)
251254

252255
BeforeEach(func() {
@@ -256,6 +259,7 @@ var _ = Describe("Examples", func() {
256259

257260
username = cluster.Username()
258261
password = cluster.Password()
262+
encrypted = control.IsTlsEnabled()
259263
})
260264

261265
Specify("Config - Address Resolver", func() {
@@ -264,7 +268,7 @@ var _ = Describe("Examples", func() {
264268
addresses = append(addresses, server.Address())
265269
}
266270

267-
driver, err := createDriverWithAddressResolver("bolt+routing://x.acme.com", username, password, addresses...)
271+
driver, err := createDriverWithAddressResolver("bolt+routing://x.acme.com", username, password, encrypted, addresses...)
268272
Expect(err).To(BeNil())
269273
Expect(driver).NotTo(BeNil())
270274

@@ -278,7 +282,7 @@ var _ = Describe("Examples", func() {
278282
})
279283

280284
// tag::hello-world[]
281-
func helloWorld(uri, username, password string) (string, error) {
285+
func helloWorld(uri, username, password string, encrypted bool) (string, error) {
282286
var (
283287
err error
284288
driver neo4j.Driver
@@ -287,7 +291,9 @@ func helloWorld(uri, username, password string) (string, error) {
287291
greeting interface{}
288292
)
289293

290-
driver, err = neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, ""))
294+
driver, err = neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, ""), func(c *neo4j.Config) {
295+
c.Encrypted = encrypted
296+
})
291297
if err != nil {
292298
return "", err
293299
}
@@ -374,7 +380,7 @@ func createDriverWithTrustStrategy(uri, username, password string) (neo4j.Driver
374380
// end::config-trust[]
375381

376382
// tag::config-custom-resolver[]
377-
func createDriverWithAddressResolver(virtualURI, username, password string, addresses ...neo4j.ServerAddress) (neo4j.Driver, error) {
383+
func createDriverWithAddressResolver(virtualURI, username, password string, encrypted bool, addresses ...neo4j.ServerAddress) (neo4j.Driver, error) {
378384
// Address resolver is only valid for bolt+routing uri
379385
return neo4j.NewDriver(virtualURI, neo4j.BasicAuth(username, password, ""), func(config *neo4j.Config) {
380386
config.AddressResolver = func(address neo4j.ServerAddress) []neo4j.ServerAddress {
@@ -383,6 +389,7 @@ func createDriverWithAddressResolver(virtualURI, username, password string, addr
383389
})
384390
}
385391

392+
/*
386393
func addPerson(name string) error {
387394
var (
388395
err error
@@ -420,6 +427,7 @@ func addPerson(name string) error {
420427
421428
return nil
422429
}
430+
*/
423431

424432
// end::config-custom-resolver[]
425433

@@ -444,9 +452,11 @@ func createDriverWithConnectionTimeout(uri, username, password string) (neo4j.Dr
444452
// end::config-connection-timeout[]
445453

446454
// tag::config-max-retry-time[]
447-
func createDriverWithMaxRetryTime(uri, username, password string) (neo4j.Driver, error) {
455+
// This driver is used to run queries, needs actual TLS configuration as well.
456+
func createDriverWithMaxRetryTime(uri, username, password string, encrypted bool) (neo4j.Driver, error) {
448457
return neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, ""), func(config *neo4j.Config) {
449458
config.MaxTransactionRetryTime = 15 * time.Second
459+
config.Encrypted = encrypted
450460
})
451461
}
452462

neo4j/test-integration/spatialtypes_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,15 @@ var _ = Describe("Spatial Types", func() {
134134
return float64(rand.Intn(360)-180) + rand.Float64()
135135
}
136136

137+
randomDoubleY := func() float64 {
138+
return float64(rand.Intn(180)-90) + rand.Float64()
139+
}
140+
137141
switch sequence % 4 {
138142
case 0:
139-
return neo4j.NewPoint2D(WGS84SrID, randomDouble(), randomDouble())
143+
return neo4j.NewPoint2D(WGS84SrID, randomDouble(), randomDoubleY())
140144
case 1:
141-
return neo4j.NewPoint3D(WGS843DSrID, randomDouble(), randomDouble(), randomDouble())
145+
return neo4j.NewPoint3D(WGS843DSrID, randomDouble(), randomDoubleY(), randomDouble())
142146
case 2:
143147
return neo4j.NewPoint2D(CartesianSrID, randomDouble(), randomDouble())
144148
case 3:
@@ -244,7 +248,7 @@ var _ = Describe("Spatial Types", func() {
244248

245249
It("should send and receive point", func() {
246250
testSendAndReceive(neo4j.NewPoint2D(WGS84SrID, 51.24923585, 0.92723724))
247-
testSendAndReceive(neo4j.NewPoint3D(WGS843DSrID, 22.86211019, 171.61820439, 0.1230987))
251+
testSendAndReceive(neo4j.NewPoint3D(WGS843DSrID, 22.86211019, 71.61820439, 0.1230987))
248252
testSendAndReceive(neo4j.NewPoint2D(CartesianSrID, 39.111748, -76.775635))
249253
testSendAndReceive(neo4j.NewPoint3D(Cartesian3DSrID, 39.111748, -76.775635, 19.2937302840))
250254
})

neo4j/test-integration/tls_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ var _ = Describe("Trust", func() {
3030
var err error
3131
var server *control.SingleInstance
3232

33+
// If the server isn't configured for TLS we cannot test this.
34+
if !control.IsTlsEnabled() {
35+
// Unable to skip here...
36+
//Skip("Can not test TLS trust on server with TLS disabled")
37+
return
38+
}
39+
3340
BeforeEach(func() {
3441
server, err = control.EnsureSingleInstance()
3542
Expect(err).To(BeNil())
@@ -45,6 +52,7 @@ var _ = Describe("Trust", func() {
4552

4653
driver, err = neo4j.NewDriver(uri, server.AuthToken(), server.Config(), func(config *neo4j.Config) {
4754
config.TrustStrategy = strategy
55+
config.Encrypted = true
4856
})
4957
Expect(err).To(BeNil())
5058
Expect(driver).NotTo(BeNil())
@@ -71,6 +79,7 @@ var _ = Describe("Trust", func() {
7179

7280
driver, err = neo4j.NewDriver(uri, server.AuthToken(), server.Config(), func(config *neo4j.Config) {
7381
config.TrustStrategy = strategy
82+
config.Encrypted = true
7483
})
7584
Expect(err).To(BeNil())
7685
Expect(driver).NotTo(BeNil())

0 commit comments

Comments
 (0)