panda_pal 5.19.0.beta1 → 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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/app/models/panda_pal/platform/canvas.rb +25 -0
  4. data/lib/panda_pal/version.rb +1 -1
  5. data/panda_pal.gemspec +1 -1
  6. metadata +2 -60
  7. data/spec/controllers/panda_pal/api_call_controller_spec.rb +0 -25
  8. data/spec/controllers/panda_pal/lti_v1_p0_controller_spec.rb +0 -194
  9. data/spec/controllers/panda_pal/lti_v1_p3_controller_spec.rb +0 -108
  10. data/spec/controllers/panda_pal/lti_v1_p3_tools_spec.rb +0 -144
  11. data/spec/core/apartment_multidb_spec.rb +0 -166
  12. data/spec/factories/panda_pal_organizations.rb +0 -9
  13. data/spec/factories/panda_pal_sessions.rb +0 -6
  14. data/spec/internal/app/models/account.rb +0 -7
  15. data/spec/internal/app/models/admin.rb +0 -6
  16. data/spec/internal/config/database.yml +0 -18
  17. data/spec/internal/config/routes.rb +0 -5
  18. data/spec/internal/config/storage.yml +0 -3
  19. data/spec/internal/db/schema.rb +0 -30
  20. data/spec/jobs/panda_pal/jobs/grade_passback_job_spec.rb +0 -83
  21. data/spec/lib/panda_pal/ags_client_spec.rb +0 -385
  22. data/spec/lib/panda_pal/helpers/secure_headers_spec.rb +0 -77
  23. data/spec/lib/panda_pal/helpers/session_replacement_spec.rb +0 -72
  24. data/spec/lib/panda_pal/lti_tools_spec.rb +0 -153
  25. data/spec/models/panda_pal/api_call_spec.rb +0 -30
  26. data/spec/models/panda_pal/lti_registration_spec.rb +0 -72
  27. data/spec/models/panda_pal/organization/settings_validation_spec.rb +0 -179
  28. data/spec/models/panda_pal/organization/task_scheduling_spec.rb +0 -145
  29. data/spec/models/panda_pal/organization_spec.rb +0 -50
  30. data/spec/models/panda_pal/platform/canvas_install_spec.rb +0 -115
  31. data/spec/models/panda_pal/platform_spec.rb +0 -349
  32. data/spec/models/panda_pal/session_account_roles_spec.rb +0 -182
  33. data/spec/models/panda_pal/session_spec.rb +0 -202
  34. data/spec/spec_helper.rb +0 -159
  35. data/spec/support/isolated_lti_config.rb +0 -24
@@ -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,159 +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
- Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f }
31
-
32
- RSpec.configure do |config|
33
- config.include PandaPal::SpecHelper
34
- config.include FactoryBot::Syntax::Methods
35
-
36
- config.before(:each) do
37
- allow_any_instance_of(PandaPal::Organization).to receive(:create_schema).and_wrap_original do |m, *args|
38
- org = m.receiver
39
- m.call(*args)
40
- org.switch_tenant do
41
- Combustion::Database::LoadSchema.call
42
- Combustion::Database::Migrate.call
43
- end
44
- end
45
- end
46
-
47
- # rspec-expectations config goes here. You can use an alternate
48
- # assertion/expectation library such as wrong or the stdlib/minitest
49
- # assertions if you prefer.
50
- config.expect_with :rspec do |expectations|
51
- # This option will default to `true` in RSpec 4. It makes the `description`
52
- # and `failure_message` of custom matchers include text for helper methods
53
- # defined using `chain`, e.g.:
54
- # be_bigger_than(2).and_smaller_than(4).description
55
- # # => "be bigger than 2 and smaller than 4"
56
- # ...rather than:
57
- # # => "be bigger than 2"
58
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
59
- end
60
-
61
- # rspec-mocks config goes here. You can use an alternate test double
62
- # library (such as bogus or mocha) by changing the `mock_with` option here.
63
- config.mock_with :rspec do |mocks|
64
- # Prevents you from mocking or stubbing a method that does not exist on
65
- # a real object. This is generally recommended, and will default to
66
- # `true` in RSpec 4.
67
- mocks.verify_partial_doubles = true
68
- end
69
-
70
- config.before(:each) do
71
- PandaPal.lti_options = {
72
- title: 'Test App',
73
- settings_structure: {}
74
- }
75
- end
76
-
77
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures.
78
- # Rails 7.1+ uses the plural fixture_paths (array); earlier versions use the
79
- # singular fixture_path (string).
80
- fixtures_dir = "#{::Rails.root}/spec/fixtures"
81
- if config.respond_to?(:fixture_paths=)
82
- config.fixture_paths |= [fixtures_dir]
83
- else
84
- config.fixture_path = fixtures_dir
85
- end
86
-
87
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
88
- # examples within a transaction, remove the following line or assign false
89
- # instead of true.
90
- config.use_transactional_fixtures = true
91
-
92
- # RSpec Rails can automatically mix in different behaviours to your tests
93
- # based on their file location, for example enabling you to call `get` and
94
- # `post` in specs under `spec/controllers`.
95
- #
96
- # You can disable this behaviour by removing the line below, and instead
97
- # explicitly tag your specs with their type, e.g.:
98
- #
99
- # RSpec.describe UsersController, :type => :controller do
100
- # # ...
101
- # end
102
- #
103
- # The different available types are documented in the features, such as in
104
- # https://relishapp.com/rspec/rspec-rails/docs
105
- config.infer_spec_type_from_file_location!
106
-
107
- # Filter lines from Rails gems in backtraces.
108
- config.filter_rails_from_backtrace!
109
-
110
- # The settings below are suggested to provide a good initial experience
111
- # with RSpec, but feel free to customize to your heart's content.
112
- =begin
113
- # These two settings work together to allow you to limit a spec run
114
- # to individual examples or groups you care about by tagging them with
115
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
116
- # get run.
117
- config.filter_run :focus
118
- config.run_all_when_everything_filtered = true
119
-
120
- # Allows RSpec to persist some state between runs in order to support
121
- # the `--only-failures` and `--next-failure` CLI options. We recommend
122
- # you configure your source control system to ignore this file.
123
- config.example_status_persistence_file_path = "spec/examples.txt"
124
-
125
- # Limits the available syntax to the non-monkey patched syntax that is
126
- # recommended. For more details, see:
127
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
128
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
129
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
130
- config.disable_monkey_patching!
131
-
132
- # Many RSpec users commonly either run the entire suite or an individual
133
- # file, and it's useful to allow more verbose output when running an
134
- # individual spec file.
135
- if config.files_to_run.one?
136
- # Use the documentation formatter for detailed output,
137
- # unless a formatter has already been configured
138
- # (e.g. via a command-line flag).
139
- config.default_formatter = 'doc'
140
- end
141
-
142
- # Print the 10 slowest examples and example groups at the
143
- # end of the spec run, to help surface which specs are running
144
- # particularly slow.
145
- config.profile_examples = 10
146
-
147
- # Run specs in random order to surface order dependencies. If you find an
148
- # order dependency and want to debug it, you can fix the order by providing
149
- # the seed, which is printed after each run.
150
- # --seed 1234
151
- config.order = :random
152
-
153
- # Seed global randomization in this process using the `--seed` CLI option.
154
- # Setting this allows you to use `--seed` to deterministically reproduce
155
- # test failures related to randomization by passing the same `--seed` value
156
- # as the one that triggered the failure.
157
- Kernel.srand config.seed
158
- =end
159
- end
@@ -1,24 +0,0 @@
1
- # PandaPal's LTI configuration (placements, tools, options, ...) lives in class
2
- # variables that host apps set once at boot. Specs that change it tag themselves
3
- # `:isolated_lti_config` so whatever they register is rolled back afterwards and
4
- # never leaks into later spec files.
5
- module IsolatedLtiConfig
6
- VARS = %i[
7
- @@lti_navigation
8
- @@lti_tools
9
- @@lti_options
10
- @@lti_custom_params
11
- @@lti_environments
12
- ].freeze
13
- end
14
-
15
- RSpec.shared_context 'isolated LTI config', isolated_lti_config: true do
16
- around do |example|
17
- saved = IsolatedLtiConfig::VARS.to_h { |var| [var, PandaPal.class_variable_get(var).deep_dup] }
18
- begin
19
- example.run
20
- ensure
21
- saved.each { |var, value| PandaPal.class_variable_set(var, value) }
22
- end
23
- end
24
- end