openstax_api 8.3.1 → 9.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/dummy/db/test.sqlite3
DELETED
Binary file
|
data/spec/dummy/public/404.html
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
background-color: #EFEFEF;
|
9
|
-
color: #2E2F30;
|
10
|
-
text-align: center;
|
11
|
-
font-family: arial, sans-serif;
|
12
|
-
margin: 0;
|
13
|
-
}
|
14
|
-
|
15
|
-
div.dialog {
|
16
|
-
width: 95%;
|
17
|
-
max-width: 33em;
|
18
|
-
margin: 4em auto 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.dialog > div {
|
22
|
-
border: 1px solid #CCC;
|
23
|
-
border-right-color: #999;
|
24
|
-
border-left-color: #999;
|
25
|
-
border-bottom-color: #BBB;
|
26
|
-
border-top: #B00100 solid 4px;
|
27
|
-
border-top-left-radius: 9px;
|
28
|
-
border-top-right-radius: 9px;
|
29
|
-
background-color: white;
|
30
|
-
padding: 7px 12% 0;
|
31
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
-
}
|
33
|
-
|
34
|
-
h1 {
|
35
|
-
font-size: 100%;
|
36
|
-
color: #730E15;
|
37
|
-
line-height: 1.5em;
|
38
|
-
}
|
39
|
-
|
40
|
-
div.dialog > p {
|
41
|
-
margin: 0 0 1em;
|
42
|
-
padding: 1em;
|
43
|
-
background-color: #F7F7F7;
|
44
|
-
border: 1px solid #CCC;
|
45
|
-
border-right-color: #999;
|
46
|
-
border-left-color: #999;
|
47
|
-
border-bottom-color: #999;
|
48
|
-
border-bottom-left-radius: 4px;
|
49
|
-
border-bottom-right-radius: 4px;
|
50
|
-
border-top-color: #DADADA;
|
51
|
-
color: #666;
|
52
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
-
}
|
54
|
-
</style>
|
55
|
-
</head>
|
56
|
-
|
57
|
-
<body>
|
58
|
-
<!-- This file lives in public/404.html -->
|
59
|
-
<div class="dialog">
|
60
|
-
<div>
|
61
|
-
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
-
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
-
</div>
|
64
|
-
<p>If you are the application owner check the logs for more information.</p>
|
65
|
-
</div>
|
66
|
-
</body>
|
67
|
-
</html>
|
data/spec/dummy/public/422.html
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The change you wanted was rejected (422)</title>
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
background-color: #EFEFEF;
|
9
|
-
color: #2E2F30;
|
10
|
-
text-align: center;
|
11
|
-
font-family: arial, sans-serif;
|
12
|
-
margin: 0;
|
13
|
-
}
|
14
|
-
|
15
|
-
div.dialog {
|
16
|
-
width: 95%;
|
17
|
-
max-width: 33em;
|
18
|
-
margin: 4em auto 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.dialog > div {
|
22
|
-
border: 1px solid #CCC;
|
23
|
-
border-right-color: #999;
|
24
|
-
border-left-color: #999;
|
25
|
-
border-bottom-color: #BBB;
|
26
|
-
border-top: #B00100 solid 4px;
|
27
|
-
border-top-left-radius: 9px;
|
28
|
-
border-top-right-radius: 9px;
|
29
|
-
background-color: white;
|
30
|
-
padding: 7px 12% 0;
|
31
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
-
}
|
33
|
-
|
34
|
-
h1 {
|
35
|
-
font-size: 100%;
|
36
|
-
color: #730E15;
|
37
|
-
line-height: 1.5em;
|
38
|
-
}
|
39
|
-
|
40
|
-
div.dialog > p {
|
41
|
-
margin: 0 0 1em;
|
42
|
-
padding: 1em;
|
43
|
-
background-color: #F7F7F7;
|
44
|
-
border: 1px solid #CCC;
|
45
|
-
border-right-color: #999;
|
46
|
-
border-left-color: #999;
|
47
|
-
border-bottom-color: #999;
|
48
|
-
border-bottom-left-radius: 4px;
|
49
|
-
border-bottom-right-radius: 4px;
|
50
|
-
border-top-color: #DADADA;
|
51
|
-
color: #666;
|
52
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
-
}
|
54
|
-
</style>
|
55
|
-
</head>
|
56
|
-
|
57
|
-
<body>
|
58
|
-
<!-- This file lives in public/422.html -->
|
59
|
-
<div class="dialog">
|
60
|
-
<div>
|
61
|
-
<h1>The change you wanted was rejected.</h1>
|
62
|
-
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
-
</div>
|
64
|
-
<p>If you are the application owner check the logs for more information.</p>
|
65
|
-
</div>
|
66
|
-
</body>
|
67
|
-
</html>
|
data/spec/dummy/public/500.html
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>We're sorry, but something went wrong (500)</title>
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
background-color: #EFEFEF;
|
9
|
-
color: #2E2F30;
|
10
|
-
text-align: center;
|
11
|
-
font-family: arial, sans-serif;
|
12
|
-
margin: 0;
|
13
|
-
}
|
14
|
-
|
15
|
-
div.dialog {
|
16
|
-
width: 95%;
|
17
|
-
max-width: 33em;
|
18
|
-
margin: 4em auto 0;
|
19
|
-
}
|
20
|
-
|
21
|
-
div.dialog > div {
|
22
|
-
border: 1px solid #CCC;
|
23
|
-
border-right-color: #999;
|
24
|
-
border-left-color: #999;
|
25
|
-
border-bottom-color: #BBB;
|
26
|
-
border-top: #B00100 solid 4px;
|
27
|
-
border-top-left-radius: 9px;
|
28
|
-
border-top-right-radius: 9px;
|
29
|
-
background-color: white;
|
30
|
-
padding: 7px 12% 0;
|
31
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
-
}
|
33
|
-
|
34
|
-
h1 {
|
35
|
-
font-size: 100%;
|
36
|
-
color: #730E15;
|
37
|
-
line-height: 1.5em;
|
38
|
-
}
|
39
|
-
|
40
|
-
div.dialog > p {
|
41
|
-
margin: 0 0 1em;
|
42
|
-
padding: 1em;
|
43
|
-
background-color: #F7F7F7;
|
44
|
-
border: 1px solid #CCC;
|
45
|
-
border-right-color: #999;
|
46
|
-
border-left-color: #999;
|
47
|
-
border-bottom-color: #999;
|
48
|
-
border-bottom-left-radius: 4px;
|
49
|
-
border-bottom-right-radius: 4px;
|
50
|
-
border-top-color: #DADADA;
|
51
|
-
color: #666;
|
52
|
-
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
-
}
|
54
|
-
</style>
|
55
|
-
</head>
|
56
|
-
|
57
|
-
<body>
|
58
|
-
<!-- This file lives in public/500.html -->
|
59
|
-
<div class="dialog">
|
60
|
-
<div>
|
61
|
-
<h1>We're sorry, but something went wrong.</h1>
|
62
|
-
</div>
|
63
|
-
<p>If you are the application owner check the logs for more information.</p>
|
64
|
-
</div>
|
65
|
-
</body>
|
66
|
-
</html>
|
File without changes
|
data/spec/factories/user.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Api
|
5
|
-
module V1
|
6
|
-
describe Apipie do
|
7
|
-
it 'adds methods to ApiController class' do
|
8
|
-
expect(OpenStax::Api::V1::ApiController).to respond_to(:api_example)
|
9
|
-
expect(OpenStax::Api::V1::ApiController).to respond_to(:json_schema)
|
10
|
-
expect(OpenStax::Api::V1::ApiController).to respond_to(:representer)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Api
|
5
|
-
describe Constraints do
|
6
|
-
context 'default is not defined' do
|
7
|
-
let!(:constraints) { Constraints.new(version: :v1) }
|
8
|
-
let(:req) { double('Request') }
|
9
|
-
|
10
|
-
it 'matches if version is correct in the accept headers' do
|
11
|
-
allow(req).to receive(:headers).and_return({
|
12
|
-
'Accept' => 'application/vnd.openstax.v1'
|
13
|
-
})
|
14
|
-
expect(constraints.matches? req).to eq true
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'does not match if version is incorrect in the accept headers' do
|
18
|
-
allow(req).to receive(:headers).and_return({
|
19
|
-
'Accept' => 'application/vnd.openstax.v2'
|
20
|
-
})
|
21
|
-
expect(constraints.matches? req).to eq false
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'does not match if version is not defined in the accept headers' do
|
25
|
-
allow(req).to receive(:headers).and_return({
|
26
|
-
'Accept' => '*/*',
|
27
|
-
})
|
28
|
-
expect(constraints.matches? req).to eq false
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'does not match if accept is not in headers' do
|
32
|
-
allow(req).to receive(:headers).and_return({
|
33
|
-
'Host' => 'localhost'
|
34
|
-
})
|
35
|
-
expect(constraints.matches? req).to eq false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'default is defined' do
|
40
|
-
let!(:constraints) { Constraints.new(version: :v1) }
|
41
|
-
let!(:constraints_2) { Constraints.new(version: :v2, default: true) }
|
42
|
-
let(:req) { double('Request') }
|
43
|
-
|
44
|
-
it 'matches if version is correct in the accept headers or if default' do
|
45
|
-
allow(req).to receive(:headers).and_return({
|
46
|
-
'Accept' => 'application/vnd.openstax.v1'
|
47
|
-
})
|
48
|
-
expect(constraints.matches? req).to eq true
|
49
|
-
expect(constraints_2.matches? req).to eq true
|
50
|
-
|
51
|
-
allow(req).to receive(:headers).and_return({
|
52
|
-
'Accept' => 'application/vnd.openstax.v2'
|
53
|
-
})
|
54
|
-
expect(constraints.matches? req).to eq false
|
55
|
-
expect(constraints_2.matches? req).to eq true
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'matches if version is invalid' do
|
59
|
-
allow(req).to receive(:headers).and_return({
|
60
|
-
'Accept' => 'application/vnd.openstax.v3'
|
61
|
-
})
|
62
|
-
expect(constraints.matches? req).to eq false
|
63
|
-
expect(constraints_2.matches? req).to eq true
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'matches if version is not defined in the accept headers' do
|
67
|
-
allow(req).to receive(:headers).and_return({
|
68
|
-
'Accept' => '*/*',
|
69
|
-
})
|
70
|
-
expect(constraints.matches? req).to eq false
|
71
|
-
expect(constraints_2.matches? req).to eq true
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'matches if accept is not in headers' do
|
75
|
-
allow(req).to receive(:headers).and_return({
|
76
|
-
'Host' => 'localhost'
|
77
|
-
})
|
78
|
-
expect(constraints.matches? req).to eq false
|
79
|
-
expect(constraints_2.matches? req).to eq true
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Api
|
5
|
-
describe DoorkeeperApplicationIncludes do
|
6
|
-
it 'must add methods to Doorkeeper::Application' do
|
7
|
-
application = Doorkeeper::Application.new
|
8
|
-
expect(application).to respond_to(:is_human?)
|
9
|
-
expect(application.is_human?).to eq(false)
|
10
|
-
expect(application).to respond_to(:is_application?)
|
11
|
-
expect(application.is_application?).to eq(true)
|
12
|
-
expect(application).to respond_to(:is_admin?)
|
13
|
-
expect(application.is_admin?).to eq(false)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'rails_helper'
|
3
|
-
|
4
|
-
module OpenStax
|
5
|
-
module Api
|
6
|
-
describe Params do
|
7
|
-
|
8
|
-
let(:params) { {a: '1', b: 2, c: nil, d: '', e: '♥', f: true} }
|
9
|
-
let(:signed) { described_class.sign(params: params, secret: 'secret') }
|
10
|
-
|
11
|
-
it 'disallows blank secrets' do
|
12
|
-
expect{
|
13
|
-
described_class.sign(params: {}, secret: nil)
|
14
|
-
}.to raise_error(StandardError)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'signs and verifies' do
|
18
|
-
expect(signed[:timestamp]).not_to be_blank
|
19
|
-
expect(signed[:signature]).not_to be_blank
|
20
|
-
|
21
|
-
expect(
|
22
|
-
described_class.signature_and_timestamp_valid?(params: signed, secret: 'secret')
|
23
|
-
).to eq true
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'does not verify is signature does not match' do
|
27
|
-
signed[:signature] += "a"
|
28
|
-
expect(
|
29
|
-
described_class.signature_and_timestamp_valid?(params: signed, secret: 'secret')
|
30
|
-
).to eq false
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'does not verify if signature blank' do
|
34
|
-
signed[:signature] = " "
|
35
|
-
expect(
|
36
|
-
described_class.signature_and_timestamp_valid?(params: signed, secret: 'secret')
|
37
|
-
).to eq false
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "altered params" do
|
41
|
-
|
42
|
-
it 'rejects additions' do
|
43
|
-
expect(
|
44
|
-
described_class.signature_and_timestamp_valid?(
|
45
|
-
params: signed.merge(evil: 'yes'),
|
46
|
-
secret: 'secret')
|
47
|
-
).to eq false
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'rejects alterations' do
|
51
|
-
expect(
|
52
|
-
described_class.signature_and_timestamp_valid?(
|
53
|
-
params: signed.merge(b: 10000),
|
54
|
-
secret: 'secret')
|
55
|
-
).to eq false
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'rejects deletions' do
|
59
|
-
expect(
|
60
|
-
described_class.signature_and_timestamp_valid?(
|
61
|
-
params: signed.except(:a),
|
62
|
-
secret: 'secret')
|
63
|
-
).to eq false
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'does not verify if timestamp too long ago' do
|
69
|
-
expect(
|
70
|
-
described_class.signature_and_timestamp_valid?(params: signed,
|
71
|
-
secret: 'secret',
|
72
|
-
timestamp_window_width: 0.minutes)
|
73
|
-
).to eq false
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Api
|
5
|
-
describe RepresentableSchemaPrinter do
|
6
|
-
it 'must print model schemas' do
|
7
|
-
schema = RepresentableSchemaPrinter.json(UserRepresenter)
|
8
|
-
expect(schema).to include('## Schema')
|
9
|
-
expect(schema).to include('{#')
|
10
|
-
expect(schema).to include(' .schema}')
|
11
|
-
expect(schema).to include("<pre class='code'>")
|
12
|
-
expect(schema).to include('</pre>')
|
13
|
-
json_schema = schema.match(/<pre class='code'>([^<]*)<\/pre>/)
|
14
|
-
expect(JSON.parse(json_schema[1])).to eq({
|
15
|
-
"type" => "object",
|
16
|
-
"required" => [ "username" ],
|
17
|
-
"properties" => {
|
18
|
-
"username" => { "type" => "string" },
|
19
|
-
"name" => { "type" => "string" },
|
20
|
-
"email" => { "type" => "string" }
|
21
|
-
},
|
22
|
-
"additionalProperties" => false
|
23
|
-
})
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|