openstax_api 8.3.1 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/controllers/openstax/api/v1/api_controller.rb +17 -12
- data/lib/openstax/api/engine.rb +2 -0
- data/lib/openstax/api/roar.rb +24 -19
- data/lib/openstax/api/rspec_helpers.rb +41 -42
- data/lib/openstax/api/version.rb +1 -1
- metadata +31 -162
- data/spec/controllers/openstax/api/v1/api_controller_spec.rb +0 -176
- data/spec/dummy/README.md +0 -1
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/api/v1/dummy_controller.rb +0 -23
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/user.rb +0 -2
- data/spec/dummy/app/representers/user_representer.rb +0 -13
- data/spec/dummy/app/representers/user_search_representer.rb +0 -5
- data/spec/dummy/app/routines/search_users.rb +0 -42
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -23
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -7
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -78
- data/spec/dummy/config/environments/test.rb +0 -39
- data/spec/dummy/config/initializers/assets.rb +0 -8
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -75
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/openstax_api.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -6
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/0_create_doorkeeper_tables.rb +0 -42
- data/spec/dummy/db/migrate/1_create_users.rb +0 -16
- data/spec/dummy/db/schema.rb +0 -68
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/controller_includes.rb +0 -3
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/user.rb +0 -8
- data/spec/lib/openstax/api/apipie_spec.rb +0 -15
- data/spec/lib/openstax/api/constraints_spec.rb +0 -84
- data/spec/lib/openstax/api/doorkeeper_application_includes_spec.rb +0 -17
- data/spec/lib/openstax/api/params_spec.rb +0 -78
- data/spec/lib/openstax/api/representable_schema_printer_spec.rb +0 -27
- data/spec/lib/openstax/api/roar_spec.rb +0 -45
- data/spec/lib/openstax/api/routing_mapper_includes_spec.rb +0 -20
- data/spec/lib/openstax_api_spec.rb +0 -19
- data/spec/models/openstax/api/api_user_spec.rb +0 -47
- data/spec/rails_helper.rb +0 -54
- data/spec/representers/openstax/api/v1/abstract_search_representer_spec.rb +0 -144
- data/spec/spec_helper.rb +0 -86
@@ -1,176 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Api
|
5
|
-
module V1
|
6
|
-
describe ApiController do
|
7
|
-
|
8
|
-
let!(:user) { FactoryBot.create :user }
|
9
|
-
let!(:user_2) { FactoryBot.create :user }
|
10
|
-
let!(:application) { double('Doorkeeper::Application') }
|
11
|
-
let!(:doorkeeper_token) { double('Doorkeeper::AccessToken') }
|
12
|
-
let!(:non_doorkeeper_user_proc) { lambda { user } }
|
13
|
-
let!(:controller) { ApiController.new }
|
14
|
-
let!(:dummy_controller) {
|
15
|
-
c = ::Api::V1::DummyController.new
|
16
|
-
c.response = ActionDispatch::TestResponse.new
|
17
|
-
c
|
18
|
-
}
|
19
|
-
|
20
|
-
context 'no authentication' do
|
21
|
-
before (:each) do
|
22
|
-
controller.doorkeeper_token = nil
|
23
|
-
controller.present_user = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'has no human_user and no application' do
|
27
|
-
expect(controller.send :session_user?).to eq false
|
28
|
-
expect(controller.current_application).to be_nil
|
29
|
-
expect(controller.current_human_user).to be_nil
|
30
|
-
expect(controller.current_session_user).to be_nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'session' do
|
35
|
-
before (:each) do
|
36
|
-
controller.doorkeeper_token = nil
|
37
|
-
controller.present_user = user
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'has a human_user but no application' do
|
41
|
-
expect(controller.send :session_user?).to eq true
|
42
|
-
expect(controller.current_application).to be_nil
|
43
|
-
expect(controller.current_human_user).to eq user
|
44
|
-
expect(controller.current_session_user).to eq user
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'token with application and human user' do
|
49
|
-
before (:each) do
|
50
|
-
controller.doorkeeper_token = doorkeeper_token
|
51
|
-
controller.present_user = nil
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'has a human_user from token and an application' do
|
55
|
-
allow(doorkeeper_token).to receive(:application).and_return(application)
|
56
|
-
allow(doorkeeper_token).to receive(:resource_owner_id).and_return(user.id)
|
57
|
-
|
58
|
-
expect(controller.send :session_user?).to eq false
|
59
|
-
expect(controller.current_application).to eq application
|
60
|
-
expect(controller.current_human_user).to eq user
|
61
|
-
expect(controller.current_session_user).to be_nil
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'token with application only' do
|
66
|
-
before (:each) do
|
67
|
-
controller.doorkeeper_token = doorkeeper_token
|
68
|
-
controller.present_user = nil
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'has an application but no human_user' do
|
72
|
-
allow(doorkeeper_token).to receive(:application).and_return(application)
|
73
|
-
allow(doorkeeper_token).to receive(:resource_owner_id).and_return(nil)
|
74
|
-
|
75
|
-
expect(controller.send :session_user?).to eq false
|
76
|
-
expect(controller.current_application).to eq application
|
77
|
-
expect(controller.current_human_user).to eq nil
|
78
|
-
expect(controller.current_session_user).to eq nil
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'session and token' do
|
83
|
-
before (:each) do
|
84
|
-
controller.doorkeeper_token = doorkeeper_token
|
85
|
-
controller.present_user = user_2
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'ignores the session unless explicitly asked' do
|
89
|
-
allow(doorkeeper_token).to receive(:application).and_return(application)
|
90
|
-
allow(doorkeeper_token).to receive(:resource_owner_id).and_return(user)
|
91
|
-
|
92
|
-
expect(controller.send :session_user?).to eq false
|
93
|
-
expect(controller.current_application).to eq application
|
94
|
-
expect(controller.current_human_user).to eq user
|
95
|
-
expect(controller.current_session_user).to eq user_2
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'date' do
|
100
|
-
before(:each) do
|
101
|
-
instance_variable_set('@controller', dummy_controller)
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'sets the Date header for successful API calls' do
|
105
|
-
@controller.present_user = user
|
106
|
-
get 'dummy'
|
107
|
-
expect(Time.parse(response.headers['Date'])).to be_within(1.second).of(Time.now)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'cors without origin configured' do
|
112
|
-
before(:each) do
|
113
|
-
instance_variable_set('@controller', dummy_controller)
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'sets the CORS headers for anonymous users' do
|
117
|
-
get 'dummy'
|
118
|
-
expect(response.headers['Access-Control-Allow-Origin']).to be_nil
|
119
|
-
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'sets the CORS headers for token users' do
|
123
|
-
token = Doorkeeper::AccessToken.create!.token
|
124
|
-
@request.headers['Authorization'] = "Bearer #{token}"
|
125
|
-
get 'dummy'
|
126
|
-
expect(response.headers['Access-Control-Allow-Origin']).to be_nil
|
127
|
-
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'sets the CORS headers for session users (the browser should block the request due to no Access-Control-Allow-Credentials header)' do
|
131
|
-
@controller.present_user = user
|
132
|
-
get 'dummy'
|
133
|
-
expect(response.headers['Access-Control-Allow-Origin']).to be_nil
|
134
|
-
expect(response.headers['Access-Control-Allow-Credentials']).to be_nil
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'cors with origin configured' do
|
139
|
-
before(:each) do
|
140
|
-
instance_variable_set('@controller', dummy_controller)
|
141
|
-
OpenStax::Api.configuration.validate_cors_origin = lambda{ |request|
|
142
|
-
request.headers["HTTP_ORIGIN"] == @valid_origin
|
143
|
-
}
|
144
|
-
end
|
145
|
-
after(:each) { OpenStax::Api.configuration.validate_cors_origin = nil }
|
146
|
-
|
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
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'clears the headers if the configured proc is falsy' do
|
165
|
-
@valid_origin = 'http://good-host'
|
166
|
-
@request.headers['HTTP_ORIGIN'] = 'http://evil-host'
|
167
|
-
get 'dummy'
|
168
|
-
expect(response.headers['Access-Control-Allow-Origin']).to eq ''
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
data/spec/dummy/README.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Dummy application used to test the openstax_api gem.
|
data/spec/dummy/Rakefile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require_tree .
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
-
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
-
* file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Api
|
2
|
-
module V1
|
3
|
-
|
4
|
-
class DummyControllerError < StandardError; end
|
5
|
-
|
6
|
-
class DummyController < OpenStax::Api::V1::ApiController
|
7
|
-
|
8
|
-
rescue_from DummyControllerError do |e|
|
9
|
-
render nothing: true, status: 500
|
10
|
-
end
|
11
|
-
|
12
|
-
def dummy
|
13
|
-
head(:ok)
|
14
|
-
end
|
15
|
-
|
16
|
-
def explode
|
17
|
-
raise DummyControllerError, "kaboom"
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'representable/json'
|
2
|
-
|
3
|
-
class UserRepresenter < Roar::Decorator
|
4
|
-
|
5
|
-
include Roar::JSON
|
6
|
-
|
7
|
-
property :unused, as: :username, readable: false, writeable: false,
|
8
|
-
schema_info: { required: true }
|
9
|
-
property :name, readable: true, writeable: true
|
10
|
-
property :email, readable: false, writeable: true
|
11
|
-
property :password_hash, readable: false, writeable: false
|
12
|
-
|
13
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# Dummy routine for testing the abstract search representer
|
2
|
-
|
3
|
-
class SearchUsers
|
4
|
-
|
5
|
-
lev_routine
|
6
|
-
|
7
|
-
uses_routine OSU::SearchAndOrganizeRelation,
|
8
|
-
as: :search,
|
9
|
-
translations: { outputs: { type: :verbatim } }
|
10
|
-
|
11
|
-
SORTABLE_FIELDS = {
|
12
|
-
'name' => :name,
|
13
|
-
'created_at' => :created_at
|
14
|
-
}
|
15
|
-
|
16
|
-
protected
|
17
|
-
|
18
|
-
def exec(params = {})
|
19
|
-
run(:search, relation: User.unscoped,
|
20
|
-
sortable_fields: SORTABLE_FIELDS,
|
21
|
-
params: params) do |with|
|
22
|
-
with.keyword :username do |names|
|
23
|
-
snames = to_string_array(names, append_wildcard: true)
|
24
|
-
next @items = @items.none if snames.empty?
|
25
|
-
@items = @items.where{username.like_any snames}
|
26
|
-
end
|
27
|
-
|
28
|
-
with.keyword :first_name do |names|
|
29
|
-
snames = to_string_array(names, append_wildcard: true)
|
30
|
-
next @items = @items.none if snames.empty?
|
31
|
-
@items = @items.where{name.like_any snames}
|
32
|
-
end
|
33
|
-
|
34
|
-
with.keyword :last_name do |names|
|
35
|
-
snames = to_string_array(names, append_wildcard: true)
|
36
|
-
.collect{|name| "% #{name}"}
|
37
|
-
next @items = @items.none if snames.empty?
|
38
|
-
@items = @items.where{name.like_any snames}
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Dummy</title>
|
5
|
-
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
-
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<%= yield %>
|
12
|
-
|
13
|
-
</body>
|
14
|
-
</html>
|
data/spec/dummy/bin/bundle
DELETED
data/spec/dummy/bin/rails
DELETED
data/spec/dummy/bin/rake
DELETED
data/spec/dummy/config.ru
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
2
|
-
|
3
|
-
require 'rails/all'
|
4
|
-
|
5
|
-
Bundler.require(*Rails.groups)
|
6
|
-
require "openstax_api"
|
7
|
-
|
8
|
-
module Dummy
|
9
|
-
class Application < Rails::Application
|
10
|
-
# Settings in config/environments/* take precedence over those specified here.
|
11
|
-
# Application configuration should go into files in config/initializers
|
12
|
-
# -- all .rb files in that directory are automatically loaded.
|
13
|
-
|
14
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
-
|
18
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
-
# config.i18n.default_locale = :de
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
data/spec/dummy/config/boot.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# SQLite version 3.x
|
2
|
-
# gem install sqlite3
|
3
|
-
#
|
4
|
-
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
-
# gem 'sqlite3'
|
6
|
-
#
|
7
|
-
default: &default
|
8
|
-
adapter: sqlite3
|
9
|
-
pool: 5
|
10
|
-
timeout: 5000
|
11
|
-
|
12
|
-
development:
|
13
|
-
<<: *default
|
14
|
-
database: db/development.sqlite3
|
15
|
-
|
16
|
-
# Warning: The database defined as "test" will be erased and
|
17
|
-
# re-generated from your development database when you run "rake".
|
18
|
-
# Do not set this db to the same as development or production.
|
19
|
-
test:
|
20
|
-
<<: *default
|
21
|
-
database: db/test.sqlite3
|
22
|
-
|
23
|
-
production:
|
24
|
-
<<: *default
|
25
|
-
database: db/production.sqlite3
|
@@ -1,37 +0,0 @@
|
|
1
|
-
Rails.application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
-
|
4
|
-
# In the development environment your application's code is reloaded on
|
5
|
-
# every request. This slows down response time but is perfect for development
|
6
|
-
# since you don't have to restart the web server when you make code changes.
|
7
|
-
config.cache_classes = false
|
8
|
-
|
9
|
-
# Do not eager load code on boot.
|
10
|
-
config.eager_load = false
|
11
|
-
|
12
|
-
# Show full error reports and disable caching.
|
13
|
-
config.consider_all_requests_local = true
|
14
|
-
config.action_controller.perform_caching = false
|
15
|
-
|
16
|
-
# Don't care if the mailer can't send.
|
17
|
-
config.action_mailer.raise_delivery_errors = false
|
18
|
-
|
19
|
-
# Print deprecation notices to the Rails logger.
|
20
|
-
config.active_support.deprecation = :log
|
21
|
-
|
22
|
-
# Raise an error on page load if there are pending migrations.
|
23
|
-
config.active_record.migration_error = :page_load
|
24
|
-
|
25
|
-
# Debug mode disables concatenation and preprocessing of assets.
|
26
|
-
# This option may cause significant delays in view rendering with a large
|
27
|
-
# number of complex assets.
|
28
|
-
config.assets.debug = true
|
29
|
-
|
30
|
-
# Adds additional error checking when serving assets at runtime.
|
31
|
-
# Checks for improperly declared sprockets dependencies.
|
32
|
-
# Raises helpful error messages.
|
33
|
-
config.assets.raise_runtime_errors = true
|
34
|
-
|
35
|
-
# Raises error for missing translations
|
36
|
-
# config.action_view.raise_on_missing_translations = true
|
37
|
-
end
|