Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Add more descriptive message upon submitting invalid credentials #3977

Merged
merged 1 commit into from
Dec 22, 2023
Merged
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
20 changes: 20 additions & 0 deletions monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ConfigurePageComponent extends AuthComponent {
this.state = {
configuration: {},
credentials: {credentialsData: [], errors: [], id: null},
credentialsErrors: [],
masqueStrings: {},
currentFormData: {},
importCandidateConfig: null,
Expand Down Expand Up @@ -409,6 +410,20 @@ class ConfigurePageComponent extends AuthComponent {
)
.then(res => {
if (!res.ok) {
res.json().then((result)=>{
let errorMessages = result.errors.map(error => {
return `${error.message.split(', ').pop()}`;
});
const messageCountMap = {};
errorMessages.map((message) => {
messageCountMap[message] = (messageCountMap[message] || 0) + 1;
});
this.setState({
credentialsErrors: Object.entries(messageCountMap)
.map(([errorMessage, count]) =>
(count > 1 ? `${count} ${_.lowerFirst(errorMessage)}` : `${errorMessage}`))
});
});
throw Error()
}
return res;
Expand Down Expand Up @@ -573,6 +588,11 @@ class ConfigurePageComponent extends AuthComponent {
<div className='alert alert-danger'>
<FontAwesomeIcon icon={faExclamationCircle} style={{'marginRight': '5px'}}/>
An invalid configuration file was imported or submitted. One or more of the credentials are invalid.
{ this.state.credentialsErrors.length !== 0 ?
<ul>
{this.state.credentialsErrors.map(error => <li key={nanoid()}>{error}</li>)}
</ul> : ''
}
</div>
: ''}
{this.state.lastAction === 'invalid_configuration' ?
Expand Down