Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"packages-version": "lerna version --allow-branch main --no-push --no-private -m \"chore(release): Bump package versions\"",
"release": "npm run release --workspace mongodb-compass --",
"reformat": "lerna run reformat --stream --no-bail",
"reformat-changed": "lerna run reformat --stream --no-bail --since origin/HEAD --exclude-dependents",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

"package-compass": "npm run package-compass --workspace=mongodb-compass --",
"prestart": "npm run compile --workspace=@mongodb-js/webpack-config-compass",
"start": "npm run start --workspace=mongodb-compass",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function AdvancedTab({
: pathname;

const handleFieldChanged = useCallback(
(key: keyof MongoClientOptions, value: unknown) => {
(key: keyof MongoClientOptions, value?: string) => {
if (!value) {
return updateConnectionFormField({
type: 'delete-search-param',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ describe('AuthenticationDefault Component', function () {
it('decodes the password as a uri component before rendering', function () {
renderComponent({
connectionStringUrl: new ConnectionStringUrl(
'mongodb://C%3BIb86n5b8%7BAnExew%5BTU%25XZy%2C)E6G!dk:password@outerspace:12345'
'mongodb://username:C%3BIb86n5b8%7BAnExew%5BTU%25XZy%2C)E6G!dk@outerspace:12345'
),
updateConnectionFormField: updateConnectionFormFieldSpy,
});

expect(screen.getByLabelText('Username').getAttribute('value')).to.equal(
expect(screen.getByLabelText('Password').getAttribute('value')).to.equal(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks for catching.

'C;Ib86n5b8{AnExew[TU%XZy,)E6G!dk'
);
});
Expand All @@ -171,12 +171,26 @@ describe('AuthenticationDefault Component', function () {
errors: [
{
fieldName: 'username',
message: 'pineapples',
message: 'username error',
},
],
updateConnectionFormField: updateConnectionFormFieldSpy,
});

expect(screen.getByText('username error')).to.be.visible;
});

it('renders a password error when there is a password error', function () {
renderComponent({
errors: [
{
fieldName: 'password',
message: 'password error',
},
],
updateConnectionFormField: updateConnectionFormFieldSpy,
});

expect(screen.getByText('pineapples')).to.be.visible;
expect(screen.getByText('password error')).to.be.visible;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ import { AuthMechanism } from 'mongodb';

import { UpdateConnectionFormField } from '../../../hooks/use-connect-form';
import FormFieldContainer from '../../form-field-container';
import { ConnectionFormError } from '../../../utils/validation';
import {
ConnectionFormError,
errorMessageByFieldName,
} from '../../../utils/validation';
import {
getConnectionStringPassword,
getConnectionStringUsername,
} from '../../../utils/connection-string-helpers';

const authSourceLabelStyles = css({
padding: 0,
Expand Down Expand Up @@ -54,8 +61,8 @@ function AuthenticationDefault({
errors: ConnectionFormError[];
updateConnectionFormField: UpdateConnectionFormField;
}): React.ReactElement {
const password = decodeURIComponent(connectionStringUrl.password);
const username = decodeURIComponent(connectionStringUrl.username);
const password = getConnectionStringPassword(connectionStringUrl);
const username = getConnectionStringUsername(connectionStringUrl);

const selectedAuthMechanism =
connectionStringUrl.searchParams.get('authMechanism') ?? '';
Expand All @@ -76,7 +83,8 @@ function AuthenticationDefault({
[updateConnectionFormField]
);

const usernameError = errors?.find((error) => error.fieldName === 'username');
const usernameError = errorMessageByFieldName(errors, 'username');
const passwordError = errorMessageByFieldName(errors, 'password');

return (
<>
Expand All @@ -91,7 +99,7 @@ function AuthenticationDefault({
});
}}
label="Username"
errorMessage={usernameError?.message}
errorMessage={usernameError}
state={usernameError ? 'error' : undefined}
value={username || ''}
/>
Expand All @@ -109,6 +117,8 @@ function AuthenticationDefault({
label="Password"
type="password"
value={password || ''}
errorMessage={passwordError}
state={passwordError ? 'error' : undefined}
/>
</FormFieldContainer>
<FormFieldContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { expect } from 'chai';
import sinon from 'sinon';
import ConnectionStringUrl from 'mongodb-connection-string-url';

import AuthenticationGssapi from './authentication-gssapi';
import { ConnectionFormError } from '../../../utils/validation';
import { UpdateConnectionFormField } from '../../../hooks/use-connect-form';

function renderComponent({
errors = [],
connectionStringUrl = new ConnectionStringUrl('mongodb://localhost:27017'),
updateConnectionFormField,
}: {
connectionStringUrl?: ConnectionStringUrl;
errors?: ConnectionFormError[];
updateConnectionFormField: UpdateConnectionFormField;
}) {
render(
<AuthenticationGssapi
errors={errors}
connectionStringUrl={connectionStringUrl}
updateConnectionFormField={updateConnectionFormField}
/>
);
}

describe('AuthenticationGssapi Component', function () {
let updateConnectionFormFieldSpy: sinon.SinonSpy;
beforeEach(function () {
updateConnectionFormFieldSpy = sinon.spy();
});

describe('when the kerberosPrincipal input is changed', function () {
beforeEach(function () {
renderComponent({
updateConnectionFormField: updateConnectionFormFieldSpy,
});
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);

fireEvent.change(screen.getByLabelText('Principal'), {
target: { value: 'good sandwich' },
});
});

it('calls to update the form field', function () {
expect(updateConnectionFormFieldSpy.callCount).to.equal(1);
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
type: 'update-username',
username: 'good sandwich',
});
});
});

describe('when the serviceName input is changed', function () {
beforeEach(function () {
renderComponent({
updateConnectionFormField: updateConnectionFormFieldSpy,
});
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);

fireEvent.change(screen.getByLabelText('Service Name'), {
target: { value: 'good sandwich' },
});
});

it('calls to update the form field', function () {
expect(updateConnectionFormFieldSpy.callCount).to.equal(1);
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
key: 'SERVICE_NAME',
type: 'update-auth-mechanism-property',
value: 'good sandwich',
});
});
});

describe('when the serviceRealm input is changed', function () {
beforeEach(function () {
renderComponent({
updateConnectionFormField: updateConnectionFormFieldSpy,
});
expect(updateConnectionFormFieldSpy.callCount).to.equal(0);

fireEvent.change(screen.getByLabelText('Service Realm'), {
target: { value: 'good sandwich' },
});
});

it('calls to update the form field', function () {
expect(updateConnectionFormFieldSpy.callCount).to.equal(1);
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
key: 'SERVICE_REALM',
type: 'update-auth-mechanism-property',
value: 'good sandwich',
});
});
});

describe('when the canoncalize hostname is changed', function () {
beforeEach(function () {
renderComponent({
updateConnectionFormField: updateConnectionFormFieldSpy,
});

expect(updateConnectionFormFieldSpy.callCount).to.equal(0);
const checkbox = screen.getByLabelText('Canonicalize Host Name');
fireEvent.click(checkbox);
});

it('calls to update the form field', function () {
expect(updateConnectionFormFieldSpy.callCount).to.equal(1);
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
key: 'CANONICALIZE_HOST_NAME',
type: 'update-auth-mechanism-property',
value: 'true',
});
});
});

it('renders an error when there is a kerberosPrincipal error', function () {
renderComponent({
errors: [
{
fieldName: 'kerberosPrincipal',
message: 'kerberosPrincipal error',
},
],
updateConnectionFormField: updateConnectionFormFieldSpy,
});

expect(screen.getByText('kerberosPrincipal error')).to.be.visible;
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,105 @@
import React from 'react';
import { Checkbox, TextInput } from '@mongodb-js/compass-components';

import ConnectionStringUrl from 'mongodb-connection-string-url';
import { UpdateConnectionFormField } from '../../../hooks/use-connect-form';
import FormFieldContainer from '../../form-field-container';
import {
ConnectionFormError,
errorMessageByFieldName,
} from '../../../utils/validation';
import {
getConnectionStringUsername,
parseAuthMechanismProperties,
} from '../../../utils/connection-string-helpers';

function AuthenticationGSSAPI({
errors,
connectionStringUrl,
updateConnectionFormField,
}: {
connectionStringUrl: ConnectionStringUrl;
errors: ConnectionFormError[];
updateConnectionFormField: UpdateConnectionFormField;
}): React.ReactElement {
const kerberosPrincipalError = errorMessageByFieldName(
errors,
'kerberosPrincipal'
);
const principal = getConnectionStringUsername(connectionStringUrl);
const authMechanismProperties =
parseAuthMechanismProperties(connectionStringUrl);
const serviceName = authMechanismProperties.get('SERVICE_NAME');
const serviceRealm = authMechanismProperties.get('SERVICE_REALM');
const canonicalizeHostname = authMechanismProperties.get(
'CANONICALIZE_HOST_NAME'
);

function AuthenticationGSSAPI(): React.ReactElement {
return (
<>
<p>Kerberos</p>
<FormFieldContainer>
<TextInput
onChange={({
target: { value },
}: React.ChangeEvent<HTMLInputElement>) => {
updateConnectionFormField({
type: 'update-username',
username: value,
});
}}
label="Principal"
errorMessage={kerberosPrincipalError}
state={kerberosPrincipalError ? 'error' : undefined}
value={principal || ''}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we had an info link to https://docs.mongodb.com/manual/core/kerberos/#principals
on this input:
Screen Shot 2022-01-25 at 3 57 22 PM
Do we want to keep it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's a good one, yeah, i'll merge this and add it right away

/>
</FormFieldContainer>

<FormFieldContainer>
<TextInput
onChange={({
target: { value },
}: React.ChangeEvent<HTMLInputElement>) => {
updateConnectionFormField({
type: 'update-auth-mechanism-property',
key: 'SERVICE_NAME',
value: value,
});
}}
label="Service Name"
value={serviceName || ''}
/>
</FormFieldContainer>

<FormFieldContainer>
<Checkbox
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
updateConnectionFormField({
type: 'update-auth-mechanism-property',
key: 'CANONICALIZE_HOST_NAME',
value: event.target.checked ? 'true' : '',
});
}}
label="Canonicalize Host Name"
checked={canonicalizeHostname === 'true'}
bold={false}
/>
</FormFieldContainer>

<FormFieldContainer>
<TextInput
onChange={({
target: { value },
}: React.ChangeEvent<HTMLInputElement>) => {
updateConnectionFormField({
type: 'update-auth-mechanism-property',
key: 'SERVICE_REALM',
value: value,
});
}}
label="Service Realm"
value={serviceRealm || ''}
/>
</FormFieldContainer>
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('DirectConnectionInput', function () {
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
type: 'update-search-param',
currentKey: 'directConnection',
value: true,
value: 'true',
});
});
});
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('DirectConnectionInput', function () {
expect(updateConnectionFormFieldSpy.firstCall.args[0]).to.deep.equal({
type: 'update-search-param',
currentKey: 'directConnection',
value: true,
value: 'true',
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function DirectConnectionInput({
return updateConnectionFormField({
type: 'update-search-param',
currentKey: 'directConnection',
value: event.target.checked,
value: event.target.checked ? 'true' : 'false',
});
},
[updateConnectionFormField]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function Socks({
connectionStringUrl.typedSearchParams<MongoClientOptions>();

const handleFieldChanged = useCallback(
(key: keyof MongoClientOptions, value: unknown) => {
(key: keyof MongoClientOptions, value?: string) => {
if (!value) {
return updateConnectionFormField({
type: 'delete-search-param',
Expand Down
Loading