-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1437 from bjoernricks/ldap-radius-improvements
LDAP and Radius improvements
- Loading branch information
Showing
18 changed files
with
521 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
Oops, something went wrong.