panda_pal 5.18.2 → 5.19.0.beta2
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/README.md +39 -0
- data/app/controllers/panda_pal/lti_v1_p0_controller.rb +11 -4
- data/app/controllers/panda_pal/lti_v1_p3_controller.rb +17 -8
- data/app/lib/lti_xml/base_platform.rb +32 -18
- data/app/lib/lti_xml/bridge_platform.rb +2 -2
- data/app/lib/panda_pal/launch_url_helpers.rb +21 -14
- data/app/models/panda_pal/lti_registration.rb +41 -0
- data/app/models/panda_pal/organization.rb +2 -0
- data/app/models/panda_pal/platform/canvas.rb +88 -28
- data/app/models/panda_pal/session.rb +19 -1
- data/config/initializers/apartment.rb +1 -1
- data/db/migrate/20261006000000_create_panda_pal_lti_registrations.rb +14 -0
- data/db/migrate/20261006000001_add_tool_to_panda_pal_sessions.rb +5 -0
- data/lib/panda_pal/helpers/controller_helper.rb +20 -1
- data/lib/panda_pal/helpers/route_helper.rb +8 -1
- data/lib/panda_pal/helpers/session_replacement.rb +2 -2
- data/lib/panda_pal/version.rb +1 -1
- data/lib/panda_pal.rb +82 -10
- data/panda_pal.gemspec +2 -1
- metadata +19 -50
- data/spec/controllers/panda_pal/api_call_controller_spec.rb +0 -25
- data/spec/controllers/panda_pal/lti_v1_p0_controller_spec.rb +0 -110
- data/spec/controllers/panda_pal/lti_v1_p3_controller_spec.rb +0 -108
- data/spec/core/apartment_multidb_spec.rb +0 -166
- data/spec/factories/panda_pal_organizations.rb +0 -9
- data/spec/factories/panda_pal_sessions.rb +0 -6
- data/spec/internal/app/models/account.rb +0 -7
- data/spec/internal/app/models/admin.rb +0 -6
- data/spec/internal/config/database.yml +0 -18
- data/spec/internal/config/routes.rb +0 -5
- data/spec/internal/config/storage.yml +0 -3
- data/spec/internal/db/schema.rb +0 -30
- data/spec/jobs/panda_pal/jobs/grade_passback_job_spec.rb +0 -83
- data/spec/lib/panda_pal/ags_client_spec.rb +0 -385
- data/spec/lib/panda_pal/helpers/secure_headers_spec.rb +0 -77
- data/spec/lib/panda_pal/helpers/session_replacement_spec.rb +0 -72
- data/spec/models/panda_pal/api_call_spec.rb +0 -30
- data/spec/models/panda_pal/organization/settings_validation_spec.rb +0 -179
- data/spec/models/panda_pal/organization/task_scheduling_spec.rb +0 -145
- data/spec/models/panda_pal/organization_spec.rb +0 -50
- data/spec/models/panda_pal/platform_spec.rb +0 -349
- data/spec/models/panda_pal/session_account_roles_spec.rb +0 -182
- data/spec/models/panda_pal/session_spec.rb +0 -202
- data/spec/spec_helper.rb +0 -158
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module PandaPal
|
|
4
|
-
RSpec.describe Session, type: :model do
|
|
5
|
-
it 'is initialized with a session_secret' do
|
|
6
|
-
expect(PandaPal::Session.new.session_secret).to_not be_nil
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe '#dup' do
|
|
10
|
-
# Mirrors validate_v1p3_launch: load the login session, delete it, dup it into
|
|
11
|
-
# the org's tenant. Only fails on Rails 8.0 with partial_inserts left on, so it
|
|
12
|
-
# is the appraisal run that gates this, not the default (Rails 8.1) lockfile.
|
|
13
|
-
it 'persists every attribute, including session_secret, on the duped record' do
|
|
14
|
-
original = PandaPal::Session.find(create(:panda_pal_session).id)
|
|
15
|
-
original_secret = original.session_secret
|
|
16
|
-
original.delete
|
|
17
|
-
|
|
18
|
-
with_partial_inserts(true) do
|
|
19
|
-
duped = original.dup
|
|
20
|
-
duped.save!
|
|
21
|
-
|
|
22
|
-
reloaded = PandaPal::Session.find(duped.id)
|
|
23
|
-
expect(reloaded.session_secret).to eq(original_secret)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Rails 7.0 split partial_writes into partial_inserts/partial_updates; on 6.1
|
|
28
|
-
# the single partial_writes flag is what controls the INSERT.
|
|
29
|
-
def with_partial_inserts(value)
|
|
30
|
-
setting = PandaPal::Session.respond_to?(:partial_inserts) ? 'partial_inserts' : 'partial_writes'
|
|
31
|
-
previous = PandaPal::Session.public_send(setting)
|
|
32
|
-
PandaPal::Session.public_send("#{setting}=", value)
|
|
33
|
-
yield
|
|
34
|
-
ensure
|
|
35
|
-
PandaPal::Session.public_send("#{setting}=", previous) unless previous.nil?
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe Session::RoleStore do
|
|
40
|
-
it 'parses an LTI 1.1 (URN-style) institution role' do
|
|
41
|
-
role_store = Session::RoleStore.new('urn:lti:instrole:ims/lis/Administrator')
|
|
42
|
-
expect(role_store.institution_roles).to eq(['administrator'])
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it 'parses an LTI 1.1 (URN-style) system role' do
|
|
46
|
-
role_store = Session::RoleStore.new('urn:lti:sysrole:ims/lis/SysAdmin')
|
|
47
|
-
expect(role_store.system_roles).to eq(['sys_admin'])
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'parses an LTI 1.3 (URL-style) institution role' do
|
|
51
|
-
role_store = Session::RoleStore.new(['http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator'])
|
|
52
|
-
expect(role_store.institution_roles).to eq(['administrator'])
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
describe '.for_panda_token' do
|
|
57
|
-
it 'returns nil for a nil token' do
|
|
58
|
-
expect(Session.for_panda_token(nil)).to be_nil
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it 'returns nil for an empty token' do
|
|
62
|
-
expect(Session.for_panda_token('')).to be_nil
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
context 'with a KEY-type token' do
|
|
66
|
-
let(:session) { create(:panda_pal_session) }
|
|
67
|
-
|
|
68
|
-
it 'returns the matching session record' do
|
|
69
|
-
found = Session.for_panda_token(session.session_key, enforce_tenant: false)
|
|
70
|
-
expect(found).to eq(session)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it 'raises SessionNonceMismatch when the secret in the signature is wrong' do
|
|
74
|
-
header, _sig = session.session_key.split('.')
|
|
75
|
-
tampered_token = "#{header}.not-the-real-secret"
|
|
76
|
-
|
|
77
|
-
expect {
|
|
78
|
-
Session.for_panda_token(tampered_token, enforce_tenant: false)
|
|
79
|
-
}.to raise_error(Session::SessionNonceMismatch)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it 'raises SessionNonceMismatch when the payload session id does not match the found record' do
|
|
83
|
-
other_session = create(:panda_pal_session)
|
|
84
|
-
|
|
85
|
-
header, sig = session.session_key.split('.')
|
|
86
|
-
payload = JSON.parse(Base64.urlsafe_decode64(header))
|
|
87
|
-
payload['s'] = other_session.id
|
|
88
|
-
tampered_header = Base64.urlsafe_encode64(payload.to_json)
|
|
89
|
-
tampered_token = "#{tampered_header}.#{sig}"
|
|
90
|
-
|
|
91
|
-
expect {
|
|
92
|
-
Session.for_panda_token(tampered_token, enforce_tenant: false)
|
|
93
|
-
}.to raise_error(Session::SessionNonceMismatch)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
describe '#sign_value / #validate_signature' do
|
|
99
|
-
it 'produces a base64-encoded HMAC-SHA256 digest without relying on OpenSSL::HMAC.base64digest' do
|
|
100
|
-
session = build(:panda_pal_session)
|
|
101
|
-
|
|
102
|
-
# OpenSSL::HMAC.base64digest doesn't exist at all on some Rubies' bundled
|
|
103
|
-
# openssl gem (that's the bug this test guards against) -- only assert the
|
|
104
|
-
# negative expectation where the method exists to negate; the correctness
|
|
105
|
-
# check below is what actually proves sign_value doesn't depend on it.
|
|
106
|
-
expect(OpenSSL::HMAC).not_to receive(:base64digest) if OpenSSL::HMAC.respond_to?(:base64digest)
|
|
107
|
-
signature = session.sign_value('some-data-to-sign')
|
|
108
|
-
|
|
109
|
-
expected = Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), session.session_secret, 'some-data-to-sign'))
|
|
110
|
-
expect(signature).to eq(expected)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it 'validates a signature produced by the same session' do
|
|
114
|
-
session = build(:panda_pal_session)
|
|
115
|
-
signature = session.sign_value('some-data-to-sign')
|
|
116
|
-
|
|
117
|
-
expect(session.validate_signature('some-data-to-sign', signature)).to be true
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it 'does not validate a signature produced by a different session' do
|
|
121
|
-
session = build(:panda_pal_session)
|
|
122
|
-
other_session = build(:panda_pal_session)
|
|
123
|
-
|
|
124
|
-
signature_from_other = other_session.sign_value('some-data-to-sign')
|
|
125
|
-
|
|
126
|
-
expect(session.validate_signature('some-data-to-sign', signature_from_other)).to be false
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
describe '.extract_panda_token' do
|
|
131
|
-
it 'extracts the token from the X-Panda-Token header (HTTP_ form)' do
|
|
132
|
-
request = double('request', headers: { 'HTTP_X_PANDA_TOKEN' => 'header.token' })
|
|
133
|
-
expect(Session.extract_panda_token(request, {})).to eq('header.token')
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it 'extracts the token from the X-Panda-Token header (raw form)' do
|
|
137
|
-
request = double('request', headers: { 'X-Panda-Token' => 'header.token' })
|
|
138
|
-
expect(Session.extract_panda_token(request, {})).to eq('header.token')
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
it 'falls back to request.env when the request does not respond to headers' do
|
|
142
|
-
request = double('request', env: { 'HTTP_X_PANDA_TOKEN' => 'env.token' })
|
|
143
|
-
expect(Session.extract_panda_token(request, {})).to eq('env.token')
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
it 'extracts the token from an "Authorization: Bearer panda:<token>" header' do
|
|
147
|
-
request = double('request', headers: { 'HTTP_AUTHORIZATION' => 'Bearer panda:bearer.token' })
|
|
148
|
-
expect(Session.extract_panda_token(request, {})).to eq('bearer.token')
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it 'extracts the token from the raw Authorization header key' do
|
|
152
|
-
request = double('request', headers: { 'Authorization' => 'Bearer panda:bearer.token' })
|
|
153
|
-
expect(Session.extract_panda_token(request, {})).to eq('bearer.token')
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it 'extracts the token from the legacy "Authorization: token=<token>" header format' do
|
|
157
|
-
request = double('request', headers: { 'HTTP_AUTHORIZATION' => 'token=legacy.token' })
|
|
158
|
-
expect(Session.extract_panda_token(request, {})).to eq('legacy.token')
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
it 'extracts the token from params["panda_token"]' do
|
|
162
|
-
request = double('request', headers: {})
|
|
163
|
-
expect(Session.extract_panda_token(request, { 'panda_token' => 'params.token' })).to eq('params.token')
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it 'extracts the token from the legacy params["session_token"]' do
|
|
167
|
-
request = double('request', headers: {})
|
|
168
|
-
expect(Session.extract_panda_token(request, { 'session_token' => 'legacy.session.token' })).to eq('legacy.session.token')
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
it 'extracts the token from the legacy params["session_key"]' do
|
|
172
|
-
request = double('request', headers: {})
|
|
173
|
-
expect(Session.extract_panda_token(request, { 'session_key' => 'legacy.session.key.token' })).to eq('legacy.session.key.token')
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
it 'returns nil when nothing is present' do
|
|
177
|
-
request = double('request', headers: {})
|
|
178
|
-
expect(Session.extract_panda_token(request, {})).to be_nil
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
describe '.format_url_for_signing' do
|
|
183
|
-
it 'strips panda_token, session_key, and session_token but keeps other params' do
|
|
184
|
-
url = 'https://example.com/some/path?panda_token=tok&foo=bar&session_key=abc&baz=qux&session_token=def'
|
|
185
|
-
|
|
186
|
-
expect(Session.format_url_for_signing(url)).to eq('/some/path?foo=bar&baz=qux')
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
it 'accepts a URI object directly' do
|
|
190
|
-
uri = URI.parse('https://example.com/some/path?panda_token=tok&foo=bar')
|
|
191
|
-
|
|
192
|
-
expect(Session.format_url_for_signing(uri)).to eq('/some/path?foo=bar')
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
it 'produces an empty query string when no params remain' do
|
|
196
|
-
url = 'https://example.com/some/path?panda_token=tok'
|
|
197
|
-
|
|
198
|
-
expect(Session.format_url_for_signing(url)).to eq('/some/path?')
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# ENV["RAILS_ENV"] ||= 'test'
|
|
2
|
-
|
|
3
|
-
if ENV['COVERAGE']
|
|
4
|
-
require 'simplecov'
|
|
5
|
-
SimpleCov.start do
|
|
6
|
-
add_filter '/spec/'
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
require 'bundler'
|
|
11
|
-
Bundler.require :default, :development
|
|
12
|
-
|
|
13
|
-
Combustion.initialize! :active_record, :active_job, :action_controller
|
|
14
|
-
|
|
15
|
-
require 'sidekiq'
|
|
16
|
-
require 'sidekiq/rails'
|
|
17
|
-
require 'sidekiq/testing'
|
|
18
|
-
require 'sidekiq-scheduler'
|
|
19
|
-
|
|
20
|
-
require 'rspec/rails'
|
|
21
|
-
require 'rspec/autorun'
|
|
22
|
-
require 'nokogiri'
|
|
23
|
-
require 'factory_bot_rails'
|
|
24
|
-
|
|
25
|
-
require "panda_pal/spec_helper"
|
|
26
|
-
|
|
27
|
-
ActiveRecord::Schema.verbose = false
|
|
28
|
-
|
|
29
|
-
Dir[File.dirname(__FILE__) + "/factories/**/*.rb"].each {|f| require f }
|
|
30
|
-
|
|
31
|
-
RSpec.configure do |config|
|
|
32
|
-
config.include PandaPal::SpecHelper
|
|
33
|
-
config.include FactoryBot::Syntax::Methods
|
|
34
|
-
|
|
35
|
-
config.before(:each) do
|
|
36
|
-
allow_any_instance_of(PandaPal::Organization).to receive(:create_schema).and_wrap_original do |m, *args|
|
|
37
|
-
org = m.receiver
|
|
38
|
-
m.call(*args)
|
|
39
|
-
org.switch_tenant do
|
|
40
|
-
Combustion::Database::LoadSchema.call
|
|
41
|
-
Combustion::Database::Migrate.call
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# rspec-expectations config goes here. You can use an alternate
|
|
47
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
48
|
-
# assertions if you prefer.
|
|
49
|
-
config.expect_with :rspec do |expectations|
|
|
50
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
51
|
-
# and `failure_message` of custom matchers include text for helper methods
|
|
52
|
-
# defined using `chain`, e.g.:
|
|
53
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
|
54
|
-
# # => "be bigger than 2 and smaller than 4"
|
|
55
|
-
# ...rather than:
|
|
56
|
-
# # => "be bigger than 2"
|
|
57
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
|
61
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
62
|
-
config.mock_with :rspec do |mocks|
|
|
63
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
|
64
|
-
# a real object. This is generally recommended, and will default to
|
|
65
|
-
# `true` in RSpec 4.
|
|
66
|
-
mocks.verify_partial_doubles = true
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
config.before(:each) do
|
|
70
|
-
PandaPal.lti_options = {
|
|
71
|
-
title: 'Test App',
|
|
72
|
-
settings_structure: {}
|
|
73
|
-
}
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures.
|
|
77
|
-
# Rails 7.1+ uses the plural fixture_paths (array); earlier versions use the
|
|
78
|
-
# singular fixture_path (string).
|
|
79
|
-
fixtures_dir = "#{::Rails.root}/spec/fixtures"
|
|
80
|
-
if config.respond_to?(:fixture_paths=)
|
|
81
|
-
config.fixture_paths |= [fixtures_dir]
|
|
82
|
-
else
|
|
83
|
-
config.fixture_path = fixtures_dir
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
87
|
-
# examples within a transaction, remove the following line or assign false
|
|
88
|
-
# instead of true.
|
|
89
|
-
config.use_transactional_fixtures = true
|
|
90
|
-
|
|
91
|
-
# RSpec Rails can automatically mix in different behaviours to your tests
|
|
92
|
-
# based on their file location, for example enabling you to call `get` and
|
|
93
|
-
# `post` in specs under `spec/controllers`.
|
|
94
|
-
#
|
|
95
|
-
# You can disable this behaviour by removing the line below, and instead
|
|
96
|
-
# explicitly tag your specs with their type, e.g.:
|
|
97
|
-
#
|
|
98
|
-
# RSpec.describe UsersController, :type => :controller do
|
|
99
|
-
# # ...
|
|
100
|
-
# end
|
|
101
|
-
#
|
|
102
|
-
# The different available types are documented in the features, such as in
|
|
103
|
-
# https://relishapp.com/rspec/rspec-rails/docs
|
|
104
|
-
config.infer_spec_type_from_file_location!
|
|
105
|
-
|
|
106
|
-
# Filter lines from Rails gems in backtraces.
|
|
107
|
-
config.filter_rails_from_backtrace!
|
|
108
|
-
|
|
109
|
-
# The settings below are suggested to provide a good initial experience
|
|
110
|
-
# with RSpec, but feel free to customize to your heart's content.
|
|
111
|
-
=begin
|
|
112
|
-
# These two settings work together to allow you to limit a spec run
|
|
113
|
-
# to individual examples or groups you care about by tagging them with
|
|
114
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
|
115
|
-
# get run.
|
|
116
|
-
config.filter_run :focus
|
|
117
|
-
config.run_all_when_everything_filtered = true
|
|
118
|
-
|
|
119
|
-
# Allows RSpec to persist some state between runs in order to support
|
|
120
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
|
121
|
-
# you configure your source control system to ignore this file.
|
|
122
|
-
config.example_status_persistence_file_path = "spec/examples.txt"
|
|
123
|
-
|
|
124
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
|
125
|
-
# recommended. For more details, see:
|
|
126
|
-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
|
127
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
128
|
-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
|
129
|
-
config.disable_monkey_patching!
|
|
130
|
-
|
|
131
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
|
132
|
-
# file, and it's useful to allow more verbose output when running an
|
|
133
|
-
# individual spec file.
|
|
134
|
-
if config.files_to_run.one?
|
|
135
|
-
# Use the documentation formatter for detailed output,
|
|
136
|
-
# unless a formatter has already been configured
|
|
137
|
-
# (e.g. via a command-line flag).
|
|
138
|
-
config.default_formatter = 'doc'
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
# Print the 10 slowest examples and example groups at the
|
|
142
|
-
# end of the spec run, to help surface which specs are running
|
|
143
|
-
# particularly slow.
|
|
144
|
-
config.profile_examples = 10
|
|
145
|
-
|
|
146
|
-
# Run specs in random order to surface order dependencies. If you find an
|
|
147
|
-
# order dependency and want to debug it, you can fix the order by providing
|
|
148
|
-
# the seed, which is printed after each run.
|
|
149
|
-
# --seed 1234
|
|
150
|
-
config.order = :random
|
|
151
|
-
|
|
152
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
|
153
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
154
|
-
# test failures related to randomization by passing the same `--seed` value
|
|
155
|
-
# as the one that triggered the failure.
|
|
156
|
-
Kernel.srand config.seed
|
|
157
|
-
=end
|
|
158
|
-
end
|