@@ -104,7 +104,7 @@ describe('Login', () => {
104104 . contains ( 'button' , 'Sign in' )
105105 . click ( ) ;
106106
107- cy . url ( ) . should ( 'eq' , 'http://127.0.0.1 :3000/' ) ;
107+ cy . url ( ) . should ( 'eq' , 'http://localhost :3000/' ) ;
108108
109109 cy . window ( ) . then (
110110 ( window ) =>
@@ -125,7 +125,7 @@ describe('Login', () => {
125125 . contains ( 'button' , 'Sign in' )
126126 . click ( ) ;
127127
128- cy . url ( ) . should ( 'eq' , 'http://127.0.0.1 :3000/' ) ;
128+ cy . url ( ) . should ( 'eq' , 'http://localhost :3000/' ) ;
129129
130130 cy . window ( ) . then (
131131 ( window ) =>
@@ -146,7 +146,7 @@ describe('Login', () => {
146146 . contains ( 'button' , 'Sign in' )
147147 . click ( ) ;
148148
149- cy . url ( ) . should ( 'eq' , 'http://127.0.0.1 :3000/' ) ;
149+ cy . url ( ) . should ( 'eq' , 'http://localhost :3000/' ) ;
150150
151151 let storedToken : string | null ;
152152
@@ -177,12 +177,12 @@ describe('Login', () => {
177177 it ( 'should redirect to logout page if logged in and navigating to login page' , ( ) => {
178178 cy . login ( 'username' , 'password' ) ;
179179 cy . visit ( '/login' ) ;
180- cy . url ( ) . should ( 'eq' , 'http://127.0.0.1 :3000/logout' ) ;
180+ cy . url ( ) . should ( 'eq' , 'http://localhost :3000/logout' ) ;
181181 } ) ;
182182
183183 it ( 'should redirect to Home page if not logged in and navigating to logout page' , ( ) => {
184184 cy . visit ( '/logout' ) ;
185- cy . url ( ) . should ( 'eq' , 'http://127.0.0.1 :3000/login' ) ;
185+ cy . url ( ) . should ( 'eq' , 'http://localhost :3000/login' ) ;
186186 } ) ;
187187
188188 it ( 'should redirect to login page when navigating to a plugin then back to the plugin after login' , ( ) => {
@@ -199,7 +199,7 @@ describe('Login', () => {
199199 . contains ( 'button' , 'Sign in' )
200200 . click ( ) ;
201201
202- cy . url ( ) . should ( 'eq' , 'http://127.0.0.1 :3000/plugin1' ) ;
202+ cy . url ( ) . should ( 'eq' , 'http://localhost :3000/plugin1' ) ;
203203 cy . get ( '#demo_plugin' ) . contains ( 'Demo Plugin' ) . should ( 'be.visible' ) ;
204204 } ) ;
205205
@@ -439,6 +439,34 @@ describe('Login', () => {
439439 cy . get ( '[aria-label="Open user menu"]' ) . should ( 'be.visible' ) ;
440440 } ) ;
441441
442+ it ( 'should be able to login via SSO after auto login and be displayed as logged in' , ( ) => {
443+ cy . visit ( '/login' ) ;
444+
445+ cy . get ( '#select-mnemonic' ) . click ( ) ;
446+ cy . contains ( 'Keycloak' ) . click ( ) ;
447+
448+ cy . url ( ) . as ( 'originUrl' , { type : 'static' } ) ;
449+
450+ cy . contains ( 'button' , 'Login with Keycloak' ) . click ( ) ;
451+
452+ cy . url ( ) . should ( 'include' , 'http://localhost:8081' ) ;
453+ // login to keycloak
454+ cy . origin ( 'http://localhost:8081' , ( ) => {
455+ cy . get ( '#username' ) . type ( 'test' ) ;
456+ cy . get ( '#password' ) . type ( 'password' ) ;
457+ cy . get ( '#kc-login' ) . click ( ) ;
458+ } ) ;
459+
460+ // redirect?
461+ // cy.origin()
462+ cy . get ( '@originUrl' ) . then ( ( url ) => {
463+ cy . url ( ) . should ( 'include' , url ) ;
464+ } ) ;
465+
466+ cy . contains ( 'Sign out' ) . should ( 'exist' ) ;
467+ cy . get ( '[aria-label="Open user menu"]' ) . should ( 'be.visible' ) ;
468+ } ) ;
469+
442470 it ( 'should autoLogin after logout' , ( ) => {
443471 window . localStorage . setItem (
444472 'scigateway:token' ,
@@ -488,4 +516,76 @@ describe('Login', () => {
488516 cy . contains ( 'Unable to create anonymous session' ) . should ( 'not.exist' ) ;
489517 } ) ;
490518 } ) ;
519+
520+ describe ( 'OIDC' , ( ) => {
521+ beforeEach ( ( ) => {
522+ cy . intercept ( '/settings.json' , {
523+ plugins : [
524+ {
525+ name : 'demo_plugin' ,
526+ src : '/plugins/e2e-plugin/main.js' ,
527+ enable : true ,
528+ location : 'main' ,
529+ } ,
530+ ] ,
531+ 'ui-strings' : 'res/default.json' ,
532+ 'auth-provider' : 'oidc' ,
533+ authUrl : 'http://localhost:8000' ,
534+ autoLogin : true ,
535+ 'help-tour-steps' : [ ] ,
536+ } ) ;
537+ } ) ;
538+
539+ it ( 'should be able to login via SSO PKCE and be displayed as logged in' , ( ) => {
540+ cy . visit ( '/login' ) ;
541+
542+ cy . url ( ) . as ( 'originUrl' , { type : 'static' } ) ;
543+
544+ cy . get ( '#select-mnemonic' ) . click ( ) ;
545+ cy . contains ( 'Keycloak (PKCE)' ) . click ( ) ;
546+
547+ cy . contains ( 'button' , 'Login with Keycloak (PKCE)' ) . click ( ) ;
548+
549+ cy . url ( ) . should ( 'include' , 'http://localhost:8081' ) ;
550+ // login to keycloak
551+ cy . origin ( 'http://localhost:8081' , ( ) => {
552+ cy . get ( '#username' ) . type ( 'test' ) ;
553+ cy . get ( '#password' ) . type ( 'password' ) ;
554+ cy . get ( '#kc-login' ) . click ( ) ;
555+ } ) ;
556+
557+ cy . get ( '@originUrl' ) . then ( ( url ) => {
558+ cy . url ( ) . should ( 'include' , url ) ;
559+ } ) ;
560+
561+ cy . contains ( 'Sign in' ) . should ( 'not.exist' ) ;
562+ cy . get ( '[aria-label="Open user menu"]' ) . should ( 'be.visible' ) ;
563+ } ) ;
564+
565+ it ( 'should be able to login via SSO non-PKCE and be displayed as logged in' , ( ) => {
566+ // test that redirect from an authorised route will take you back
567+ cy . visit ( '/plugin1' ) ;
568+
569+ cy . url ( ) . as ( 'originUrl' , { type : 'static' } ) ;
570+
571+ cy . get ( '#select-mnemonic' ) . click ( ) ;
572+ cy . contains ( 'Keycloak (Non-PKCE)' ) . click ( ) ;
573+
574+ cy . contains ( 'button' , 'Login with Keycloak (Non-PKCE)' ) . click ( ) ;
575+
576+ cy . url ( ) . should ( 'include' , 'http://localhost:8081' ) ;
577+ // login to keycloak
578+ cy . origin ( 'http://localhost:8081' , ( ) => {
579+ cy . get ( '#username' ) . type ( 'test' ) ;
580+ cy . get ( '#password' ) . type ( 'password' ) ;
581+ cy . get ( '#kc-login' ) . click ( ) ;
582+ } ) ;
583+
584+ cy . get ( '@originUrl' ) . then ( ( url ) => {
585+ cy . url ( ) . should ( 'include' , url ) ;
586+ } ) ;
587+
588+ cy . get ( '#demo_plugin' ) . contains ( 'h2' , '/plugin1' ) . should ( 'be.visible' ) ;
589+ } ) ;
590+ } ) ;
491591} ) ;
0 commit comments