16735: Added better checks for the PAM and LDAP login
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Fri, 21 Aug 2020 12:56:45 +0000 (14:56 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Fri, 21 Aug 2020 12:58:04 +0000 (14:58 +0200)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

src/views-components/current-token-dialog/current-token-dialog.tsx
src/views/login-panel/login-panel.test.tsx [new file with mode: 0644]
src/views/login-panel/login-panel.tsx

index 0ea24690fd901c92e33ab5732e8aa398f3cc812f..9cb08f8b825b49a487a3da86bc87e00176cb56a4 100644 (file)
@@ -57,6 +57,7 @@ unset ARVADOS_API_HOST_INSECURE`
 
     render() {
         const { classes, open, closeDialog, ...data } = this.props;
+
         return <Dialog
             open={open}
             onClose={closeDialog}
diff --git a/src/views/login-panel/login-panel.test.tsx b/src/views/login-panel/login-panel.test.tsx
new file mode 100644 (file)
index 0000000..c716433
--- /dev/null
@@ -0,0 +1,117 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { requirePasswordLogin } from './login-panel';
+
+describe('<LoginPanel />', () => {
+    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
index f60f032a7f07f8c7f068ace3a60ba78c849da45b..1d7e6ad442627d0936feb3d9989303c689977379 100644 (file)
@@ -70,8 +70,8 @@ type LoginPanelProps = DispatchProp<any> & WithStyles<CssRules> & {
     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;