mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Ensure the host parameter is correctly pickup up from the service file. Fixes #3200
This commit is contained in:
parent
60893bcdd1
commit
34f1ebc88e
@ -500,7 +500,7 @@ class ServerNode(PGChildNodeView):
|
||||
if 'db_res' in data:
|
||||
data['db_res'] = ','.join(data['db_res'])
|
||||
|
||||
if 'hostaddr' in data and data['hostaddr'] != '':
|
||||
if 'hostaddr' in data and data['hostaddr'] and data['hostaddr'] != '':
|
||||
if not self.pat4.match(data['hostaddr']):
|
||||
if not self.pat6.match(data['hostaddr']):
|
||||
return make_json_response(
|
||||
@ -700,7 +700,7 @@ class ServerNode(PGChildNodeView):
|
||||
)
|
||||
)
|
||||
|
||||
if 'hostaddr' in data and data['hostaddr'] != '':
|
||||
if 'hostaddr' in data and data['hostaddr'] and data['hostaddr'] != '':
|
||||
if not self.pat4.match(data['hostaddr']):
|
||||
if not self.pat6.match(data['hostaddr']):
|
||||
return make_json_response(
|
||||
|
@ -31,6 +31,8 @@ export class ModelValidation {
|
||||
this.checkForEmpty('name', gettext('Name must be specified.'));
|
||||
|
||||
if (ModelValidation.isEmptyString(serviceId)) {
|
||||
// Do not sent empty string
|
||||
this.setNullValueForEmptyString('service');
|
||||
this.checkHostAndHostAddress();
|
||||
|
||||
this.checkForEmpty('db', gettext('Maintenance database must be specified.'));
|
||||
@ -50,8 +52,20 @@ export class ModelValidation {
|
||||
return null;
|
||||
}
|
||||
|
||||
setNullValueForEmptyString(field) {
|
||||
let val = this.model.get(field);
|
||||
if (_.isUndefined(val) || _.isNull(val))
|
||||
return;
|
||||
|
||||
// To avoid passing empty string to connection parameter
|
||||
if(String(val).trim() === '') {
|
||||
this.model.set(field, null);
|
||||
}
|
||||
}
|
||||
|
||||
clearHostAddressAndDbErrors() {
|
||||
_.each(['host', 'hostaddr', 'db'], (item) => {
|
||||
this.setNullValueForEmptyString(item);
|
||||
this.model.errorModel.unset(item);
|
||||
});
|
||||
}
|
||||
|
@ -20,6 +20,9 @@ describe('Server#ModelValidation', () => {
|
||||
get: function (key) {
|
||||
return this.allValues[key];
|
||||
},
|
||||
set: function (key, value) {
|
||||
this.key = value;
|
||||
},
|
||||
sessAttrs: {},
|
||||
};
|
||||
model.isNew = jasmine.createSpy('isNew');
|
||||
@ -51,6 +54,20 @@ describe('Server#ModelValidation', () => {
|
||||
expect(model.errorModel.set).toHaveBeenCalledWith({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Service id present', () => {
|
||||
it('sets empty service name which should throw an error', () => {
|
||||
model.allValues['service'] = '';
|
||||
expect(modelValidation.validate()).toBe('Either Host name, Address or Service must be specified.');
|
||||
expect(model.errorModel.set).toHaveBeenCalledWith({
|
||||
host: 'Either Host name, Address or Service must be specified.',
|
||||
hostaddr: 'Either Host name, Address or Service must be specified.',
|
||||
db: 'Maintenance database must be specified.'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('When no parameters are valid', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user