@@ -29,36 +29,70 @@ before(() => {
29
29
30
30
// Avoid Cypress lock onto the ipv4 range, so fake `visit()` before `request()`.
31
31
// See: https://github.com/cypress-io/cypress/issues/25397#issuecomment-1402556488
32
- cy . visit ( `http://localhost:5601${ basePath } ` ) ;
32
+ if ( Cypress . env ( 'loginMethod' ) === 'saml_multiauth' ) {
33
+ cy . visit ( `http://localhost:5601${ basePath } ` ) ;
34
+ } else {
35
+ cy . request ( `http://localhost:5601${ basePath } ` ) ;
36
+ }
33
37
34
38
cy . createRoleMapping ( ALL_ACCESS_ROLE , samlUserRoleMapping ) ;
35
39
cy . clearCookies ( ) ;
36
40
cy . clearLocalStorage ( ) ;
37
41
} ) ;
38
42
43
+ beforeEach ( ( ) => {
44
+ cy . intercept ( 'GET' , '**/**' , ( req ) => {
45
+ // Replace [::1] with localhost in the request URL and headers
46
+ if ( req . url . includes ( '[::1]' ) ) {
47
+ req . url = req . url . replace ( / \[ : : 1 \] / g, 'localhost' ) ;
48
+ }
49
+
50
+ req . on ( 'response' , ( res ) => {
51
+ if ( res && res . headers ) {
52
+ Object . keys ( res . headers ) . forEach ( ( key ) => {
53
+ if ( typeof res . headers [ key ] === 'string' && res . headers [ key ] . includes ( '[::1]' ) ) {
54
+ res . headers [ key ] = res . headers [ key ] . replace ( / \[ : : 1 \] / g, 'localhost' ) ;
55
+ }
56
+ } ) ;
57
+ }
58
+ return res ;
59
+ } ) ;
60
+ } ) ;
61
+ } ) ;
62
+
39
63
afterEach ( ( ) => {
40
64
cy . clearCookies ( ) ;
41
65
cy . clearLocalStorage ( ) ;
42
66
} ) ;
43
67
44
68
describe ( 'Log in via SAML' , ( ) => {
45
- const samlLogin = ( ) => {
46
- if ( Cypress . env ( 'loginMethod' ) === 'saml_multiauth' ) {
47
- cy . loginWithSamlMultiauth ( ) ;
48
- } else {
49
- cy . loginWithSaml ( ) ;
50
- }
69
+ const loginWithSamlMultiauth = ( ) => {
70
+ cy . get ( 'a[aria-label="saml_login_button"]' ) . should ( 'be.visible' ) ;
71
+ cy . get ( 'a[aria-label="saml_login_button"]' ) . should ( 'be.visible' ) . click ( ) ;
72
+ cy . origin ( 'http://localhost:7000' , ( ) => {
73
+ cy . get ( 'input[id=userName]' ) . should ( 'be.visible' ) ;
74
+ cy . get ( 'button[id=btn-sign-in]' ) . should ( 'be.visible' ) . click ( ) ;
75
+ } ) ;
51
76
} ;
52
77
53
78
it ( 'Login to app/opensearch_dashboards_overview#/ when SAML is enabled' , ( ) => {
54
79
localStorage . setItem ( 'opendistro::security::tenant::saved' , '"__user__"' ) ;
55
80
localStorage . setItem ( 'home:newThemeModal:show' , 'false' ) ;
56
81
57
- cy . visit ( `http://localhost:5601${ basePath } /app/opensearch_dashboards_overview` , {
58
- failOnStatusCode : false ,
59
- } ) ;
60
-
61
- samlLogin ( ) ;
82
+ if ( Cypress . env ( 'loginMethod' ) === 'saml_multiauth' ) {
83
+ cy . visit ( `http://localhost:5601${ basePath } /app/opensearch_dashboards_overview` , {
84
+ failOnStatusCode : false ,
85
+ } ) ;
86
+ loginWithSamlMultiauth ( ) ;
87
+ } else {
88
+ cy . origin ( 'http://localhost:7000' , { args : { basePath } } , ( { basePath } ) => {
89
+ cy . visit ( `http://localhost:5601${ basePath } /app/opensearch_dashboards_overview` , {
90
+ failOnStatusCode : false ,
91
+ } ) ;
92
+ cy . get ( 'input[id=userName]' ) . should ( 'be.visible' ) ;
93
+ cy . get ( 'button[id=btn-sign-in]' ) . should ( 'be.visible' ) . click ( ) ;
94
+ } ) ;
95
+ }
62
96
63
97
cy . get ( '#osdOverviewPageHeader__title' ) . should ( 'be.visible' ) ;
64
98
cy . getCookie ( 'security_authentication' ) . should ( 'exist' ) ;
@@ -68,11 +102,20 @@ describe('Log in via SAML', () => {
68
102
localStorage . setItem ( 'opendistro::security::tenant::saved' , '"__user__"' ) ;
69
103
localStorage . setItem ( 'home:newThemeModal:show' , 'false' ) ;
70
104
71
- cy . visit ( `http://localhost:5601${ basePath } /app/dev_tools#/console` , {
72
- failOnStatusCode : false ,
73
- } ) ;
74
-
75
- samlLogin ( ) ;
105
+ if ( Cypress . env ( 'loginMethod' ) === 'saml_multiauth' ) {
106
+ cy . visit ( `http://localhost:5601${ basePath } /app/dev_tools#/console` , {
107
+ failOnStatusCode : false ,
108
+ } ) ;
109
+ loginWithSamlMultiauth ( ) ;
110
+ } else {
111
+ cy . origin ( 'http://localhost:7000' , { args : { basePath } } , ( { basePath } ) => {
112
+ cy . visit ( `http://localhost:5601${ basePath } /app/dev_tools#/console` , {
113
+ failOnStatusCode : false ,
114
+ } ) ;
115
+ cy . get ( 'input[id=userName]' ) . should ( 'be.visible' ) ;
116
+ cy . get ( 'button[id=btn-sign-in]' ) . should ( 'be.visible' ) . click ( ) ;
117
+ } ) ;
118
+ }
76
119
77
120
cy . get ( 'a.euiBreadcrumb--last' ) . contains ( 'Dev Tools' ) ;
78
121
cy . getCookie ( 'security_authentication' ) . should ( 'exist' ) ;
@@ -84,11 +127,20 @@ describe('Log in via SAML', () => {
84
127
85
128
const urlWithHash = `http://localhost:5601${ basePath } /app/security-dashboards-plugin#/getstarted` ;
86
129
87
- cy . visit ( urlWithHash , {
88
- failOnStatusCode : false ,
89
- } ) ;
90
-
91
- samlLogin ( ) ;
130
+ if ( Cypress . env ( 'loginMethod' ) === 'saml_multiauth' ) {
131
+ cy . visit ( urlWithHash , {
132
+ failOnStatusCode : false ,
133
+ } ) ;
134
+ loginWithSamlMultiauth ( ) ;
135
+ } else {
136
+ cy . origin ( 'http://localhost:7000' , { args : { urlWithHash } } , ( { urlWithHash } ) => {
137
+ cy . visit ( urlWithHash , {
138
+ failOnStatusCode : false ,
139
+ } ) ;
140
+ cy . get ( 'input[id=userName]' ) . should ( 'be.visible' ) ;
141
+ cy . get ( 'button[id=btn-sign-in]' ) . should ( 'be.visible' ) . click ( ) ;
142
+ } ) ;
143
+ }
92
144
93
145
cy . get ( 'h1' ) . contains ( 'Get started' ) ;
94
146
cy . getCookie ( 'security_authentication' ) . should ( 'exist' ) ;
@@ -97,11 +149,20 @@ describe('Log in via SAML', () => {
97
149
it ( 'Tenancy persisted after logout in SAML' , ( ) => {
98
150
localStorage . setItem ( 'home:newThemeModal:show' , 'false' ) ;
99
151
100
- cy . visit ( `http://localhost:5601${ basePath } /app/opensearch_dashboards_overview` , {
101
- failOnStatusCode : false ,
102
- } ) ;
103
-
104
- samlLogin ( ) ;
152
+ if ( Cypress . env ( 'loginMethod' ) === 'saml_multiauth' ) {
153
+ cy . visit ( `http://localhost:5601${ basePath } /app/opensearch_dashboards_overview` , {
154
+ failOnStatusCode : false ,
155
+ } ) ;
156
+ loginWithSamlMultiauth ( ) ;
157
+ } else {
158
+ cy . origin ( 'http://localhost:7000' , { args : { basePath } } , ( { basePath } ) => {
159
+ cy . visit ( `http://localhost:5601${ basePath } /app/opensearch_dashboards_overview` , {
160
+ failOnStatusCode : false ,
161
+ } ) ;
162
+ cy . get ( 'input[id=userName]' ) . should ( 'be.visible' ) ;
163
+ cy . get ( 'button[id=btn-sign-in]' ) . should ( 'be.visible' ) . click ( ) ;
164
+ } ) ;
165
+ }
105
166
106
167
cy . get ( '#private' ) . should ( 'be.enabled' ) ;
107
168
cy . get ( '#private' ) . click ( { force : true } ) ;
@@ -114,7 +175,20 @@ describe('Log in via SAML', () => {
114
175
115
176
cy . get ( 'button[data-test-subj^="log-out-"]' ) . click ( ) ;
116
177
117
- samlLogin ( ) ;
178
+ if ( Cypress . env ( 'loginMethod' ) === 'saml_multiauth' ) {
179
+ cy . visit ( `http://localhost:5601${ basePath } /app/opensearch_dashboards_overview` , {
180
+ failOnStatusCode : false ,
181
+ } ) ;
182
+ loginWithSamlMultiauth ( ) ;
183
+ } else {
184
+ cy . origin ( 'http://localhost:7000' , { args : { basePath } } , ( { basePath } ) => {
185
+ cy . visit ( `http://localhost:5601${ basePath } /app/opensearch_dashboards_overview` , {
186
+ failOnStatusCode : false ,
187
+ } ) ;
188
+ cy . get ( 'input[id=userName]' ) . should ( 'be.visible' ) ;
189
+ cy . get ( 'button[id=btn-sign-in]' ) . should ( 'be.visible' ) . click ( ) ;
190
+ } ) ;
191
+ }
118
192
119
193
cy . get ( '#user-icon-btn' ) . should ( 'be.visible' ) ;
120
194
cy . get ( '#user-icon-btn' ) . click ( ) ;
@@ -131,8 +205,20 @@ describe('Log in via SAML', () => {
131
205
// since the Shorten URL api is return's set-cookie header for admin user.
132
206
cy . clearCookies ( ) . then ( ( ) => {
133
207
const gotoUrl = `http://localhost:5601${ basePath } /goto/${ response . urlId } ?security_tenant=global` ;
134
- cy . visit ( gotoUrl ) ;
135
- samlLogin ( ) ;
208
+ if ( Cypress . env ( 'loginMethod' ) === 'saml_multiauth' ) {
209
+ cy . visit ( gotoUrl , {
210
+ failOnStatusCode : false ,
211
+ } ) ;
212
+ loginWithSamlMultiauth ( ) ;
213
+ } else {
214
+ cy . origin ( 'http://localhost:7000' , { args : { gotoUrl } } , ( { gotoUrl } ) => {
215
+ cy . visit ( gotoUrl , {
216
+ failOnStatusCode : false ,
217
+ } ) ;
218
+ cy . get ( 'input[id=userName]' ) . should ( 'be.visible' ) ;
219
+ cy . get ( 'button[id=btn-sign-in]' ) . should ( 'be.visible' ) . click ( ) ;
220
+ } ) ;
221
+ }
136
222
cy . getCookie ( 'security_authentication' ) . should ( 'exist' ) ;
137
223
} ) ;
138
224
} ) ;
0 commit comments