Skip to content

Commit

Permalink
add user/password verification per PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuellr committed Mar 23, 2020
1 parent 977a95f commit 97d5c0b
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ describe('connector validation', () => {
});
});

test('connector validation succeeds when connector config is valid with empty user/password', () => {
const actionConnector = {
secrets: {
user: null,
password: null,
},
id: 'test',
actionTypeId: '.email',
name: 'email',
config: {
from: 'test@test.com',
port: 2323,
host: 'localhost',
test: 'test',
},
} as EmailActionConnector;

expect(actionTypeModel.validateConnector(actionConnector)).toEqual({
errors: {
from: [],
port: [],
host: [],
user: [],
password: [],
},
});
});
test('connector validation fails when connector config is not valid', () => {
const actionConnector = {
secrets: {
Expand All @@ -82,6 +109,60 @@ describe('connector validation', () => {
},
});
});
test('connector validation fails when user specified but not password', () => {
const actionConnector = {
secrets: {
user: 'user',
password: null,
},
id: 'test',
actionTypeId: '.email',
name: 'email',
config: {
from: 'test@test.com',
port: 2323,
host: 'localhost',
test: 'test',
},
} as EmailActionConnector;

expect(actionTypeModel.validateConnector(actionConnector)).toEqual({
errors: {
from: [],
port: [],
host: [],
user: [],
password: ['Password is required when username is used.'],
},
});
});
test('connector validation fails when password specified but not user', () => {
const actionConnector = {
secrets: {
user: null,
password: 'password',
},
id: 'test',
actionTypeId: '.email',
name: 'email',
config: {
from: 'test@test.com',
port: 2323,
host: 'localhost',
test: 'test',
},
} as EmailActionConnector;

expect(actionTypeModel.validateConnector(actionConnector)).toEqual({
errors: {
from: [],
port: [],
host: [],
user: ['Username is required when password is used.'],
password: [],
},
});
});
});

describe('action params validation', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ export function getActionType(): ActionTypeModel {
)
);
}
if (action.secrets.user && !action.secrets.password) {
errors.password.push(
i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.error.requiredPasswordText',
{
defaultMessage: 'Password is required when username is used.',
}
)
);
}
if (!action.secrets.user && action.secrets.password) {
errors.user.push(
i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.error.requiredUserText',
{
defaultMessage: 'Username is required when password is used.',
}
)
);
}
return validationResult;
},
validateParams: (actionParams: EmailActionParams): ValidationResult => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ interface EmailConfig {
}

interface EmailSecrets {
user: string;
password: string;
user: string | null;
password: string | null;
}

export interface EmailActionConnector extends ActionConnector {
Expand Down

0 comments on commit 97d5c0b

Please sign in to comment.