Skip to content

Commit e812705

Browse files
committed
Disable secure connection warning when the window.protocol is not available (#664)
The window.location is not available in the WebWorkers contexts and because of the driver keeps wrongly warning about a misconfiguration. If the information location protocol is not available, the driver should not warning.
1 parent 06aed3d commit e812705

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/internal/browser/browser-channel.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ function isProtocolSecure (protocolSupplier) {
323323
}
324324

325325
function verifyEncryptionSettings (encryptionOn, encryptionOff, secureProtocol) {
326-
if (encryptionOn && !secureProtocol) {
326+
if (secureProtocol === null) {
327+
// do nothing sice the protocol could not be identified
328+
} else if (encryptionOn && !secureProtocol) {
327329
// encryption explicitly turned on for a driver used on a HTTP web page
328330
console.warn(
329331
'Neo4j driver is configured to use secure WebSocket on a HTTP web page. ' +

test/internal/browser/browser-channel.test.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ describe('#unit WebSocketChannel', () => {
142142
testWarningInMixedEnvironment(ENCRYPTION_OFF, 'https')
143143
})
144144

145+
it('should generate not warning when encryption turned and the protocol could not be fetched', () => {
146+
testWarningInMixedEnvironment(true, null, warnMessages =>
147+
expect(warnMessages.length).toBe(0)
148+
)
149+
testWarningInMixedEnvironment(ENCRYPTION_ON, null, warnMessages =>
150+
expect(warnMessages.length).toBe(0)
151+
)
152+
})
153+
154+
it('should generate a warning when encryption turned off and the protocol could not be fetched', () => {
155+
testWarningInMixedEnvironment(false, null, warnMessages =>
156+
expect(warnMessages.length).toBe(0)
157+
)
158+
testWarningInMixedEnvironment(ENCRYPTION_OFF, null, warnMessages =>
159+
expect(warnMessages.length).toBe(0)
160+
)
161+
})
162+
145163
it('should resolve close if websocket is already closed', async () => {
146164
const address = ServerAddress.fromUrl('bolt://localhost:8989')
147165
const channelConfig = new ChannelConfig(address, {}, SERVICE_UNAVAILABLE)
@@ -216,7 +234,11 @@ describe('#unit WebSocketChannel', () => {
216234
expect(channel._ws.url).toEqual(expectedScheme + '://localhost:8989')
217235
}
218236

219-
function testWarningInMixedEnvironment (encrypted, scheme) {
237+
function testWarningInMixedEnvironment (
238+
encrypted,
239+
scheme,
240+
assertWarnMessage = warnMessages => expect(warnMessages.length).toEqual(1)
241+
) {
220242
const originalConsoleWarn = console.warn
221243
try {
222244
// replace console.warn with a function that memorizes the message
@@ -229,7 +251,7 @@ describe('#unit WebSocketChannel', () => {
229251
{ encrypted: encrypted },
230252
SERVICE_UNAVAILABLE
231253
)
232-
const protocolSupplier = () => scheme + ':'
254+
const protocolSupplier = () => (scheme != null ? scheme + ':' : scheme)
233255

234256
const channel = new WebSocketChannel(
235257
config,
@@ -238,7 +260,7 @@ describe('#unit WebSocketChannel', () => {
238260
)
239261

240262
expect(channel).toBeDefined()
241-
expect(warnMessages.length).toEqual(1)
263+
assertWarnMessage(warnMessages)
242264
} finally {
243265
console.warn = originalConsoleWarn
244266
}

0 commit comments

Comments
 (0)