Skip to content

Commit

Permalink
feat(deploy): add port validation to contactPoint field
Browse files Browse the repository at this point in the history
Closes #2863
  • Loading branch information
smbea committed Mar 31, 2022
1 parent 1d35144 commit 60b3646
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export default class DeploymentPlugin extends PureComponent {
id: generateId(),
targetType: CAMUNDA_CLOUD,
authType: AUTH_TYPES.NONE,
contactPoint: '0.0.0.0:26500',
contactPoint: '',
oauthURL: '',
audience: '',
clientId: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const SELF_HOSTED_TEXT = 'Camunda Platform 8 Self-Managed';
export const OAUTH_TEXT = 'OAuth';
export const NONE = 'None';
export const CAMUNDA_CLOUD_TEXT = 'Camunda Platform 8 SaaS';
export const CONTACT_POINT = 'Contact Point';
export const CONTACT_POINT = 'Cluster endpoint';
export const DEPLOYMENT_NAME_HINT = 'Default value is the file name.';
export const CONTACT_POINT_HINT = 'Default value is 0.0.0.0:26500';
export const CONTACT_POINT_HINT = '0.0.0.0:26500';
export const OAUTH_URL = 'OAuth URL';
export const AUDIENCE = 'Audience';
export const CLIENT_ID = 'Client ID';
Expand All @@ -31,6 +31,7 @@ export const REMEMBER_CREDENTIALS = 'Remember credentials';

export const MUST_PROVIDE_A_VALUE = 'Must provide a value.';
export const CONTACT_POINT_MUST_NOT_BE_EMPTY = 'Contact point must not be empty.';
export const CONTACT_POINT_MUST_HAVE_VALID_PORT = 'Contact point must contain a valid port.';
export const OAUTH_URL_MUST_NOT_BE_EMPTY = 'OAuth URL must not be empty.';
export const AUDIENCE_MUST_NOT_BE_EMPTY = 'Audience must not be empty.';
export const CLIENT_ID_MUST_NOT_BE_EMPTY = 'Client ID must not be empty.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export default class DeploymentPluginOverlay extends React.PureComponent {
name="endpoint.contactPoint"
component={ TextInput }
label={ CONTACT_POINT }
validate={ validatorFunctionsByFieldNames.contactPoint }
fieldError={ this.endpointConfigurationFieldError }
hint={ CONTACT_POINT_HINT }
autoFocus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
AUDIENCE_MUST_NOT_BE_EMPTY,
CLIENT_ID_MUST_NOT_BE_EMPTY,
CLIENT_SECRET_MUST_NOT_BE_EMPTY,
CLUSTER_URL_MUST_BE_VALID_CLOUD_URL
CLUSTER_URL_MUST_BE_VALID_CLOUD_URL,
CONTACT_POINT_MUST_HAVE_VALID_PORT
} from './DeploymentPluginConstants';

import { AUTH_TYPES } from '../shared/ZeebeAuthTypes';
Expand Down Expand Up @@ -43,8 +44,19 @@ export default class DeploymentPluginValidator {
return validCloudUrl(value) ? null : message;
}

validateAddressPort = (value, message) => {
var parts = value.split(':');
var port = parseInt(parts[parts.length - 1]);

if (!port || port < 1 || port > 65535) {
return message;
}

return null;
}

validateZeebeContactPoint = (value) => {
return this.validateNonEmpty(value, CONTACT_POINT_MUST_NOT_BE_EMPTY);
return this.validateNonEmpty(value, CONTACT_POINT_MUST_NOT_BE_EMPTY) || this.validateAddressPort(value, CONTACT_POINT_MUST_HAVE_VALID_PORT);
}

validateOAuthURL = (value) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
CLIENT_ID_MUST_NOT_BE_EMPTY,
CLIENT_SECRET_MUST_NOT_BE_EMPTY,
CLUSTER_URL_MUST_BE_VALID_CLOUD_URL,
CONTACT_POINT_MUST_HAVE_VALID_PORT,
} from '../DeploymentPluginConstants';


Expand All @@ -31,11 +32,13 @@ describe('<DeploymentPluginValidator> (Zeebe)', () => {
it('should validate Zeebe contact point', () => {

// given
const nonValidZeebeContactPoint = '';
const validZeebeContactPoint = 'validZeebeContactPoint';
const emptyZeebeContactPoint = '';
const noPortZeebeContactPoint = 'validZeebeContactPoint';
const validZeebeContactPoint = 'validZeebeContactPoint:0001';

// then
expect(validator.validateZeebeContactPoint(nonValidZeebeContactPoint)).to.eql(CONTACT_POINT_MUST_NOT_BE_EMPTY);
expect(validator.validateZeebeContactPoint(emptyZeebeContactPoint)).to.eql(CONTACT_POINT_MUST_NOT_BE_EMPTY);
expect(validator.validateZeebeContactPoint(noPortZeebeContactPoint)).to.eql(CONTACT_POINT_MUST_HAVE_VALID_PORT);
expect(validator.validateZeebeContactPoint(validZeebeContactPoint)).to.not.exist;
});

Expand Down Expand Up @@ -152,7 +155,7 @@ describe('<DeploymentPluginValidator> (Zeebe)', () => {
endpoint: {
targetType: 'selfHosted',
authType: 'none',
contactPoint: 'https://camunda.com'
contactPoint: 'https://camunda.com:0001'
}
};

Expand All @@ -167,7 +170,7 @@ describe('<DeploymentPluginValidator> (Zeebe)', () => {

// then
expect(Object.keys(validator.validateConfig(config))).to.have.lengthOf(0);
expect(Object.keys(validator.validateConfig(wrongConfig))).to.have.lengthOf(1);
expect(Object.keys(validator.validateConfig(wrongConfig))).to.have.lengthOf(2);
});


Expand All @@ -181,7 +184,7 @@ describe('<DeploymentPluginValidator> (Zeebe)', () => {
endpoint: {
targetType: 'selfHosted',
authType: 'oauth',
contactPoint: 'https://camunda.com',
contactPoint: 'https://camunda.com:0001',
oauthURL: 'https://camunda.com',
audience: 'bearer',
clientId: 'test',
Expand All @@ -203,7 +206,7 @@ describe('<DeploymentPluginValidator> (Zeebe)', () => {

// then
expect(Object.keys(validator.validateConfig(config))).to.have.lengthOf(0);
expect(Object.keys(validator.validateConfig(wrongConfig))).to.have.lengthOf(3);
expect(Object.keys(validator.validateConfig(wrongConfig))).to.have.lengthOf(4);
});
});

Expand Down

0 comments on commit 60b3646

Please sign in to comment.