Skip to content

Commit 88c998d

Browse files
authored
feat(connect-form): Add new form kerberos options COMPASS-5500 (#2794)
* wip: canonicalize hostname select * fix name attribute * add test for canonicalize hostname * use test ids instead of labels * add tests for password input * cleanup * undo select bump * default to none * fix test
1 parent 0092996 commit 88c998d

File tree

5 files changed

+232
-45
lines changed

5 files changed

+232
-45
lines changed

packages/compass-components/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export { default as Modal } from '@leafygreen-ui/modal';
4646
export { uiColors } from '@leafygreen-ui/palette';
4747
export * as compassUIColors from './compass-ui-colors';
4848
export { default as Portal } from '@leafygreen-ui/portal';
49-
export { RadioBox, RadioBoxGroup } from '@leafygreen-ui/radio-box-group';
49+
export {
50+
RadioBox,
51+
RadioBoxGroup,
52+
Size as RadioBoxSize,
53+
} from '@leafygreen-ui/radio-box-group';
5054
export { Radio, RadioGroup } from '@leafygreen-ui/radio-group';
5155
export {
5256
Select,

packages/connection-form/src/components/advanced-options-tabs/authentication-tab/authentication-default.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ function AuthenticationDefault({
167167
<RadioBoxGroup
168168
onChange={onAuthMechanismSelected}
169169
id="authentication-mechanism-radio-box-group"
170-
size="default"
171170
value={selectedAuthTab.value}
172171
>
173172
{defaultAuthMechanismOptions.map(({ title, value }) => {
@@ -177,7 +176,6 @@ function AuthenticationDefault({
177176
checked={selectedAuthTab.value === value}
178177
value={value}
179178
key={value}
180-
size="default"
181179
>
182180
{title}
183181
</RadioBox>

packages/connection-form/src/components/advanced-options-tabs/authentication-tab/authentication-gssapi.spec.tsx

Lines changed: 125 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import React from 'react';
2-
import { render, screen, fireEvent } from '@testing-library/react';
2+
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
33
import { expect } from 'chai';
44
import sinon from 'sinon';
55
import ConnectionStringUrl from 'mongodb-connection-string-url';
66

7-
import AuthenticationGssapi, {
8-
GSSAPI_CANONICALIZE_HOST_NAME_LABEL,
9-
GSSAPI_PRINCIPAL_NAME_LABEL,
10-
GSSAPI_SERVICE_NAME_LABEL,
11-
GSSAPI_SERVICE_REALM_LABEL,
12-
} from './authentication-gssapi';
7+
import AuthenticationGssapi from './authentication-gssapi';
138
import type { ConnectionFormError } from '../../../utils/validation';
149
import type { UpdateConnectionFormField } from '../../../hooks/use-connect-form';
1510

@@ -32,6 +27,8 @@ function renderComponent({
3227
}
3328

3429
describe('AuthenticationGssapi Component', function () {
30+
afterEach(cleanup);
31+
3532
let updateConnectionFormFieldSpy: sinon.SinonSpy;
3633
beforeEach(function () {
3734
updateConnectionFormFieldSpy = sinon.spy();
@@ -44,7 +41,7 @@ describe('AuthenticationGssapi Component', function () {
4441
});
4542
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);
4643

47-
fireEvent.change(screen.getByLabelText(GSSAPI_PRINCIPAL_NAME_LABEL), {
44+
fireEvent.change(screen.getByTestId('gssapi-principal-input'), {
4845
target: { value: 'good sandwich' },
4946
});
5047
});
@@ -65,7 +62,7 @@ describe('AuthenticationGssapi Component', function () {
6562
});
6663
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);
6764

68-
fireEvent.change(screen.getByLabelText(GSSAPI_SERVICE_NAME_LABEL), {
65+
fireEvent.change(screen.getByTestId('gssapi-service-name-input'), {
6966
target: { value: 'good sandwich' },
7067
});
7168
});
@@ -87,7 +84,7 @@ describe('AuthenticationGssapi Component', function () {
8784
});
8885
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);
8986

90-
fireEvent.change(screen.getByLabelText(GSSAPI_SERVICE_REALM_LABEL), {
87+
fireEvent.change(screen.getByTestId('gssapi-service-realm-input'), {
9188
target: { value: 'good sandwich' },
9289
});
9390
});
@@ -102,25 +99,136 @@ describe('AuthenticationGssapi Component', function () {
10299
});
103100
});
104101

105-
describe('when the canoncalize hostname is changed', function () {
102+
describe('when canoncalize hostname is empty', function () {
106103
beforeEach(function () {
107104
renderComponent({
108105
updateConnectionFormField: updateConnectionFormFieldSpy,
109106
});
110107

111108
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);
112-
const checkbox = screen.getByLabelText(
113-
GSSAPI_CANONICALIZE_HOST_NAME_LABEL
109+
});
110+
111+
it('selects None', function () {
112+
const radio = screen
113+
.getByTestId('gssapi-canonicalize-host-name-none')
114+
.closest('input');
115+
116+
expect(radio.checked).to.be.true;
117+
});
118+
119+
it('updates the form field with CANONICALIZE_HOST_NAME forward', function () {
120+
const button = screen.getByTestId(
121+
'gssapi-canonicalize-host-name-forward'
114122
);
115-
fireEvent.click(checkbox);
123+
fireEvent.click(button);
124+
125+
expect(updateConnectionFormFieldSpy.callCount).to.equal(1);
126+
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
127+
key: 'CANONICALIZE_HOST_NAME',
128+
type: 'update-auth-mechanism-property',
129+
value: 'forward',
130+
});
116131
});
117132

118-
it('calls to update the form field', function () {
133+
it('updates the form field with CANONICALIZE_HOST_NAME forwardAndReverse', function () {
134+
const button = screen.getByTestId(
135+
'gssapi-canonicalize-host-name-forwardAndReverse'
136+
);
137+
fireEvent.click(button);
138+
139+
expect(updateConnectionFormFieldSpy.callCount).to.equal(1);
140+
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
141+
key: 'CANONICALIZE_HOST_NAME',
142+
type: 'update-auth-mechanism-property',
143+
value: 'forwardAndReverse',
144+
});
145+
});
146+
});
147+
148+
describe('when canoncalize hostname is set', function () {
149+
beforeEach(function () {
150+
renderComponent({
151+
updateConnectionFormField: updateConnectionFormFieldSpy,
152+
connectionStringUrl: new ConnectionStringUrl(
153+
'mongodb://localhost:27017/?authMechanism=GSSAPI&authSource=%24external&authMechanismProperties=CANONICALIZE_HOST_NAME%3Aforward'
154+
),
155+
});
156+
157+
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);
158+
});
159+
160+
it('resets CANONICALIZE_HOST_NAME when None is selected', function () {
161+
const button = screen.getByTestId('gssapi-canonicalize-host-name-none');
162+
fireEvent.click(button);
163+
119164
expect(updateConnectionFormFieldSpy.callCount).to.equal(1);
120165
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
121166
key: 'CANONICALIZE_HOST_NAME',
122167
type: 'update-auth-mechanism-property',
123-
value: 'true',
168+
value: '',
169+
});
170+
});
171+
});
172+
173+
describe('when password is not in the connection string', function () {
174+
beforeEach(function () {
175+
renderComponent({
176+
updateConnectionFormField: updateConnectionFormFieldSpy,
177+
});
178+
179+
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);
180+
});
181+
182+
it('allows to edit the password when enter password directly is enabled', function () {
183+
expect(screen.queryByTestId('gssapi-password-input')).to.not.exist;
184+
const checkbox = screen.getByTestId('gssapi-password-checkbox');
185+
expect(checkbox.closest('input').checked).to.be.false;
186+
187+
fireEvent.click(checkbox);
188+
189+
const passwordInput = screen.getByTestId('gssapi-password-input');
190+
191+
fireEvent.change(passwordInput, {
192+
target: { value: 'some-password' },
193+
});
194+
195+
expect(updateConnectionFormFieldSpy.callCount).to.equal(1);
196+
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
197+
type: 'update-password',
198+
password: 'some-password',
199+
});
200+
});
201+
});
202+
203+
describe('when password is in the connection string', function () {
204+
beforeEach(function () {
205+
renderComponent({
206+
connectionStringUrl: new ConnectionStringUrl(
207+
'mongodb://user:password@localhost:27017'
208+
),
209+
updateConnectionFormField: updateConnectionFormFieldSpy,
210+
});
211+
212+
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);
213+
});
214+
215+
it('enables the checkbox and shows the password input', function () {
216+
const checkbox = screen.getByTestId('gssapi-password-checkbox');
217+
expect(checkbox.closest('input').checked).to.be.true;
218+
const passwordInput = screen.queryByTestId('gssapi-password-input');
219+
expect(passwordInput).to.exist;
220+
expect(passwordInput.closest('input').value).to.equal('password');
221+
});
222+
223+
it('resets the password when the checkbox is unchecked', function () {
224+
const checkbox = screen.getByTestId('gssapi-password-checkbox');
225+
expect(checkbox.closest('input').checked).to.be.true;
226+
fireEvent.click(checkbox);
227+
228+
expect(updateConnectionFormFieldSpy.callCount).to.equal(1);
229+
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
230+
type: 'update-password',
231+
password: '',
124232
});
125233
});
126234
});
@@ -129,6 +237,7 @@ describe('AuthenticationGssapi Component', function () {
129237
renderComponent({
130238
errors: [
131239
{
240+
fieldTab: 'authentication',
132241
fieldName: 'kerberosPrincipal',
133242
message: 'kerberosPrincipal error',
134243
},

0 commit comments

Comments
 (0)