From f0fb75714e54f5191a7026eedbec757ee22a682c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Fri, 21 Aug 2020 14:56:45 +0200 Subject: [PATCH] 16735: Added better checks for the PAM and LDAP login MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- .../current-token-dialog.tsx | 1 + src/views/login-panel/login-panel.test.tsx | 117 ++++++++++++++++++ src/views/login-panel/login-panel.tsx | 4 +- 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 src/views/login-panel/login-panel.test.tsx diff --git a/src/views-components/current-token-dialog/current-token-dialog.tsx b/src/views-components/current-token-dialog/current-token-dialog.tsx index 0ea24690..9cb08f8b 100644 --- a/src/views-components/current-token-dialog/current-token-dialog.tsx +++ b/src/views-components/current-token-dialog/current-token-dialog.tsx @@ -57,6 +57,7 @@ unset ARVADOS_API_HOST_INSECURE` render() { const { classes, open, closeDialog, ...data } = this.props; + return ', () => { + describe('requirePasswordLogin', () => { + it('should return false if no config specified', () => { + // given + const config = null; + + // when + const result = requirePasswordLogin(config); + + // then + expect(result).toBeFalsy(); + }); + + it('should return false if no config.clusterConfig specified', () => { + // given + const config = {}; + + // when + const result = requirePasswordLogin(config); + + // then + expect(result).toBeFalsy(); + }); + + it('should return false if no config.clusterConfig.Login specified', () => { + // given + const config = { + clusterConfig: {}, + }; + + // when + const result = requirePasswordLogin(config); + + // then + expect(result).toBeFalsy(); + }); + + it('should return false if no config.clusterConfig.Login.LDAP and config.clusterConfig.Login.PAM specified', () => { + // given + const config = { + clusterConfig: { + Login: {} + }, + }; + + // when + const result = requirePasswordLogin(config); + + // then + expect(result).toBeFalsy(); + }); + + it('should return false if config.clusterConfig.Login.LDAP.Enable and config.clusterConfig.Login.PAM.Enable not specified', () => { + // given + const config = { + clusterConfig: { + Login: { + PAM: {}, + LDAP: {}, + }, + }, + }; + + // when + const result = requirePasswordLogin(config); + + // then + expect(result).toBeFalsy(); + }); + + it('should return value from config.clusterConfig.Login.LDAP.Enable', () => { + // given + const config = { + clusterConfig: { + Login: { + PAM: {}, + LDAP: { + Enable: true + }, + }, + }, + }; + + // when + const result = requirePasswordLogin(config); + + // then + expect(result).toBeTruthy(); + }); + + it('should return value from config.clusterConfig.Login.PAM.Enable', () => { + // given + const config = { + clusterConfig: { + Login: { + LDAP: {}, + PAM: { + Enable: true + }, + }, + }, + }; + + // when + const result = requirePasswordLogin(config); + + // then + expect(result).toBeTruthy(); + }); + }); +}); \ No newline at end of file diff --git a/src/views/login-panel/login-panel.tsx b/src/views/login-panel/login-panel.tsx index f60f032a..1d7e6ad4 100644 --- a/src/views/login-panel/login-panel.tsx +++ b/src/views/login-panel/login-panel.tsx @@ -70,8 +70,8 @@ type LoginPanelProps = DispatchProp & WithStyles & { passwordLogin: boolean, }; -const requirePasswordLogin = (config: Config): boolean => { - if (config && config.clusterConfig) { +export const requirePasswordLogin = (config: Config): boolean => { + if (config && config.clusterConfig && config.clusterConfig.Login && (config.clusterConfig.Login.LDAP || config.clusterConfig.Login.PAM)) { return config.clusterConfig.Login.LDAP.Enable || config.clusterConfig.Login.PAM.Enable || false; } return false; -- 2.30.2