coalescing_panda 5.0.4 → 5.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/app/controllers/coalescing_panda/canvas_batches_controller.rb +2 -2
  3. data/app/helpers/coalescing_panda/canvas_batches_helper.rb +1 -1
  4. data/app/views/coalescing_panda/canvas_batches/_canvas_batch_flash.html.haml +3 -3
  5. data/db/migrate/20131114150001_create_coalescing_panda_canvas_api_auths.rb +1 -1
  6. data/db/migrate/20131118211442_create_coalescing_panda_lti_accounts.rb +1 -1
  7. data/db/migrate/20131119165343_create_coalescing_panda_lti_nonces.rb +1 -1
  8. data/db/migrate/20140904223159_create_coalescing_panda_sessions.rb +1 -1
  9. data/db/migrate/20141119225319_create_coalescing_panda_terms.rb +1 -1
  10. data/db/migrate/20141119225721_create_coalescing_panda_courses.rb +1 -1
  11. data/db/migrate/20141120151432_create_coalescing_panda_sections.rb +1 -1
  12. data/db/migrate/20141120151940_create_coalescing_panda_assignments.rb +1 -1
  13. data/db/migrate/20141120152458_create_coalescing_panda_users.rb +1 -1
  14. data/db/migrate/20141120152546_create_coalescing_panda_submissions.rb +1 -1
  15. data/db/migrate/20141120153135_create_coalescing_panda_enrollments.rb +1 -1
  16. data/db/migrate/20141121174846_create_coalescing_panda_canvas_batches.rb +1 -1
  17. data/db/migrate/20141124160857_create_delayed_jobs.rb +1 -1
  18. data/db/migrate/20141208221740_add_submission_types_to_assignments.rb +1 -1
  19. data/db/migrate/20150106175418_add_group_category_id_to_assignment.rb +1 -1
  20. data/db/migrate/20150106180131_add_published_to_assignments.rb +1 -1
  21. data/db/migrate/20150107205405_create_coalescing_panda_groups.rb +1 -1
  22. data/db/migrate/20150107205413_create_coalescing_panda_group_memberships.rb +1 -1
  23. data/db/migrate/20150210180516_add_context_to_canvas_batch.rb +1 -1
  24. data/db/migrate/20150506183335_create_coalescing_panda_assignment_groups.rb +1 -1
  25. data/db/migrate/20150506192717_add_assignment_group_id_to_assignments.rb +1 -1
  26. data/db/migrate/20150526144713_add_account_to_canvas_batches.rb +1 -1
  27. data/db/migrate/20150602205257_add_option_to_canvas_batches.rb +1 -1
  28. data/db/migrate/20150708192717_add_group_moderator_to_group_memberships.rb +1 -1
  29. data/db/migrate/20150709192717_add_leader_id_to_groups.rb +1 -1
  30. data/db/migrate/20150714205405_create_coalescing_panda_group_categories.rb +1 -1
  31. data/db/migrate/20150811140030_add_fields_to_users.rb +1 -1
  32. data/db/migrate/20151209155923_add_refresh_settings_to_canvas_api_auth.rb +1 -1
  33. data/db/migrate/20160830183155_create_coalescing_panda_oauth_states.rb +1 -1
  34. data/db/migrate/20200528224505_create_coalescing_panda_persistent_session.rb +1 -1
  35. data/lib/coalescing_panda/controller_helpers.rb +15 -4
  36. data/lib/coalescing_panda/engine.rb +8 -42
  37. data/lib/coalescing_panda/misc_helper.rb +13 -0
  38. data/lib/coalescing_panda/secure_headers.rb +84 -0
  39. data/lib/coalescing_panda/version.rb +1 -1
  40. data/spec/controllers/coalescing_panda/oauth2_controller_spec.rb +2 -2
  41. data/spec/models/coalescing_panda/canvas_api_auth_spec.rb +2 -2
  42. data/spec/spec_helper.rb +7 -0
  43. metadata +8 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: '0191513dcb57ac4c2146d650ff1b6d03af0cc52ac7aa7f62571b74f018ec3906'
4
- data.tar.gz: 1f938c10ebea3510455f6e0f077bb531fc7eca49086df42792ab0ab23f96f6fd
2
+ SHA1:
3
+ metadata.gz: 0d5aa87e2a3916918af65a1e1f277bc43d7f7e84
4
+ data.tar.gz: 442e7c12a0bc6e5b9ff459c1a5b7e35f069961c9
5
5
  SHA512:
6
- metadata.gz: 75ffaa346308463f9beb170800fafa30a6303613a52e8c7ce527efee418369e0ae4a94ef7f2dbb1ef12b5a5f8a7d43ef33b59114064ee4eb63fca72cc3843305
7
- data.tar.gz: bb268446450390d6af368149529ca6f23e34596155dc2151fcf5ee8cc2d604d25eb575cee4627b039894a8f8f439a52f6c8e959f4b8e0ff53979fe56128c1240
6
+ metadata.gz: 13ce225d0d9f95cf1f56327fa231d8680611ad55b9b3ceab43cbf11da20775b1ccd54a5ffb564b0460c75e2ad238ccd4b1b2e9ebddfd5bda51280b7b320e5fbb
7
+ data.tar.gz: dd493d6bf57b29132db15a9a3cd48bcb85b924591c77b39d9c1e2d22a9a486755ea077c412f98034cce860002af797189e7464b461d4d0bfdf7167948b6b2688
@@ -12,13 +12,13 @@ module CoalescingPanda
12
12
  @batch.status = 'Queued'
13
13
  @batch.save
14
14
  worker = CoalescingPanda::Workers::CourseMiner.new(@batch.context, @batch.options)
15
- session[:canvas_batch_id] = worker.batch.id
15
+ current_session_data[:canvas_batch_id] = worker.batch.id
16
16
  worker.start(true)
17
17
  redirect_to :back
18
18
  end
19
19
 
20
20
  def clear_batch_session
21
- session[:canvas_batch_id] = nil
21
+ current_session_data[:canvas_batch_id] = nil
22
22
  render nothing: true
23
23
  end
24
24
  end
@@ -1,7 +1,7 @@
1
1
  module CoalescingPanda
2
2
  module CanvasBatchesHelper
3
3
  def current_batch
4
- @current_batch ||= CoalescingPanda::CanvasBatch.find_by_id(session[:canvas_batch_id])
4
+ @current_batch ||= CoalescingPanda::CanvasBatch.find_by_id(current_session_data[:canvas_batch_id])
5
5
  end
6
6
  end
7
7
  end
@@ -1,4 +1,4 @@
1
1
  - if current_batch.present?
2
- - path = CoalescingPanda::Engine.routes.url_helpers.canvas_batch_path(current_batch)
3
- - clear_path = CoalescingPanda::Engine.routes.url_helpers.clear_batch_session_path
4
- #batch-progress{data: {batch: current_batch.try(:to_json), url: path, clear_path: clear_path} }
2
+ - path = CoalescingPanda::Engine.routes.url_helpers.canvas_batch_path(current_batch) + "?encrypted_session_key=#{encrypted_session_key}"
3
+ - clear_path = CoalescingPanda::Engine.routes.url_helpers.clear_batch_session_path + "?encrypted_session_key=#{encrypted_session_key}"
4
+ #batch-progress{data: {batch: current_batch.try(:to_json), url: path, clear_path: clear_path} }
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaCanvasApiAuths < ActiveRecord::Migration
1
+ class CreateCoalescingPandaCanvasApiAuths < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_canvas_api_auths do |t|
4
4
  t.string :user_id
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaLtiAccounts < ActiveRecord::Migration
1
+ class CreateCoalescingPandaLtiAccounts < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_lti_accounts do |t|
4
4
  t.string :name
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaLtiNonces < ActiveRecord::Migration
1
+ class CreateCoalescingPandaLtiNonces < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_lti_nonces do |t|
4
4
  t.belongs_to :coalescing_panda_lti_account
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaSessions < ActiveRecord::Migration
1
+ class CreateCoalescingPandaSessions < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_sessions do |t|
4
4
  t.string :token
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaTerms < ActiveRecord::Migration
1
+ class CreateCoalescingPandaTerms < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_terms do |t|
4
4
  t.belongs_to :coalescing_panda_lti_account, null: false
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaCourses < ActiveRecord::Migration
1
+ class CreateCoalescingPandaCourses < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_courses do |t|
4
4
  t.belongs_to :coalescing_panda_lti_account, null: false
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaSections < ActiveRecord::Migration
1
+ class CreateCoalescingPandaSections < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_sections do |t|
4
4
  t.belongs_to :coalescing_panda_course, null: false
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaAssignments < ActiveRecord::Migration
1
+ class CreateCoalescingPandaAssignments < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_assignments do |t|
4
4
  t.belongs_to :coalescing_panda_course, null: false
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaUsers < ActiveRecord::Migration
1
+ class CreateCoalescingPandaUsers < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_users do |t|
4
4
  t.belongs_to :coalescing_panda_lti_account, null: false
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaSubmissions < ActiveRecord::Migration
1
+ class CreateCoalescingPandaSubmissions < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_submissions do |t|
4
4
  t.belongs_to :coalescing_panda_user, null: false
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaEnrollments < ActiveRecord::Migration
1
+ class CreateCoalescingPandaEnrollments < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_enrollments do |t|
4
4
  t.belongs_to :coalescing_panda_user, null: false
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaCanvasBatches < ActiveRecord::Migration
1
+ class CreateCoalescingPandaCanvasBatches < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_canvas_batches do |t|
4
4
  t.float :percent_complete, default: 0.0
@@ -1,4 +1,4 @@
1
- class CreateDelayedJobs < ActiveRecord::Migration
1
+ class CreateDelayedJobs < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def self.up
3
3
  create_table :delayed_jobs, :force => true do |table|
4
4
  table.integer :priority, :default => 0, :null => false # Allows some jobs to jump to the front of the queue
@@ -1,4 +1,4 @@
1
- class AddSubmissionTypesToAssignments < ActiveRecord::Migration
1
+ class AddSubmissionTypesToAssignments < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_assignments, :submission_types, :text
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddGroupCategoryIdToAssignment < ActiveRecord::Migration
1
+ class AddGroupCategoryIdToAssignment < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_assignments, :group_category_id, :integer
4
4
  add_column :coalescing_panda_assignments, :grade_group_students_individually, :boolean
@@ -1,4 +1,4 @@
1
- class AddPublishedToAssignments < ActiveRecord::Migration
1
+ class AddPublishedToAssignments < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_assignments, :published, :boolean
4
4
  end
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaGroups < ActiveRecord::Migration
1
+ class CreateCoalescingPandaGroups < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_groups do |t|
4
4
  t.belongs_to :context, polymorphic: true
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaGroupMemberships < ActiveRecord::Migration
1
+ class CreateCoalescingPandaGroupMemberships < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_group_memberships do |t|
4
4
  t.belongs_to :coalescing_panda_group
@@ -1,4 +1,4 @@
1
- class AddContextToCanvasBatch < ActiveRecord::Migration
1
+ class AddContextToCanvasBatch < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_canvas_batches, :context_id, :integer
4
4
  add_column :coalescing_panda_canvas_batches, :context_type, :string
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaAssignmentGroups < ActiveRecord::Migration
1
+ class CreateCoalescingPandaAssignmentGroups < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_assignment_groups do |t|
4
4
  t.belongs_to :coalescing_panda_course, null: false
@@ -1,4 +1,4 @@
1
- class AddAssignmentGroupIdToAssignments < ActiveRecord::Migration
1
+ class AddAssignmentGroupIdToAssignments < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_assignments, :coalescing_panda_assignment_group_id, :integer
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddAccountToCanvasBatches < ActiveRecord::Migration
1
+ class AddAccountToCanvasBatches < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_canvas_batches, :coalescing_panda_lti_account_id, :integer, index: true
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddOptionToCanvasBatches < ActiveRecord::Migration
1
+ class AddOptionToCanvasBatches < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_canvas_batches, :options, :text
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddGroupModeratorToGroupMemberships < ActiveRecord::Migration
1
+ class AddGroupModeratorToGroupMemberships < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_group_memberships, :moderator, :boolean
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddLeaderIdToGroups < ActiveRecord::Migration
1
+ class AddLeaderIdToGroups < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_groups, :leader_id, :integer
4
4
  add_foreign_key :coalescing_panda_groups, :coalescing_panda_users, column: :leader_id, primary_key: "id"
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaGroupCategories < ActiveRecord::Migration
1
+ class CreateCoalescingPandaGroupCategories < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_group_categories do |t|
4
4
  t.belongs_to :context, polymorphic: true
@@ -1,4 +1,4 @@
1
- class AddFieldsToUsers < ActiveRecord::Migration
1
+ class AddFieldsToUsers < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_users, :login_id, :string
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddRefreshSettingsToCanvasApiAuth < ActiveRecord::Migration
1
+ class AddRefreshSettingsToCanvasApiAuth < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :coalescing_panda_canvas_api_auths, :refresh_token, :string
4
4
  add_column :coalescing_panda_canvas_api_auths, :expires_at, :datetime
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaOauthStates < ActiveRecord::Migration
1
+ class CreateCoalescingPandaOauthStates < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_oauth_states do |t|
4
4
  t.string :state_key
@@ -1,4 +1,4 @@
1
- class CreateCoalescingPandaPersistentSession < ActiveRecord::Migration
1
+ class CreateCoalescingPandaPersistentSession < CoalescingPanda::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :coalescing_panda_persistent_sessions do |t|
4
4
  t.string :session_key
@@ -81,9 +81,7 @@ module CoalescingPanda
81
81
  client = Bearcat::Client.new(prefix: uri.prefix)
82
82
  state = SecureRandom.hex(32)
83
83
  OauthState.create! state_key: state, data: { key: params['oauth_consumer_key'], user_id: user_id, api_domain: uri.api_domain }
84
- redirect_path = coalescing_panda.oauth2_redirect_path
85
- redirect_url = [coalescing_panda_url, redirect_path.sub(/^\/lti/, '')].join
86
- @canvas_url = client.auth_redirect_url(client_id, redirect_url, { state: state })
84
+ @canvas_url = client.auth_redirect_url(client_id, resolve_coalescing_panda_url(:oauth2_redirect_url), { state: state })
87
85
 
88
86
  #delete the added params so the original oauth sig still works
89
87
  @lti_params = params.to_hash
@@ -94,7 +92,7 @@ module CoalescingPanda
94
92
 
95
93
  def refresh_token(uri, api_auth)
96
94
  refresh_client = Bearcat::Client.new(prefix: uri.prefix)
97
- refresh_body = refresh_client.retrieve_token(@lti_account.oauth2_client_id, coalescing_panda.oauth2_redirect_url,
95
+ refresh_body = refresh_client.retrieve_token(@lti_account.oauth2_client_id, resolve_coalescing_panda_url(:oauth2_redirect_url),
98
96
  @lti_account.oauth2_client_key, api_auth.refresh_token, 'refresh_token')
99
97
  api_auth.update({ api_token: refresh_body['access_token'], expires_at: (Time.now + refresh_body['expires_in']) })
100
98
  end
@@ -257,5 +255,18 @@ module CoalescingPanda
257
255
  }.merge(redirect_params))
258
256
  end
259
257
 
258
+ private
259
+
260
+ # This is necessitated by a bug in Rails Engines where it isn't resolving the URL correctly
261
+ # when using coalescing_panda.xyz_url (The Engine Prefix is not included)
262
+ # I believe https://github.com/rails/rails/issues/34452 is the same issue
263
+ def resolve_coalescing_panda_url(key)
264
+ key = key.to_s[0...-4] if key.to_s.ends_with?('_url')
265
+ resolved_path = coalescing_panda.send(:"#{key}_path")
266
+ cpurl = coalescing_panda_url
267
+ cppath = URI.parse(cpurl).path
268
+ resolved_path = cppath + resolved_path unless resolved_path.starts_with?(cppath)
269
+ URI.join(cpurl, resolved_path)
270
+ end
260
271
  end
261
272
  end
@@ -1,4 +1,5 @@
1
1
  require 'secure_headers'
2
+ require_relative './secure_headers'
2
3
 
3
4
  module CoalescingPanda
4
5
  class Engine < ::Rails::Engine
@@ -42,56 +43,21 @@ module CoalescingPanda
42
43
  end
43
44
 
44
45
  initializer :secure_headers do |app|
45
- connect_src = %w('self')
46
- script_src = %w('self')
47
-
48
- if Rails.env.development?
49
- # Allow webpack-dev-server to work
50
- connect_src << "http://localhost:3035"
51
- connect_src << "ws://localhost:3035"
52
-
53
- # Allow stuff like rack-mini-profiler to work in development:
54
- # https://github.com/MiniProfiler/rack-mini-profiler/issues/327
55
- # DON'T ENABLE THIS FOR PRODUCTION!
56
- script_src << "'unsafe-eval'"
57
- elsif CoalescingPanda.lti_options.has_key?(:allow_unsafe_eval) && CoalescingPanda.lti_options[:allow_unsafe_eval] == true
58
- # For when code is returned from server and injected into dom. Need to have unsafe-eval or it won't work.
59
- script_src << "'unsafe-eval'"
60
- end
61
-
62
- SecureHeaders::Configuration.default do |config|
63
- # The default cookie headers aren't compatible with PandaPal cookies currently
64
- config.cookies = { samesite: { none: true } }
65
-
66
- if Rails.env.production?
67
- config.cookies[:secure] = true
46
+ begin
47
+ ::SecureHeaders::Configuration.default do |config|
48
+ CoalescingPanda::SecureHeaders.apply_defaults(config)
68
49
  end
69
-
70
- # Need to allow LTI iframes
71
- config.x_frame_options = "ALLOWALL"
72
-
73
- config.x_content_type_options = "nosniff"
74
- config.x_xss_protection = "1; mode=block"
75
- config.referrer_policy = %w(origin-when-cross-origin strict-origin-when-cross-origin)
76
-
77
- config.csp = {
78
- default_src: %w('self'),
79
- script_src: script_src,
80
- # Certain CSS-in-JS libraries inline the CSS, so we need to use unsafe-inline for them
81
- style_src: %w('self' 'unsafe-inline' blob: https://fonts.googleapis.com),
82
- font_src: %w('self' data: https://fonts.gstatic.com),
83
- connect_src: connect_src,
84
- }
50
+ rescue ::SecureHeaders::Configuration::AlreadyConfiguredError
51
+ # The App already applied settings
85
52
  end
86
53
 
87
- SecureHeaders::Configuration.override(:safari_override) do |config|
54
+ ::SecureHeaders::Configuration.override(:safari_override) do |config|
88
55
  config.cookies = SecureHeaders::OPT_OUT
89
56
  end
90
57
 
91
- SecureHeaders::Configuration.override(:allow_inline_scripts) do |config|
58
+ ::SecureHeaders::Configuration.override(:allow_inline_scripts) do |config|
92
59
  config.csp[:script_src] << "'unsafe-inline'"
93
60
  end
94
61
  end
95
-
96
62
  end
97
63
  end
@@ -0,0 +1,13 @@
1
+ module CoalescingPanda
2
+ module MiscHelper
3
+ MigrationClass = Rails.version < '5.0' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
4
+
5
+ def self.to_boolean(v)
6
+ if Rails.version < '5.0'
7
+ ActiveRecord::Type::Boolean.new.type_cast_from_user("0")
8
+ else
9
+ ActiveRecord::Type::Boolean.new.deserialize('0')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,84 @@
1
+ module CoalescingPanda
2
+ module SecureHeaders
3
+ def self.apply_defaults(config)
4
+ @config = config
5
+ # The default cookie headers aren't compatable with CoalescingPanda cookies currenntly
6
+ config.cookies = { samesite: { none: true } }
7
+
8
+ if Rails.env.production?
9
+ config.cookies[:secure] = true
10
+ end
11
+
12
+ # Need to allow LTI iframes
13
+ config.x_frame_options = "ALLOWALL"
14
+
15
+ config.x_content_type_options = "nosniff"
16
+ config.x_xss_protection = "1; mode=block"
17
+ config.referrer_policy = %w(origin-when-cross-origin strict-origin-when-cross-origin)
18
+
19
+ config.csp ||= {}
20
+
21
+ csp_entry(:default_src, %w['self'])
22
+ csp_entry(:connect_src, %w['self'])
23
+ csp_entry(:script_src, %w['self'])
24
+
25
+ if Rails.env.development?
26
+ # Allow webpack-dev-server to work
27
+ csp_entry(:connect_src, "http://localhost:3035")
28
+ csp_entry(:connect_src, "ws://localhost:3035")
29
+
30
+ # Allow stuff like rack-mini-profiler to work in development:
31
+ # https://github.com/MiniProfiler/rack-mini-profiler/issues/327
32
+ # DON'T ENABLE THIS FOR PRODUCTION!
33
+ csp_entry(:script_src, "'unsafe-eval'")
34
+
35
+ # Detect and permit Scout APM in Dev
36
+ if MiscHelper.to_boolean(ENV['SCOUT_DEV_TRACE'])
37
+ csp_entry(:default_src, 'https://scoutapm.com')
38
+ csp_entry(:default_src, 'https://apm.scoutapp.com')
39
+
40
+ csp_entry(:script_src, "'unsafe-inline'")
41
+ csp_entry(:script_src, 'https://scoutapm.com')
42
+ csp_entry(:script_src, 'https://apm.scoutapp.com')
43
+
44
+ csp_entry(:connect_src, 'https://apm.scoutapp.com')
45
+
46
+ csp_entry(:style_src, 'https://scoutapm.com')
47
+ csp_entry(:style_src, 'https://apm.scoutapp.com')
48
+ end
49
+ end
50
+
51
+ if CoalescingPanda.lti_options.has_key?(:allow_unsafe_eval) && CoalescingPanda.lti_options[:allow_unsafe_eval] == true
52
+ # For when code is returned from server and injected into dom. Need to have unsafe-eval or it won't work.
53
+ csp_entry(:script_src, "'unsafe-eval'")
54
+ end
55
+
56
+ # Detect and permit Sentry
57
+ if defined?(Raven) && Raven.configuration.server.present?
58
+ csp_entry(:connect_src, Raven.configuration.server)
59
+
60
+ # Report CSP Violations to Sentry
61
+ unless config.csp[:report_uri].present?
62
+ cfg = Raven.configuration
63
+ config.csp[:report_uri] = ["#{cfg.scheme}://#{cfg.host}/api/#{cfg.project_id}/security/?sentry_key=#{cfg.public_key}"] unless config.csp[:report_uri].present?
64
+ end
65
+ end
66
+
67
+ # Certain CSS-in-JS libraries inline the CSS, so we need to use unsafe-inline for them
68
+ csp_entry(:style_src, %w('self' 'unsafe-inline' blob: https://fonts.googleapis.com))
69
+ csp_entry(:font_src, %w('self' data: https://fonts.gstatic.com))
70
+
71
+ @config = nil
72
+
73
+ config
74
+ end
75
+
76
+ private
77
+
78
+ def self.csp_entry(key, *values)
79
+ values = values.flatten
80
+ @config.csp[key] ||= []
81
+ @config.csp[key] |= values
82
+ end
83
+ end
84
+ end
@@ -1,3 +1,3 @@
1
1
  module CoalescingPanda
2
- VERSION = '5.0.4'
2
+ VERSION = '5.0.10'
3
3
  end
@@ -11,7 +11,7 @@ describe CoalescingPanda::Oauth2Controller, :type => :controller do
11
11
  Bearcat::Client.any_instance.stub(retrieve_token: { 'access_token' => 'token', 'refresh_token' => 'token', 'expires_in' => 3600 })
12
12
  session[:state] = 'test'
13
13
  CoalescingPanda::OauthState.create!(state_key: session[:state], data: { key: account.key, user_id: user.id, api_domain: 'foo.com' })
14
- get :redirect, {user_id: user.id, api_domain: 'foo.com', code: 'bar', key: account.key, state: 'test'}
14
+ get :redirect, params: {user_id: user.id, api_domain: 'foo.com', code: 'bar', key: account.key, state: 'test'}
15
15
  auth = CoalescingPanda::CanvasApiAuth.find_by_user_id_and_api_domain(user.id, 'foo.com')
16
16
  auth.should_not == nil
17
17
  expect(auth.api_token).to eql 'token'
@@ -20,7 +20,7 @@ describe CoalescingPanda::Oauth2Controller, :type => :controller do
20
20
  end
21
21
 
22
22
  it "doesn't create a token in the db" do
23
- get :redirect, {error: 'your face'}
23
+ get :redirect, params: {error: 'your face'}
24
24
  CoalescingPanda::CanvasApiAuth.all.count.should == 0
25
25
  end
26
26
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe CoalescingPanda::CanvasApiAuth do
3
+ describe CoalescingPanda::CanvasApiAuth, type: :model do
4
4
 
5
5
  it { should validate_uniqueness_of(:user_id).scoped_to(:api_domain)}
6
6
  it { should validate_presence_of(:user_id)}
7
- it {should validate_presence_of(:api_domain)}
7
+ it { should validate_presence_of(:api_domain)}
8
8
 
9
9
  describe '#expired?' do
10
10
  let(:auth) { FactoryGirl.create :canvas_api_auth }
@@ -24,6 +24,13 @@ SimpleCov.start
24
24
 
25
25
  ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
26
26
 
27
+ Shoulda::Matchers.configure do |config|
28
+ config.integrate do |with|
29
+ with.test_framework :rspec
30
+ with.library :rails
31
+ end
32
+ end
33
+
27
34
  # This file was generated by the `rails generate rspec:install` command. Conventionally, all
28
35
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
29
36
  # The generated `.rspec` file contains `--require spec_helper` which will cause this
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coalescing_panda
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.4
4
+ version: 5.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Mills
@@ -10,20 +10,20 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-07-29 00:00:00.000000000 Z
13
+ date: 2020-09-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: 4.2.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: 4.2.1
29
29
  - !ruby/object:Gem::Dependency
@@ -487,7 +487,9 @@ files:
487
487
  - lib/coalescing_panda/bearcat_uri.rb
488
488
  - lib/coalescing_panda/controller_helpers.rb
489
489
  - lib/coalescing_panda/engine.rb
490
+ - lib/coalescing_panda/misc_helper.rb
490
491
  - lib/coalescing_panda/route_helpers.rb
492
+ - lib/coalescing_panda/secure_headers.rb
491
493
  - lib/coalescing_panda/version.rb
492
494
  - lib/tasks/coalescing_panda_tasks.rake
493
495
  - spec/controllers/coalescing_panda/canvas_batches_controller_spec.rb
@@ -575,7 +577,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
575
577
  - !ruby/object:Gem::Version
576
578
  version: '0'
577
579
  requirements: []
578
- rubygems_version: 3.1.2
580
+ rubyforge_project:
581
+ rubygems_version: 2.6.14.4
579
582
  signing_key:
580
583
  specification_version: 4
581
584
  summary: Canvas LTI and OAUTH2 mountable engine