Skip to content

Disable secure connection warning when the window.protocol is not available #664

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
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
4 changes: 3 additions & 1 deletion src/internal/browser/browser-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ function isProtocolSecure (protocolSupplier) {
}

function verifyEncryptionSettings (encryptionOn, encryptionOff, secureProtocol) {
if (encryptionOn && !secureProtocol) {
if (secureProtocol === null) {
// do nothing sice the protocol could not be identified
} else if (encryptionOn && !secureProtocol) {
// encryption explicitly turned on for a driver used on a HTTP web page
console.warn(
'Neo4j driver is configured to use secure WebSocket on a HTTP web page. ' +
Expand Down
28 changes: 25 additions & 3 deletions test/internal/browser/browser-channel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ describe('#unit WebSocketChannel', () => {
testWarningInMixedEnvironment(ENCRYPTION_OFF, 'https')
})

it('should generate not warning when encryption turned and the protocol could not be fetched', () => {
testWarningInMixedEnvironment(true, null, warnMessages =>
expect(warnMessages.length).toBe(0)
)
testWarningInMixedEnvironment(ENCRYPTION_ON, null, warnMessages =>
expect(warnMessages.length).toBe(0)
)
})

it('should generate a warning when encryption turned off and the protocol could not be fetched', () => {
testWarningInMixedEnvironment(false, null, warnMessages =>
expect(warnMessages.length).toBe(0)
)
testWarningInMixedEnvironment(ENCRYPTION_OFF, null, warnMessages =>
expect(warnMessages.length).toBe(0)
)
})

it('should resolve close if websocket is already closed', async () => {
const address = ServerAddress.fromUrl('bolt://localhost:8989')
const channelConfig = new ChannelConfig(address, {}, SERVICE_UNAVAILABLE)
Expand Down Expand Up @@ -216,7 +234,11 @@ describe('#unit WebSocketChannel', () => {
expect(channel._ws.url).toEqual(expectedScheme + '://localhost:8989')
}

function testWarningInMixedEnvironment (encrypted, scheme) {
function testWarningInMixedEnvironment (
encrypted,
scheme,
assertWarnMessage = warnMessages => expect(warnMessages.length).toEqual(1)
) {
const originalConsoleWarn = console.warn
try {
// replace console.warn with a function that memorizes the message
Expand All @@ -229,7 +251,7 @@ describe('#unit WebSocketChannel', () => {
{ encrypted: encrypted },
SERVICE_UNAVAILABLE
)
const protocolSupplier = () => scheme + ':'
const protocolSupplier = () => (scheme != null ? scheme + ':' : scheme)

const channel = new WebSocketChannel(
config,
Expand All @@ -238,7 +260,7 @@ describe('#unit WebSocketChannel', () => {
)

expect(channel).toBeDefined()
expect(warnMessages.length).toEqual(1)
assertWarnMessage(warnMessages)
} finally {
console.warn = originalConsoleWarn
}
Expand Down