From e4c72a0b4035a8e1de85aca32cc474dfa6db4125 Mon Sep 17 00:00:00 2001 From: Oskar Hane Date: Fri, 5 Oct 2018 15:42:41 +0200 Subject: [PATCH 1/2] Use `url` field from Neo4j Desktop context if it exists New addition to Neo4j Desktop API (will be out in 1.1.11). Keeps backwards compatibility. Note that these URL:s can have the `bolt+routing` protocol. --- src/browser/modules/App/App.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browser/modules/App/App.jsx b/src/browser/modules/App/App.jsx index 720c39602ad..916cfed798e 100644 --- a/src/browser/modules/App/App.jsx +++ b/src/browser/modules/App/App.jsx @@ -193,7 +193,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { ...stateProps.defaultConnectionData, ...creds, encrypted: creds.tlsLevel === 'REQUIRED', - host: `bolt://${creds.host}:${creds.port}`, + host: creds.url || `bolt://${creds.host}:${creds.port}`, restApi } ownProps.bus.send(SWITCH_CONNECTION, connectionCreds) @@ -212,7 +212,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { ...stateProps.defaultConnectionData, ...creds, encrypted: creds.tlsLevel === 'REQUIRED', - host: `bolt://${creds.host}:${creds.port}`, + host: creds.url || `bolt://${creds.host}:${creds.port}`, restApi } ownProps.bus.send(INJECTED_DISCOVERY, connectionCreds) From d6d94e36f68888c827607e599fc5eddd8f067a2d Mon Sep 17 00:00:00 2001 From: Oskar Hane Date: Fri, 5 Oct 2018 18:13:43 +0200 Subject: [PATCH 2/2] Add e2e tests --- e2e_tests/integration/desktop-env-url.spec.js | 68 +++++++++++++++++++ e2e_tests/integration/desktop-env.spec.js | 49 +++---------- e2e_tests/support/utils.js | 42 ++++++++++++ 3 files changed, 119 insertions(+), 40 deletions(-) create mode 100644 e2e_tests/integration/desktop-env-url.spec.js create mode 100644 e2e_tests/support/utils.js diff --git a/e2e_tests/integration/desktop-env-url.spec.js b/e2e_tests/integration/desktop-env-url.spec.js new file mode 100644 index 00000000000..05f9c8f0cc1 --- /dev/null +++ b/e2e_tests/integration/desktop-env-url.spec.js @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2002-2018 "Neo4j, Inc" + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* global Cypress, cy, test, expect, before */ + +import { getDesktopContext } from '../support/utils' +let appContextListener + +// This file only esists to be able to test the auto connect using +// the host field. +// We can't load two times in the same file + +describe('Neo4j Desktop environment using url field', () => { + before(() => { + cy.visit(Cypress.config.url, { + onBeforeLoad: win => { + win.neo4jDesktopApi = { + getContext: () => + Promise.resolve(getDesktopContext(Cypress.config, 'url')), + onContextUpdate: fn => (appContextListener = fn.bind(fn)) + } + } + }) + }) + it('can auto connect using url field', () => { + const frames = cy.get('[data-test-id="frameCommand"]', { timeout: 10000 }) + frames.should('have.length', 2) + + // Auto connected = :play start + frames.first().should('contain', ':play start') + cy.wait(1000) + }) + it('switches connection when that event is triggered using url field', () => { + cy.executeCommand(':clear') + cy.wait(1000).then(() => { + appContextListener( + { type: 'GRAPH_ACTIVE', id: 'test' }, + getDesktopContext(Cypress.config, 'url') + ) + }) + + const frames = cy.get('[data-test-id="frameCommand"]', { timeout: 10000 }) + frames.should('have.length', 1) + + frames.first().should('contain', ':server switch success') + + cy.get('[data-test-id="frame"]', { timeout: 10000 }) + .first() + .should('contain', 'Connection updated') + }) +}) diff --git a/e2e_tests/integration/desktop-env.spec.js b/e2e_tests/integration/desktop-env.spec.js index 42fafdb7705..2c0a1086b1e 100644 --- a/e2e_tests/integration/desktop-env.spec.js +++ b/e2e_tests/integration/desktop-env.spec.js @@ -19,6 +19,7 @@ */ /* global Cypress, cy, test, expect, before */ +import { getDesktopContext } from '../support/utils' let appContextListener @@ -27,13 +28,14 @@ describe('Neo4j Desktop environment', () => { cy.visit(Cypress.config.url, { onBeforeLoad: win => { win.neo4jDesktopApi = { - getContext: () => Promise.resolve(getContext()), + getContext: () => + Promise.resolve(getDesktopContext(Cypress.config, 'url')), onContextUpdate: fn => (appContextListener = fn.bind(fn)) } } }) }) - it('can auto connect', () => { + it('can auto connect using host + post fields', () => { const frames = cy.get('[data-test-id="frameCommand"]', { timeout: 10000 }) frames.should('have.length', 2) @@ -41,10 +43,13 @@ describe('Neo4j Desktop environment', () => { frames.first().should('contain', ':play start') cy.wait(1000) }) - it('switches connection when that event is triggered', () => { + it('switches connection when that event is triggered using host + port fields', () => { cy.executeCommand(':clear') cy.wait(1000).then(() => { - appContextListener({ type: 'GRAPH_ACTIVE', id: 'test' }, getContext()) + appContextListener( + { type: 'GRAPH_ACTIVE', id: 'test' }, + getDesktopContext(Cypress.config, 'url') + ) }) const frames = cy.get('[data-test-id="frameCommand"]', { timeout: 10000 }) @@ -57,39 +62,3 @@ describe('Neo4j Desktop environment', () => { .should('contain', 'Connection updated') }) }) - -const getContext = () => ({ - projects: [ - { - graphs: [ - { - status: 'ACTIVE', - connection: { - type: 'REMOTE', - configuration: { - protocols: { - bolt: { - enabled: true, - username: 'neo4j', - password: Cypress.config.password, - host: Cypress.config.boltHost, - port: Cypress.config.boltPort, - tlsLevel: Cypress.config.url.startsWith('https') - ? 'REQUIRED' - : 'OPTIONAL' - }, - http: { - enabled: true, - username: 'neo4j', - password: Cypress.config.password, - host: 'localhost', - port: '7474' - } - } - } - } - } - ] - } - ] -}) diff --git a/e2e_tests/support/utils.js b/e2e_tests/support/utils.js new file mode 100644 index 00000000000..cfab7a3e6c7 --- /dev/null +++ b/e2e_tests/support/utils.js @@ -0,0 +1,42 @@ +export const getDesktopContext = (config, connectionCredsType = 'host') => ({ + projects: [ + { + graphs: [ + { + status: 'ACTIVE', + connection: { + type: 'REMOTE', + configuration: { + protocols: { + bolt: getBoltConfig(config, connectionCredsType), + http: { + enabled: true, + username: 'neo4j', + password: config.password, + host: 'localhost', + port: '7474' + } + } + } + } + } + ] + } + ] +}) + +const getBoltConfig = (config, type) => { + const obj = { + enabled: true, + username: 'neo4j', + password: config.password, + tlsLevel: config.url.startsWith('https') ? 'REQUIRED' : 'OPTIONAL' + } + if (type === 'url') { + obj.url = `bolt://${config.boltHost}:${config.boltPort}` + } else { + obj.host = config.boltHost + obj.port = config.boltPort + } + return obj +}