From 0571df405802bd1b3ca237e741957735bff8f276 Mon Sep 17 00:00:00 2001
From: Clement Michaud <clement.michaud34@gmail.com>
Date: Fri, 1 Nov 2019 16:08:22 +0100
Subject: [PATCH] Fetch state after logging out.

---
 bootstrap.sh                                    |  3 +--
 .../containers/views/LogoutView/LogoutView.ts   | 17 +++++++++++++++++
 client/src/routes/routes.ts                     |  2 +-
 client/src/views/LogoutView/LogoutView.tsx      | 12 +++++++-----
 cmd/authelia-scripts/cmd_suites.go              | 12 ++++++------
 .../behaviors/RegisterAndLoginTwoFactor.ts      |  2 --
 .../scenarii/SingleFactorAuthentication.ts      |  5 +----
 7 files changed, 33 insertions(+), 20 deletions(-)
 create mode 100644 client/src/containers/views/LogoutView/LogoutView.ts

diff --git a/bootstrap.sh b/bootstrap.sh
index 48eff9f6..7e147962 100644
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -1,5 +1,4 @@
-
-set -e
+#!/bin/bash
 
 export PATH=./cmd/authelia-scripts/:/tmp:$PATH
 
diff --git a/client/src/containers/views/LogoutView/LogoutView.ts b/client/src/containers/views/LogoutView/LogoutView.ts
new file mode 100644
index 00000000..52d2cd50
--- /dev/null
+++ b/client/src/containers/views/LogoutView/LogoutView.ts
@@ -0,0 +1,17 @@
+import { connect } from 'react-redux';
+import { Dispatch } from 'redux';
+import { RootState } from '../../../reducers';
+import LogoutView, { DispatchProps } from '../../../views/LogoutView/LogoutView';
+import LogoutBehavior from '../../../behaviors/LogoutBehavior';
+
+const mapStateToProps = (state: RootState) => {
+  return {};
+}
+
+const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => {
+  return {
+    onInit: () => LogoutBehavior(dispatch),
+  }
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(LogoutView);
\ No newline at end of file
diff --git a/client/src/routes/routes.ts b/client/src/routes/routes.ts
index 40208e4a..d3c9c347 100644
--- a/client/src/routes/routes.ts
+++ b/client/src/routes/routes.ts
@@ -4,7 +4,7 @@ import SecurityKeyRegistrationView from "../containers/views/SecurityKeyRegistra
 import ForgotPasswordView from "../containers/views/ForgotPasswordView/ForgotPasswordView";
 import ResetPasswordView from "../containers/views/ResetPasswordView/ResetPasswordView";
 import AuthenticationView from "../containers/views/AuthenticationView/AuthenticationView";
-import LogoutView from "../views/LogoutView/LogoutView";
+import LogoutView from "../containers/views/LogoutView/LogoutView";
 
 export const routes = [{
   path: '/',
diff --git a/client/src/views/LogoutView/LogoutView.tsx b/client/src/views/LogoutView/LogoutView.tsx
index f0bfc339..72adcda9 100644
--- a/client/src/views/LogoutView/LogoutView.tsx
+++ b/client/src/views/LogoutView/LogoutView.tsx
@@ -1,13 +1,15 @@
 import React from "react"
 import { Redirect } from "react-router";
 
-async function logout() {
-    return fetch("/api/logout", {method: "POST"})
+export interface DispatchProps {
+    onInit: () => void;
 }
 
-export default class LogoutView extends React.Component {
-    componentDidMount() {
-        logout().catch(console.error);
+type Props = DispatchProps;
+
+export default class LogoutView extends React.Component<Props> {
+    componentWillMount() {
+        this.props.onInit();
     }
 
     render() {
diff --git a/cmd/authelia-scripts/cmd_suites.go b/cmd/authelia-scripts/cmd_suites.go
index 8d42d1a5..6eddf438 100644
--- a/cmd/authelia-scripts/cmd_suites.go
+++ b/cmd/authelia-scripts/cmd_suites.go
@@ -152,10 +152,12 @@ var SuitesTestCmd = &cobra.Command{
 			runSuiteTests(suite, runningSuite == "")
 		} else {
 			if runningSuite != "" {
-				panic(errors.New("Cannot run all tests while a suite is currently running. Shutdown running suite and retry"))
+				fmt.Println("Running suite (" + runningSuite + ") detected. Run tests of that suite")
+				runSuiteTests(runningSuite, false)
+			} else {
+				fmt.Println("No suite provided therefore all suites will be tested")
+				runAllSuites()
 			}
-			fmt.Println("No suite provided therefore all suites will be tested")
-			runAllSuites()
 		}
 	},
 	Args: cobra.MaximumNArgs(1),
@@ -193,11 +195,9 @@ func runSuiteTests(suite string, withEnv bool) {
 	var cmd *exec.Cmd
 
 	if withEnv {
-		fmt.Println("No running suite detected, setting up an environment for running the tests")
 		cmd = CommandWithStdout("bash", "-c",
 			"./node_modules/.bin/ts-node ./scripts/run-environment.ts "+suite+" '"+mochaCmdLine+"'")
 	} else {
-		fmt.Println("Running suite detected. Running tests...")
 		cmd = CommandWithStdout("bash", "-c", mochaCmdLine)
 	}
 
@@ -209,7 +209,7 @@ func runSuiteTests(suite string, withEnv bool) {
 	err := cmd.Run()
 
 	if err != nil {
-		os.Exit(1)
+		panic(err)
 	}
 }
 
diff --git a/test/helpers/behaviors/RegisterAndLoginTwoFactor.ts b/test/helpers/behaviors/RegisterAndLoginTwoFactor.ts
index 70139873..f477e0d3 100644
--- a/test/helpers/behaviors/RegisterAndLoginTwoFactor.ts
+++ b/test/helpers/behaviors/RegisterAndLoginTwoFactor.ts
@@ -1,10 +1,8 @@
 import { WebDriver } from "selenium-webdriver";
 import LoginAndRegisterTotp from "../LoginAndRegisterTotp";
-import FullLogin from "../FullLogin";
 import VerifyUrlIs from "../assertions/VerifyUrlIs";
 import VisitPageAndWaitUrlIs from "./VisitPageAndWaitUrlIs";
 import ValidateTotp from "../ValidateTotp";
-import FillLoginPageAndClick from "../FillLoginPageAndClick";
 
 export default async function(
   driver: WebDriver,
diff --git a/test/helpers/scenarii/SingleFactorAuthentication.ts b/test/helpers/scenarii/SingleFactorAuthentication.ts
index 9cbec895..c1a74c3a 100644
--- a/test/helpers/scenarii/SingleFactorAuthentication.ts
+++ b/test/helpers/scenarii/SingleFactorAuthentication.ts
@@ -28,10 +28,7 @@ export default function(timeout: number = 5000) {
     it("should redirect to portal if not enough authorized", async function() {
       await LoginOneFactor(this.driver, "john", "password", "https://singlefactor.example.com:8080/secret.html", timeout);
       await VisitPage(this.driver, "https://admin.example.com:8080/secret.html");
-  
-      // the url should be the one from the portal.
-      await VerifyUrlContains(this.driver, "https://login.example.com:8080/#/?rd=https://admin.example.com:8080/secret.html", timeout);
-  
+       
       // And the user should end up on the second factor page.
       await VerifyIsSecondFactorStage(this.driver, timeout);
     });