@@ -399,4 +399,64 @@ class OmniauthTest < ActionDispatch::IntegrationTest
399399 assert_response :not_found
400400 end
401401
402+ test 'authentication redirects users back to origin space on subdomain' do
403+ space = spaces ( :astro )
404+ space . update! ( host : 'space.example.com' )
405+
406+ OmniAuth . config . mock_auth [ :oidc ] = OmniAuth ::AuthHash . new (
407+ {
408+ provider : 'oidc' ,
409+ uid : '0123456789abcdcef' ,
410+ info : {
411+ email : 'aai@example.com' ,
412+ nickname : 'aaf_user' ,
413+ first_name : 'AAF' ,
414+ last_name : 'User'
415+ }
416+ } )
417+
418+ post user_oidc_omniauth_authorize_url ( space_id : space . id )
419+ follow_redirect! # OmniAuth redirect
420+ assert_equal "http://space.example.com/users/aaf_user/edit" , response . headers [ 'Location' ]
421+ end
422+
423+ test 'authentication does not redirect user to entirely different domain' do
424+ space = spaces ( :astro )
425+ space . update! ( host : 'my-cool-space-host.com' )
426+
427+ OmniAuth . config . mock_auth [ :oidc ] = OmniAuth ::AuthHash . new (
428+ {
429+ provider : 'oidc' ,
430+ uid : '0123456789abcdcef' ,
431+ info : {
432+ email : 'aai@example.com' ,
433+ nickname : 'aaf_user' ,
434+ first_name : 'AAF' ,
435+ last_name : 'User'
436+ }
437+ } )
438+
439+ post user_oidc_omniauth_authorize_url ( space_id : space . id )
440+ follow_redirect! # OmniAuth redirect
441+ assert_equal "http://www.example.com/users/aaf_user/edit" , response . headers [ 'Location' ]
442+ end
443+
444+ test 'invalid space is ignored when redirecting' do
445+ OmniAuth . config . mock_auth [ :oidc ] = OmniAuth ::AuthHash . new (
446+ {
447+ provider : 'oidc' ,
448+ uid : '0123456789abcdcef' ,
449+ info : {
450+ email : 'aai@example.com' ,
451+ nickname : 'aaf_user' ,
452+ first_name : 'AAF' ,
453+ last_name : 'User'
454+ }
455+ } )
456+
457+ post user_oidc_omniauth_authorize_url ( space_id : 'ufhgfsdkhgskdjfhsdkjfhsdkjfhsd' )
458+ follow_redirect! # OmniAuth redirect
459+ assert_equal "http://www.example.com/users/aaf_user/edit" , response . headers [ 'Location' ]
460+ end
461+
402462end
0 commit comments