File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33class AuthController < ApplicationController
44 ERR_TICKET_MISMATCH = 'Ticket from callback URL parameter does not match credential from OmniAuth hash' . freeze
55
6+ def failure
7+ error = {
8+ errors : [
9+ {
10+ status : '401' ,
11+ title : 'Authentication failed' ,
12+ detail : 'Authentication failed'
13+ }
14+ ]
15+ }
16+
17+ render json : error , status : :unauthorized , content_type : JSONAPI ::MEDIA_TYPE
18+ end
19+
620 def callback
721 logger . debug ( { msg : 'Received omniauth callback' , omniauth : auth_hash , params : params . to_unsafe_h } )
822
Original file line number Diff line number Diff line change 22
33 direct ( :login ) { '/auth/calnet' } # convenience to provide login_url helper
44 get '/logout' , to : 'auth#logout' , as : :logout
5+ get '/auth/failure' , to : 'auth#failure'
56 get '/auth/:provider/callback' , to : 'auth#callback' , as : :omniauth_callback
67
78 scope module : 'preview' do
Original file line number Diff line number Diff line change 4747 end
4848 end
4949
50+ describe 'GET /auth/failure' do
51+ it 'returns a JSON authentication failure response' do
52+ get '/auth/failure'
53+
54+ expect ( response ) . to have_http_status ( :unauthorized )
55+ expect ( response . content_type ) . to start_with ( JSONAPI ::MEDIA_TYPE )
56+
57+ parsed = JSON . parse ( response . body )
58+ expect ( parsed [ 'errors' ] . first [ 'detail' ] ) . to eq ( 'Authentication failed' )
59+ end
60+ end
61+
5062 # NOTE: In effect we're just testing omniauth-cas here, but with
5163 # app-specific configuration and CalNet-specific data, to
5264 # be completely sure we know what we're doing
You can’t perform that action at this time.
0 commit comments