File tree Expand file tree Collapse file tree 6 files changed +11
-32
lines changed Expand file tree Collapse file tree 6 files changed +11
-32
lines changed Original file line number Diff line number Diff line change 3
3
class AuthController < ApplicationController
4
4
ERR_TICKET_MISMATCH = 'Ticket from callback URL parameter does not match credential from OmniAuth hash' . freeze
5
5
6
- # Debug UI for staging, 404 Not Found for production
7
- def index
8
- raise Error ::NotFoundError if ENV [ 'SERVE_TEST_UI' ] . blank?
9
-
10
- redirect_to preview_path
11
- end
12
-
13
6
def callback
14
7
logger . debug ( { msg : 'Received omniauth callback' , omniauth : auth_hash , params : params . to_unsafe_h } )
15
8
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ module Preview
2
2
class PreviewController < Preview ::ApplicationController
3
3
4
4
def index
5
- @api_url = Rails . env . production? ? 'https://galc-api.ucblib.org' : 'http://localhost:3000'
5
+ @api_url = ENV [ 'GALC_API_URL' ] || 'http://localhost:3000'
6
6
end
7
7
end
8
8
end
Original file line number Diff line number Diff line change 1
1
Rails . application . routes . draw do
2
- root to : 'auth#index'
3
-
2
+
4
3
direct ( :login ) { '/auth/calnet' } # convenience to provide login_url helper
5
4
get '/logout' , to : 'auth#logout' , as : :logout
6
5
get '/auth/:provider/callback' , to : 'auth#callback' , as : :omniauth_callback
7
6
8
7
scope module : 'preview' do
9
8
constraints ( -> ( _ ) { ENV [ 'SERVE_TEST_UI' ] . present? } ) do
10
- get '/preview' , to : 'preview#index' , as : :preview
9
+ root to : 'preview#index' , as : :preview
11
10
end
12
11
end
13
12
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ services:
8
8
- db
9
9
environment :
10
10
- SERVE_TEST_UI=${SERVE_TEST_UI:-true}
11
+ - GALC_API_URL=${GALC_API_URL:-http://localhost:3000}
11
12
init : true
12
13
networks :
13
14
default :
Original file line number Diff line number Diff line change 39
39
# ------------------------------------------------------------
40
40
# Tests
41
41
42
- describe 'GET /' do
43
- it 'returns 404 Not Found' do
44
- allow ( ENV ) . to receive ( :[] ) . with ( 'SERVE_TEST_UI' ) . and_return ( nil )
45
- get root_path
46
- expect ( response ) . to have_http_status ( :not_found )
47
- end
48
-
49
- it 'redirects to a test UI in staging' do
50
- allow ( ENV ) . to receive ( :[] ) . with ( 'SERVE_TEST_UI' ) . and_return ( true )
51
-
52
- get root_path
53
- expect ( response ) . to redirect_to ( preview_path )
54
- end
55
- end
56
-
57
42
describe 'GET /auth/calnet' do
58
43
# See https://github.com/omniauth/omniauth/wiki/Resolving-CVE-2015-9284
59
44
it 'is disallowed' do
Original file line number Diff line number Diff line change 1
1
require 'rails_helper'
2
2
3
3
RSpec . describe Preview ::PreviewController , type : :request do
4
- describe 'GET /preview ' do
4
+ describe 'GET /' do
5
5
context 'with the preview environment enabled' do
6
6
before do
7
7
allow ( ENV ) . to receive ( :[] ) . with ( 'SERVE_TEST_UI' ) . and_return ( true )
8
8
end
9
9
10
10
it 'shows a test UI in when SERVE_TEST_UI is true' do
11
+ allow ( ENV ) . to receive ( :[] ) . with ( 'GALC_API_URL' ) . and_return ( 'https://galc.biz' )
11
12
get preview_path
12
13
expect ( response ) . to have_http_status ( :ok )
13
14
expect ( response . content_type ) . to start_with ( 'text/html' )
14
15
end
15
16
16
17
context 'sets the API URL correctly' do
17
- it 'sets the url for staging API in production ' do
18
- allow ( Rails . env ) . to receive ( :production? ) . and_return ( true )
18
+ it 'sets the url when GALC_API_URL is present ' do
19
+ allow ( ENV ) . to receive ( :[] ) . with ( 'GALC_API_URL' ) . and_return ( 'https://galc.biz' )
19
20
get preview_path
20
- expect ( assigns ( :api_url ) ) . to eq ( 'https://galc-api.ucblib.org ' )
21
+ expect ( assigns ( :api_url ) ) . to eq ( 'https://galc.biz ' )
21
22
end
22
23
23
- it 'sets the url for API to be localhost in dev/test ' do
24
- allow ( Rails . env ) . to receive ( :production? ) . and_return ( false )
24
+ it 'sets the API URL when GALC_API_URL is not present ' do
25
+ allow ( ENV ) . to receive ( :[] ) . with ( 'GALC_API_URL' ) . and_return ( nil )
25
26
get preview_path
26
27
expect ( assigns ( :api_url ) ) . to eq ( 'http://localhost:3000' )
27
28
end
You can’t perform that action at this time.
0 commit comments