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

LDAP and Radius improvements #1437

Merged
merged 10 commits into from
Jun 4, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Cleanup get_report function in gsad [#1263](https://github.com/greenbone/gsa/pull/1263)

### Fixed
- Display text if gvm-libs is build without LDAP and/or Radius support [#1437](https://github.com/greenbone/gsa/pull/1437)
- Fix sending related resources in permission.create() [#1432](https://github.com/greenbone/gsa/pull/1432)
- Don't allow bulk tagging vulnerabilities [#1429](https://github.com/greenbone/gsa/pull/1429)
- Fix "given type was invalid" error for saving filters [#1428](https://github.com/greenbone/gsa/pull/1428)
Expand Down
133 changes: 133 additions & 0 deletions gsa/src/gmp/commands/__tests__/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import {AuthenticationCommand} from '../auth';

import {createActionResultResponse, createHttp} from '../testing';

describe('AuthenticationCommand tests', () => {
test('should enable ldap', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

const authdn = 'cn=%s,dc=devel,dc=foo,dc=bar';
const certificate = 'foobar';
const ldaphost = 'foo.bar';

expect.hasAssertions();

const cmd = new AuthenticationCommand(fakeHttp);
return cmd
.saveLdap({
authdn,
certificate,
enable: true,
ldaphost,
})
.then(() => {
expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: {
authdn,
certificate,
cmd: 'save_auth',
enable: 1,
group: 'method:ldap_connect',
ldaphost,
},
});
});
});

test('should disable ldap', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

const authdn = 'cn=%s,dc=devel,dc=foo,dc=bar';
const certificate = 'foobar';
const ldaphost = 'foo.bar';

expect.hasAssertions();

const cmd = new AuthenticationCommand(fakeHttp);
return cmd
.saveLdap({
authdn,
certificate,
enable: false,
ldaphost,
})
.then(() => {
expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: {
authdn,
certificate,
cmd: 'save_auth',
enable: 0,
group: 'method:ldap_connect',
ldaphost,
},
});
});
});

test('should enable radius', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

const radiushost = 'foo.bar';
const radiuskey = 'foo';

expect.hasAssertions();

const cmd = new AuthenticationCommand(fakeHttp);
return cmd.saveRadius({enable: true, radiushost, radiuskey}).then(() => {
expect(fakeHttp.request).toBeCalledWith('post', {
data: {
cmd: 'save_auth',
enable: 1,
group: 'method:radius_connect',
radiushost,
radiuskey,
},
});
});
});

test('should disable radius', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

const radiushost = 'foo.bar';
const radiuskey = 'foo';

expect.hasAssertions();

const cmd = new AuthenticationCommand(fakeHttp);
return cmd.saveRadius({enable: false, radiushost, radiuskey}).then(() => {
expect(fakeHttp.request).toBeCalledWith('post', {
data: {
cmd: 'save_auth',
enable: 0,
group: 'method:radius_connect',
radiushost,
radiuskey,
},
});
});
});
});
37 changes: 37 additions & 0 deletions gsa/src/gmp/commands/__tests__/convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import {convertBoolean} from '../convert';

describe('convertBoolean tests', () => {
test('should convert true', () => {
expect(convertBoolean(true)).toEqual(1);
});

test('should convert false', () => {
expect(convertBoolean(false)).toEqual(0);
});

test('should convert to undefined for other value', () => {
expect(convertBoolean('true')).toBeUndefined();
expect(convertBoolean('false')).toBeUndefined();
expect(convertBoolean(1)).toBeUndefined();
expect(convertBoolean(0)).toBeUndefined();
});
});
80 changes: 80 additions & 0 deletions gsa/src/gmp/commands/__tests__/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import {UserCommand} from '../users';

import {createResponse, createHttp} from '../testing';
describe('UserCommand tests', () => {
test('should parse auth settinngs in currentAuthSettings', () => {
const response = createResponse({
auth_settings: {
describe_auth_response: {
group: [
{
_name: 'foo',
auth_conf_setting: [
{
key: 'enable',
value: 'true',
},
],
},
{
_name: 'bar',
auth_conf_setting: [
{
key: 'foo',
value: 'true',
},
{
certificate_info: 'ipsum',
},
],
},
],
},
},
});
const fakeHttp = createHttp(response);

expect.hasAssertions();

const cmd = new UserCommand(fakeHttp);
return cmd.currentAuthSettings().then(resp => {
expect(fakeHttp.request).toHaveBeenCalledWith('get', {
args: {
cmd: 'auth_settings',
name: '--',
},
});

const {data: settings} = resp;

expect(settings.has('foo')).toEqual(true);
expect(settings.has('bar')).toEqual(true);
expect(settings.has('ipsum')).toEqual(false);

const fooSettings = settings.get('foo');
expect(fooSettings.enabled).toEqual(true);

const barSettings = settings.get('bar');
expect(barSettings.foo).toEqual('true');
expect(barSettings.certificateInfo).toEqual('ipsum');
});
});
});
12 changes: 7 additions & 5 deletions gsa/src/gmp/commands/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ import registerCommand from '../command';

import HttpCommand from './http';

class AuthenticationCommand extends HttpCommand {
saveLdap({authdn, certificate, enable, group, ldaphost}) {
import {convertBoolean} from './convert';

export class AuthenticationCommand extends HttpCommand {
saveLdap({authdn, certificate, enable, ldaphost}) {
return this.httpPost({
cmd: 'save_auth',
group: 'method:ldap_connect',
authdn,
certificate,
enable,
enable: convertBoolean(enable),
ldaphost,
});
}

saveRadius({enable, group, radiushost, radiuskey}) {
saveRadius({enable, radiushost, radiuskey}) {
return this.httpPost({
cmd: 'save_auth',
group: 'method:radius_connect',
enable,
enable: convertBoolean(enable),
radiushost,
radiuskey,
});
Expand Down
34 changes: 34 additions & 0 deletions gsa/src/gmp/commands/convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/**
* Convert boolean true/false to API 1/0 values
*
* It converts true to int 1 and false to 0. Converting other values returns
* undefined.
*/
export const convertBoolean = value => {
if (value === true) {
return 1;
}
if (value === false) {
return 0;
}
return undefined;
};
Loading