openstax_api 6.1.0 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/openstax/api/v1/api_controller.rb +7 -0
- data/lib/openstax/api/version.rb +1 -1
- data/spec/controllers/openstax/api/v1/api_controller_spec.rb +20 -9
- data/spec/dummy/app/controllers/api/v1/dummy_controller.rb +10 -0
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +3017 -33743
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dc286ebde4e9b6e9bf1a3f7efc08514e4f78610
|
4
|
+
data.tar.gz: a6be75bd1d025aabad6325fd0201778268e578fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35474cafc2e08ab2429623f923bf0c8df44261a597be93e205221d1630907f3d585da87ff198aa32766b9448636d50c67a12ba8cb127cac659b069aa2d479d83
|
7
|
+
data.tar.gz: 12ff60007d7e23858a7b9c8447b59a997adf4bbc95e60cdd9392181a08d27548f3be4324e69237ded06ad41b4efad54ba6e73cf97d1e22e6bff5d1f4c5065368
|
@@ -12,8 +12,14 @@ module OpenStax
|
|
12
12
|
|
13
13
|
respond_to :json
|
14
14
|
|
15
|
+
# after_filters are in place to make sure certain things are set how we
|
16
|
+
# want even if something else goes on during the request. These filters
|
17
|
+
# are also paired with before_filters in case an exception prevents
|
18
|
+
# normal action completion.
|
19
|
+
|
15
20
|
# Always force JSON requests and send the Date header in the response
|
16
21
|
before_filter :force_json_content_type
|
22
|
+
before_filter :set_date_header
|
17
23
|
after_filter :set_date_header
|
18
24
|
|
19
25
|
# Doorkeeper is used only if a token is present
|
@@ -24,6 +30,7 @@ module OpenStax
|
|
24
30
|
skip_before_filter :verify_authenticity_token, unless: :session_user?
|
25
31
|
skip_before_filter :verify_authenticity_token, only: :options
|
26
32
|
before_filter :set_cors_preflight_headers, only: :options
|
33
|
+
before_filter :set_cors_headers
|
27
34
|
after_filter :set_cors_headers
|
28
35
|
|
29
36
|
# Keep old current_user method so we can use it
|
data/lib/openstax/api/version.rb
CHANGED
@@ -22,7 +22,7 @@ module OpenStax
|
|
22
22
|
controller.doorkeeper_token = nil
|
23
23
|
controller.present_user = nil
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it 'has no human_user and no application' do
|
27
27
|
expect(controller.send :session_user?).to eq false
|
28
28
|
expect(controller.current_application).to be_nil
|
@@ -36,7 +36,7 @@ module OpenStax
|
|
36
36
|
controller.doorkeeper_token = nil
|
37
37
|
controller.present_user = user
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it 'has a human_user but no application' do
|
41
41
|
expect(controller.send :session_user?).to eq true
|
42
42
|
expect(controller.current_application).to be_nil
|
@@ -50,7 +50,7 @@ module OpenStax
|
|
50
50
|
controller.doorkeeper_token = doorkeeper_token
|
51
51
|
controller.present_user = nil
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it 'has a human_user from token and an application' do
|
55
55
|
allow(doorkeeper_token).to receive(:application).and_return(application)
|
56
56
|
allow(doorkeeper_token).to receive(:resource_owner_id).and_return(user.id)
|
@@ -67,7 +67,7 @@ module OpenStax
|
|
67
67
|
controller.doorkeeper_token = doorkeeper_token
|
68
68
|
controller.present_user = nil
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
it 'has an application but no human_user' do
|
72
72
|
allow(doorkeeper_token).to receive(:application).and_return(application)
|
73
73
|
allow(doorkeeper_token).to receive(:resource_owner_id).and_return(nil)
|
@@ -144,11 +144,21 @@ module OpenStax
|
|
144
144
|
end
|
145
145
|
after(:each) { OpenStax::Api.configuration.validate_cors_origin = nil }
|
146
146
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
147
|
+
context 'when configured proc is true' do
|
148
|
+
before(:each) do
|
149
|
+
@valid_origin = 'http://good-host'
|
150
|
+
@request.headers['HTTP_ORIGIN'] = @valid_origin
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'sets the origin to whatever was reqeusted' do
|
154
|
+
get 'dummy'
|
155
|
+
expect(response.headers['Access-Control-Allow-Origin']).to eq @valid_origin
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'sets the origin to whatever was requested even if there was an exception raised' do
|
159
|
+
get 'explode'
|
160
|
+
expect(response.headers['Access-Control-Allow-Origin']).to eq @valid_origin
|
161
|
+
end
|
152
162
|
end
|
153
163
|
|
154
164
|
it 'clears the headers if the configured proc is falsy' do
|
@@ -158,6 +168,7 @@ module OpenStax
|
|
158
168
|
expect(response.headers['Access-Control-Allow-Origin']).to eq ''
|
159
169
|
end
|
160
170
|
|
171
|
+
|
161
172
|
end
|
162
173
|
|
163
174
|
end
|
@@ -1,12 +1,22 @@
|
|
1
1
|
module Api
|
2
2
|
module V1
|
3
3
|
|
4
|
+
class DummyControllerError < StandardError; end
|
5
|
+
|
4
6
|
class DummyController < OpenStax::Api::V1::ApiController
|
5
7
|
|
8
|
+
rescue_from DummyControllerError do |e|
|
9
|
+
render nothing: true, status: 500
|
10
|
+
end
|
11
|
+
|
6
12
|
def dummy
|
7
13
|
head(:ok)
|
8
14
|
end
|
9
15
|
|
16
|
+
def explode
|
17
|
+
raise DummyControllerError, "kaboom"
|
18
|
+
end
|
19
|
+
|
10
20
|
end
|
11
21
|
|
12
22
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|