Skip to content

Commit 20e9b87

Browse files
committed
Add test to see that <App /> acts on Kerberos if enabled
1 parent 68c59ed commit 20e9b87

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (c) 2002-2018 "Neo4j, Inc"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
/* global jest, test, expect */
22+
import React from 'react'
23+
import { render } from 'react-testing-library'
24+
import { App } from './App'
25+
import { buildConnectionCredentialsObject } from 'browser-components/DesktopIntegration/helpers'
26+
import { flushPromises } from 'services/utils'
27+
28+
jest.mock('../FeatureToggle/FeatureToggleProvider', () => {
29+
return ({ children }) => <div>{children}</div>
30+
})
31+
jest.mock('./styled', () => {
32+
const orig = require.requireActual('./styled')
33+
return {
34+
...orig,
35+
StyledApp: () => null
36+
}
37+
})
38+
39+
describe('App', () => {
40+
test('App loads', async () => {
41+
// Given
42+
const getKerberosTicket = jest.fn(() => Promise.resolve('xxx'))
43+
const desktopIntegrationPoint = getIntegrationPoint(true, getKerberosTicket)
44+
let connectionCreds = null
45+
const props = {
46+
desktopIntegrationPoint,
47+
setInitialConnectionData: async (
48+
graph,
49+
credentials,
50+
context,
51+
getKerberosTicket
52+
) => {
53+
connectionCreds = await buildConnectionCredentialsObject(
54+
context,
55+
{},
56+
getKerberosTicket
57+
)
58+
}
59+
}
60+
61+
// When
62+
render(<App {...props} />)
63+
64+
// Then
65+
await flushPromises()
66+
expect(connectionCreds).toMatchObject({
67+
authenticationMethod: 'KERBEROS',
68+
password: 'xxx'
69+
})
70+
expect(getKerberosTicket).toHaveBeenCalledTimes(1)
71+
})
72+
})
73+
74+
const getIntegrationPoint = (kerberosEnabled, getKerberosTicket) => {
75+
const context = Promise.resolve(getDesktopContext(kerberosEnabled))
76+
return {
77+
getKerberosTicket: getKerberosTicket,
78+
getContext: () => context
79+
}
80+
}
81+
82+
const getDesktopContext = (kerberosEnabled = false) => ({
83+
projects: [
84+
{
85+
graphs: [
86+
{
87+
status: 'ACTIVE',
88+
connection: {
89+
type: 'REMOTE',
90+
configuration: {
91+
authenticationMethods: {
92+
kerberos: {
93+
enabled: kerberosEnabled,
94+
servicePrincipal: 'KERBEROS'
95+
}
96+
},
97+
protocols: {
98+
bolt: {
99+
enabled: true,
100+
username: 'neo4j',
101+
password: 'password',
102+
tlsLevel: 'REQUIRED',
103+
url: `bolt://localhost:7687`
104+
},
105+
http: {
106+
enabled: true,
107+
username: 'neo4j',
108+
password: 'password',
109+
host: 'localhost',
110+
port: '7474'
111+
}
112+
}
113+
}
114+
}
115+
}
116+
]
117+
}
118+
]
119+
})

0 commit comments

Comments
 (0)