@@ -248,8 +248,19 @@ context('multi-domain navigation', { experimentalSessionSupport: true }, () => {
248248 } )
249249 } )
250250
251- // TODO: un-skip once multiple remote states are supported
252- it . skip ( 'supports auth options and adding auth to subsequent requests' , ( ) => {
251+ // TODO: test currently fails when redirecting
252+ it . skip ( 'supports visit redirects' , ( ) => {
253+ cy . visit ( '/fixtures/multi-domain.html' )
254+ cy . get ( 'a[data-cy="dom-link"]' ) . click ( )
255+
256+ cy . switchToDomain ( 'http://www.foobar.com:3500' , ( ) => {
257+ cy . visit ( '/redirect?href=http://localhost:3500/fixtures/multi-domain-secondary.html' )
258+ } )
259+
260+ cy . get ( '[data-cy="dom-check"]' ) . should ( 'have.text' , 'From a secondary domain' )
261+ } )
262+
263+ it ( 'supports auth options and adding auth to subsequent requests' , ( ) => {
253264 cy . switchToDomain ( 'http://foobar.com:3500' , ( ) => {
254265 cy . visit ( 'http://www.foobar.com:3500/basic_auth' , {
255266 auth : {
@@ -260,26 +271,83 @@ context('multi-domain navigation', { experimentalSessionSupport: true }, () => {
260271
261272 cy . get ( 'body' ) . should ( 'have.text' , 'basic auth worked' )
262273
263- cy . window ( ) . then ( { timeout : 60000 } , ( win ) => {
264- return new Cypress . Promise ( ( ( resolve , reject ) => {
265- const xhr = new win . XMLHttpRequest ( )
274+ cy . window ( ) . then ( ( win ) => {
275+ win . location . href = 'http://www.foobar.com:3500/basic_auth'
276+ } )
277+
278+ cy . get ( 'body' ) . should ( 'have.text' , 'basic auth worked' )
279+ } )
280+
281+ // attaches the auth options for the foobar domain even from another switchToDomain
282+ cy . switchToDomain ( 'http://www.idp.com:3500' , ( ) => {
283+ cy . visit ( '/fixtures/multi-domain.html' )
284+
285+ cy . window ( ) . then ( ( win ) => {
286+ win . location . href = 'http://www.foobar.com:3500/basic_auth'
287+ } )
288+ } )
289+
290+ cy . switchToDomain ( 'http://foobar.com:3500' , ( ) => {
291+ cy . get ( 'body' ) . should ( 'have.text' , 'basic auth worked' )
292+ } )
293+
294+ cy . visit ( '/fixtures/multi-domain.html' )
295+
296+ // attaches the auth options for the foobar domain from the top-level
297+ cy . window ( ) . then ( ( win ) => {
298+ win . location . href = 'http://www.foobar.com:3500/basic_auth'
299+ } )
300+
301+ cy . switchToDomain ( 'http://foobar.com:3500' , ( ) => {
302+ cy . get ( 'body' ) . should ( 'have.text' , 'basic auth worked' )
303+ } )
304+ } )
266305
267- xhr . open ( 'GET' , '/basic_auth' )
268- xhr . onload = function ( ) {
269- try {
270- expect ( this . responseText ) . to . include ( 'basic auth worked' )
306+ it ( 'does not propagate the auth options across tests' , ( done ) => {
307+ cy . intercept ( '/basic_auth' , ( req ) => {
308+ req . on ( 'response' , ( res ) => {
309+ // clear the www-authenticate header so the browser doesn't prompt for username/password
310+ res . headers [ 'www-authenticate' ] = ''
311+ expect ( res . statusCode ) . to . equal ( 401 )
312+ done ( )
313+ } )
314+ } )
271315
272- return resolve ( win )
273- } catch ( err ) {
274- return reject ( err )
275- }
276- }
316+ cy . window ( ) . then ( ( win ) => {
317+ win . location . href = 'http://www.foobar.com:3500/fixtures/multi-domain.html'
318+ } )
277319
278- return xhr . send ( )
279- } ) )
320+ cy . switchToDomain ( 'http://foobar.com:3500' , ( ) => {
321+ cy . window ( ) . then ( ( win ) => {
322+ win . location . href = 'http://www.foobar.com:3500/basic_auth'
280323 } )
281324 } )
282325 } )
326+
327+ it ( 'succeeds when visiting local file server first' , { baseUrl : undefined } , ( ) => {
328+ cy . visit ( 'cypress/fixtures/multi-domain.html' )
329+
330+ cy . switchToDomain ( 'http://www.foobar.com:3500' , ( ) => {
331+ cy . visit ( '/fixtures/multi-domain-secondary.html' )
332+ cy . get ( '[data-cy="dom-check"]' ) . should ( 'have.text' , 'From a secondary domain' )
333+ } )
334+ } )
335+
336+ it ( 'handles visit failures' , { baseUrl : undefined } , ( done ) => {
337+ cy . on ( 'fail' , ( e ) => {
338+ expect ( e . message ) . to . include ( 'failed trying to load:\n\nhttp://www.foobar.com:3500/fixtures/multi-domain-secondary.html' )
339+ expect ( e . message ) . to . include ( '500: Internal Server Error' )
340+
341+ done ( )
342+ } )
343+
344+ cy . intercept ( '*/multi-domain-secondary.html' , { statusCode : 500 } )
345+
346+ cy . visit ( 'cypress/fixtures/multi-domain.html' )
347+ cy . switchToDomain ( 'http://www.foobar.com:3500' , ( ) => {
348+ cy . visit ( 'fixtures/multi-domain-secondary.html' )
349+ } )
350+ } )
283351 } )
284352
285353 it ( 'supports navigating through changing the window.location.href' , ( ) => {
0 commit comments