You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2021/11/08 09:28:44 UTC

[incubator-streampipes] branch STREAMPIPES-426 updated: [STREAMPIPES-426] Fix test login for new authentication

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch STREAMPIPES-426
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/STREAMPIPES-426 by this push:
     new b7eac41  [STREAMPIPES-426] Fix test login for new authentication
b7eac41 is described below

commit b7eac41fc367292079c8b4152b60ebc91ade9dd6
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Mon Nov 8 10:26:38 2021 +0100

    [STREAMPIPES-426] Fix test login for new authentication
---
 ui/cypress/support/general/login.ts                | 33 +++++++--------
 ui/cypress/support/general/logout.ts               | 24 +++++------
 ui/cypress/support/general/resetStreamPipes.ts     |  8 +++-
 ui/cypress/support/utils/UserUtils.ts              |  4 +-
 ui/cypress/tests/adapter/machineDataSimulator.ts   |  2 +
 ui/cypress/tests/installation/installation.ts      | 48 ----------------------
 .../installation/login.ts}                         | 23 ++++++-----
 .../login/components/login/login.component.html    | 21 ++++++++--
 8 files changed, 69 insertions(+), 94 deletions(-)

diff --git a/ui/cypress/support/general/login.ts b/ui/cypress/support/general/login.ts
index d165242..c47ac4a 100644
--- a/ui/cypress/support/general/login.ts
+++ b/ui/cypress/support/general/login.ts
@@ -17,26 +17,27 @@
  */
 
 import { UserUtils } from '../utils/UserUtils';
+import { JwtHelperService } from '@auth0/angular-jwt';
 
 declare global {
-    namespace Cypress {
-        interface Chainable {
-            /**
-             * Login into streampipes with standard test user
-             * @example cy.login();
-             */
-            login: typeof login;
-        }
+  namespace Cypress {
+    interface Chainable {
+      /**
+       * Login into streampipes with standard test user
+       * @example cy.login();
+       */
+      login: typeof login;
     }
+  }
 }
 
 export const login = () => {
-    Cypress.Cookies.defaults({
-        preserve: 'JSESSIONID'
-    });
-
-    cy.request('POST', '/streampipes-backend/api/v2/admin/login', {
-        username: UserUtils.testUserName,
-        password: UserUtils.testUserPassword
-    });
+  cy.request('POST', '/streampipes-backend/api/v2/auth/login', {
+    username: UserUtils.testUserName,
+    password: UserUtils.testUserPassword
+  }).then(res => {
+    const decodedToken = new JwtHelperService({}).decodeToken(res.body.accessToken);
+    window.localStorage.setItem('auth-user', JSON.stringify(decodedToken.user));
+    window.localStorage.setItem('auth-token', res.body.accessToken);
+  });
 };
diff --git a/ui/cypress/support/general/logout.ts b/ui/cypress/support/general/logout.ts
index fced9fc..c6ea807 100644
--- a/ui/cypress/support/general/logout.ts
+++ b/ui/cypress/support/general/logout.ts
@@ -17,22 +17,18 @@
  */
 
 declare global {
-    namespace Cypress {
-        interface Chainable {
-            /**
-             * Logout of StreamPipes
-             * @example cy.logout();
-             */
-            logout: typeof logout;
-        }
+  namespace Cypress {
+    interface Chainable {
+      /**
+       * Logout of StreamPipes
+       * @example cy.logout();
+       */
+      logout: typeof logout;
     }
+  }
 }
 
 export const logout = () => {
-    Cypress.Cookies.defaults({
-        preserve: 'JSESSIONID'
-    });
-
-    cy.dataCy('sp-user-preferences').click();
-    cy.dataCy('sp-logout').click();
+  cy.dataCy('sp-user-preferences').click();
+  cy.dataCy('sp-logout').click();
 };
diff --git a/ui/cypress/support/general/resetStreamPipes.ts b/ui/cypress/support/general/resetStreamPipes.ts
index 0c87f14..acb5a87 100644
--- a/ui/cypress/support/general/resetStreamPipes.ts
+++ b/ui/cypress/support/general/resetStreamPipes.ts
@@ -25,5 +25,11 @@ declare global {
 }
 
 export const resetStreamPipes = () => {
-  cy.request('POST', `/streampipes-backend/api/v2/reset`, {});
+  cy.request({
+    method: 'POST',
+    url: '/streampipes-backend/api/v2/reset',
+    auth: {
+      bearer: window.localStorage.getItem('auth-token')
+    }
+  });
 };
diff --git a/ui/cypress/support/utils/UserUtils.ts b/ui/cypress/support/utils/UserUtils.ts
index b9b26e2..b932f69 100644
--- a/ui/cypress/support/utils/UserUtils.ts
+++ b/ui/cypress/support/utils/UserUtils.ts
@@ -17,6 +17,6 @@
  */
 
 export class UserUtils {
-  public static testUserName = 'test@streampipes.apache.org';
-  public static testUserPassword = '1234';
+  public static testUserName = 'admin@streampipes.apache.org';
+  public static testUserPassword = 'admin';
 }
diff --git a/ui/cypress/tests/adapter/machineDataSimulator.ts b/ui/cypress/tests/adapter/machineDataSimulator.ts
index 6ff206f..87827a5 100644
--- a/ui/cypress/tests/adapter/machineDataSimulator.ts
+++ b/ui/cypress/tests/adapter/machineDataSimulator.ts
@@ -31,6 +31,8 @@ describe('Test Random Data Simulator Stream Adapter', () => {
       .addInput('input', 'wait-time-ms', '1000')
       .build();
 
+
+    cy.visit('#/connect');
     AdapterUtils.testSpecificStreamAdapter(adapterInput);
     AdapterUtils.deleteAdapter();
 
diff --git a/ui/cypress/tests/installation/installation.ts b/ui/cypress/tests/installation/installation.ts
deleted file mode 100644
index 79f9923..0000000
--- a/ui/cypress/tests/installation/installation.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-import { UserUtils } from '../../support/utils/UserUtils';
-
-
-describe('Install StreamPipes', () => {
-  let isSetupPage: boolean;
-
-  it('Perform Test', () => {
-
-    cy.visit('#/login');
-
-    // This wait ensures that the installation site is completely loaded
-    // If a better solution is found this wait can be removed
-    // The test should work for both cases either when the system is already installed and when it should be installed
-    cy.wait(10000);
-
-    cy.url({ timeout: 60000 }).then(($route) => {
-      isSetupPage = ($route.endsWith('setup')) ? true : false;
-      if (isSetupPage) {
-        cy.get('input[name="email"]').type(UserUtils.testUserName);
-        cy.get('input[name="password"]').type(UserUtils.testUserPassword);
-
-        cy.get('button').contains('Install').parent().click();
-
-        cy.dataCy('sp-button-finish-installation', { timeout: 240000 }).should('be.visible');
-        cy.dataCy('sp-button-finish-installation').click();
-      }
-    });
-  });
-
-});
diff --git a/ui/cypress/support/general/resetStreamPipes.ts b/ui/cypress/tests/installation/login.ts
similarity index 69%
copy from ui/cypress/support/general/resetStreamPipes.ts
copy to ui/cypress/tests/installation/login.ts
index 0c87f14..043cb4e 100644
--- a/ui/cypress/support/general/resetStreamPipes.ts
+++ b/ui/cypress/tests/installation/login.ts
@@ -16,14 +16,17 @@
  *
  */
 
-declare global {
-  namespace Cypress {
-    interface Chainable {
-      resetStreamPipes: typeof resetStreamPipes;
-    }
-  }
-}
+import { UserUtils } from '../../support/utils/UserUtils';
 
-export const resetStreamPipes = () => {
-  cy.request('POST', `/streampipes-backend/api/v2/reset`, {});
-};
+
+describe('Login and logout of StreamPipes', () => {
+
+  it('Perform Test', () => {
+    cy.visit('#/login');
+    cy.dataCy('login-email').type(UserUtils.testUserName);
+    cy.dataCy('login-password').type(UserUtils.testUserPassword);
+    cy.dataCy('login-button').click();
+    cy.logout();
+  });
+
+});
diff --git a/ui/src/app/login/components/login/login.component.html b/ui/src/app/login/components/login/login.component.html
index fd11193..afc06d0 100644
--- a/ui/src/app/login/components/login/login.component.html
+++ b/ui/src/app/login/components/login/login.component.html
@@ -25,15 +25,30 @@
             <div fxFlex="100" fxLayout="column">
                 <mat-form-field fxFlex color="accent">
                     <mat-label>Email</mat-label>
-                    <input formControlName="username" matInput name="username" class="sp" required/>
+                    <input formControlName="username"
+                           matInput
+                           name="username"
+                           class="sp"
+                           required
+                           data-cy="login-email"/>
                 </mat-form-field>
                 <mat-form-field fxFlex color="accent">
                     <mat-label>Password</mat-label>
-                    <input formControlName="password" matInput name="password" type="password" class="sp" required/>
+                    <input formControlName="password"
+                           matInput
+                           name="password"
+                           type="password"
+                           class="sp"
+                           required
+                           data-cy="login-password"/>
                 </mat-form-field>
             </div>
             <div class="form-actions" style="margin-top:20px;">
-                <button mat-button mat-raised-button color="accent" (click)="logIn()"
+                <button mat-button
+                        mat-raised-button
+                        color="accent"
+                        data-cy="login-button"
+                        (click)="logIn()"
                         [disabled]="!parentForm.valid || loading">
                     <span *ngIf="loading">Logging in...</span>
                     <span *ngIf="!loading">Login</span>