diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..a048833 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,59 @@ +inherit_mode: + merge: + - Exclude +require: + - rubocop-rails +AllCops: + Exclude: + - bin/puma + - bin/pumactl + - bin/setup + - bin/rainbows + - bin/unicorn + - bin/unicorn_rails + - bin/update + - bin/yarn + - vendor/bundle/**/* + TargetRubyVersion: 2.6 +Layout/HashAlignment: + EnforcedHashRocketStyle: [ key, table ] + EnforcedColonStyle: [ key, table ] +Layout/LineLength: + Max: 200 +Metrics: + Enabled: false +Naming/MethodParameterName: + MinNameLength: 2 +Rails: + Enabled: true +Rails/DynamicFindBy: + # The models used in this code aren't actually ActiveRecord + Enabled: false +Style/AsciiComments: + AllowedChars: [ © ] +Style/Documentation: + Enabled: false +Style/DoubleNegation: + Enabled: false +Style/ClassAndModuleChildren: + Enabled: false +Style/MethodCallWithArgsParentheses: + Enabled: true + IgnoredMethods: + - desc + - gem + - include + - require + - require_relative + - ruby + - raise + - source + - throw + Exclude: + - "**/*.xml.builder" +Style/SymbolArray: + MinSize: 6 +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: consistent_comma +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: consistent_comma \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fa4019c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +sudo: required +language: ruby +cache: bundler +rvm: +- 2.7.1 +jobs: + include: + - stage: test + name: rubocop + script: bundle install & bundle exec rubocop + if: env(TEST_IGNORE) IS NOT present + - stage: test + name: test + before_script: + - bundle install + script: + - export + - bundle exec rails test + if: env(TEST_IGNORE) IS NOT present \ No newline at end of file diff --git a/Gemfile b/Gemfile index 96e9b06..032456b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,6 @@ -source "https://rubygems.org" +# frozen_string_literal: true + +source 'https://rubygems.org' # Declare your gem's dependencies in rails_lti2_provider.gemspec. # Bundler will treat runtime dependencies like base dependencies, and @@ -11,4 +13,4 @@ gemspec # your gem to rubygems.org. # To use debugger -# gem 'debugger' \ No newline at end of file +# gem 'debugger' diff --git a/Rakefile b/Rakefile index bc2f14d..b8910eb 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,9 @@ +# frozen_string_literal: true + begin require 'bundler/setup' rescue LoadError - puts 'You must `gem install bundler` and `bundle install` to run rake tasks' + puts('You must `gem install bundler` and `bundle install` to run rake tasks') end require 'rdoc/task' @@ -14,10 +16,7 @@ RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('lib/**/*.rb') end -APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__) -load 'rails/tasks/engine.rake' - - +APP_RAKEFILE = File.expand_path('spec/test_app/Rakefile', __dir__) +load('rails/tasks/engine.rake') Bundler::GemHelper.install_tasks - diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..1c38727 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,5 @@ +// frozen_string_literal: true + +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css \ No newline at end of file diff --git a/app/controllers/rails_lti2_provider/application_controller.rb b/app/controllers/rails_lti2_provider/application_controller.rb index 9780fe3..6b8c086 100644 --- a/app/controllers/rails_lti2_provider/application_controller.rb +++ b/app/controllers/rails_lti2_provider/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RailsLti2Provider class ApplicationController < ActionController::Base end diff --git a/app/controllers/rails_lti2_provider/tools_controller.rb b/app/controllers/rails_lti2_provider/tools_controller.rb index d2e6b23..553914b 100644 --- a/app/controllers/rails_lti2_provider/tools_controller.rb +++ b/app/controllers/rails_lti2_provider/tools_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RailsLti2Provider class ToolsController < ApplicationController include RailsLti2Provider::ControllerHelpers @@ -8,52 +10,51 @@ def register redirect_to_consumer(register_proxy(@registration)) end - #alternative action for custom registration workflow + # alternative action for custom registration workflow def submit_proxy registration = RailsLti2Provider::Registration.find(params[:registration_uuid]) begin response = register_proxy(registration) rescue IMS::LTI::ToolProxyRegistrationError response = { - return_url: registration.registration_request.launch_presentation_return_url, - status: 'error', - message: "Failed to create a tool proxy", + return_url: registration.registration_request.launch_presentation_return_url, + status: 'error', + message: 'Failed to create a tool proxy', } end redirect_to_consumer(response) end - def show - - end + def show; end def apply_rereg tool = Tool.where(uuid: params[:tool_proxy_guid]).first registration = tool.registrations.where(correlation_id: params[:correlation_id]).first - render status: :not_found and return unless registration + render(status: :not_found) && return unless registration + tool_proxy = tool.tool_proxy registered_proxy = registration.tool_proxy - if tc_secret = registered_proxy.tc_half_shared_secret - shared_secret = tc_secret + tool_proxy.security_contract.tp_half_shared_secret - else - shared_secret = tool_proxy.security_contract.shared_secret - end + shared_secret = if (tc_secret = registered_proxy.tc_half_shared_secret) + tc_secret + tool_proxy.security_contract.tp_half_shared_secret + else + tool_proxy.security_contract.shared_secret + end tool.transaction do - tool.shared_secret= shared_secret + tool.shared_secret = shared_secret tool.tool_settings = registered_proxy.as_json tool.lti_version = registered_proxy.lti_version tool.save! registration.update!(workflow_state: 'registered') end - render nothing: true + render(nothing: true) end def delete_rereg tool = Tool.where(uuid: params[:tool_proxy_guid]).first registration = tool.registrations.where(correlation_id: params[:correlation_id]).first - render status: :not_found and return unless registration + render(status: :not_found) && return unless registration + registration.delete! end - end end diff --git a/app/helpers/rails_lti2_provider/application_helper.rb b/app/helpers/rails_lti2_provider/application_helper.rb index b36f85f..024fc16 100644 --- a/app/helpers/rails_lti2_provider/application_helper.rb +++ b/app/helpers/rails_lti2_provider/application_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RailsLti2Provider module ApplicationHelper end diff --git a/app/helpers/rails_lti2_provider/tools_helper.rb b/app/helpers/rails_lti2_provider/tools_helper.rb index d4d1f6c..5d54884 100644 --- a/app/helpers/rails_lti2_provider/tools_helper.rb +++ b/app/helpers/rails_lti2_provider/tools_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RailsLti2Provider module ToolsHelper end diff --git a/app/models/rails_lti2_provider/lti_launch.rb b/app/models/rails_lti2_provider/lti_launch.rb index 210b1cc..8502726 100644 --- a/app/models/rails_lti2_provider/lti_launch.rb +++ b/app/models/rails_lti2_provider/lti_launch.rb @@ -1,36 +1,39 @@ +# frozen_string_literal: true + require 'ims/lti' module RailsLti2Provider - class LtiLaunch < ActiveRecord::Base - validates_presence_of :tool_id, :nonce + class LtiLaunch < ApplicationRecord + validates :tool_id, :nonce, presence: true belongs_to :tool serialize :message def self.check_launch(lti_message) tool = Tool.find_by_uuid(lti_message.oauth_consumer_key) - raise Unauthorized.new(:invalid_key) unless tool - raise Unauthorized.new(:invalid_signature) unless IMS::LTI::Services::MessageAuthenticator.new(lti_message.launch_url, lti_message.post_params.merge(lti_message.oauth_params), tool.shared_secret).valid_signature? - raise Unauthorized.new(:invalid_nonce) if tool.lti_launches.where(nonce: lti_message.oauth_nonce).count > 0 - raise Unauthorized.new(:request_too_old) if DateTime.strptime(lti_message.oauth_timestamp,'%s') < 5.minutes.ago - - Rails.logger.info "Removing the old launches from before #{1.day.ago}" - tool.lti_launches.where('created_at < ?', 1.day.ago).delete_all + raise Unauthorized, :invalid_key unless tool + unless IMS::LTI::Services::MessageAuthenticator + .new(lti_message.launch_url, + lti_message.post_params.merge(lti_message.oauth_params), tool.shared_secret).valid_signature? + raise Unauthorized, :invalid_signature + end + raise Unauthorized, :invalid_nonce if tool.lti_launches.where(nonce: lti_message.oauth_nonce).count.positive? + raise Unauthorized, :request_to_old if DateTime.strptime(lti_message.oauth_timestamp, '%s') < 5.minutes.ago - launch = tool.lti_launches.create!(nonce: lti_message.oauth_nonce, message: lti_message.post_params) - Rails.logger.info "Launch created launch=#{launch.inspect}" - launch + tool.lti_launches.where('created_at > ?', 1.day.ago).delete_all + tool.lti_launches.create(nonce: lti_message.oauth_nonce, message: lti_message.post_params) end def message - IMS::LTI::Models::Messages::Message.generate(read_attribute(:message)) + IMS::LTI::Models::Messages::Message.generate(self[:message]) end def jwt_body - read_attribute(:message) + self[:message] end - class Unauthorized < StandardError; + class Unauthorized < StandardError attr_reader :error + def initialize(error = :unknown) @error = error end diff --git a/app/models/rails_lti2_provider/registration.rb b/app/models/rails_lti2_provider/registration.rb index 71c0bfc..eb94c18 100644 --- a/app/models/rails_lti2_provider/registration.rb +++ b/app/models/rails_lti2_provider/registration.rb @@ -1,26 +1,24 @@ +# frozen_string_literal: true + module RailsLti2Provider - class Registration < ActiveRecord::Base + class Registration < ApplicationRecord validates :correlation_id, uniqueness: true, allow_nil: true serialize :tool_proxy_json, JSON serialize :registration_request_params, JSON belongs_to :tool, optional: true - def register - - end - + def register; end def registration_request @registration_request ||= IMS::LTI::Models::Messages::Message.generate(registration_request_params) end def tool_proxy - IMS::LTI::Models::ToolProxy.from_json(self.tool_proxy_json) + IMS::LTI::Models::ToolProxy.from_json(tool_proxy_json) end def tool_consumer_profile @tool_consumer_profile ||= IMS::LTI::Services::ToolProxyRegistrationService.new(registration_request).tool_consumer_profile end - end end diff --git a/app/models/rails_lti2_provider/tenant.rb b/app/models/rails_lti2_provider/tenant.rb index e2245fe..f9f7bdf 100644 --- a/app/models/rails_lti2_provider/tenant.rb +++ b/app/models/rails_lti2_provider/tenant.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module RailsLti2Provider class Tenant < ApplicationRecord - has_many :tools + has_many :tools, dependent: :restrict_with_exception end end diff --git a/app/models/rails_lti2_provider/tool.rb b/app/models/rails_lti2_provider/tool.rb index f1b6dac..a5ee616 100644 --- a/app/models/rails_lti2_provider/tool.rb +++ b/app/models/rails_lti2_provider/tool.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + module RailsLti2Provider - class Tool < ActiveRecord::Base - validates_presence_of :shared_secret, :uuid, :tool_settings, :lti_version + class Tool < ApplicationRecord + validates :shared_secret, :uuid, :tool_settings, :lti_version, presence: true serialize :tool_settings - belongs_to :tenant, foreign_key: :tenant_id - has_many :lti_launches - has_many :registrations + belongs_to :tenant, inverse_of: :tools + has_many :lti_launches, dependent: :restrict_with_exception + has_many :registrations, dependent: :restrict_with_exception def tool_proxy IMS::LTI::Models::ToolProxy.from_json(tool_settings) @@ -12,14 +14,12 @@ def tool_proxy def self.find_by_issuer(issuer, options = {}) if options.any? - puts options.inspect - Tool.where(uuid: issuer).each do |tool| + Rails.logger.warn(options.inspect) + Tool.where(uuid: issuer).find_each do |tool| tool_settings = JSON.parse(tool.tool_settings) match = true - options.each do |key, value| - if tool_settings[key] != options[key] - match = false - end + options.each do |key, _value| + match = false if tool_settings[key] != options[key] end return tool if match end diff --git a/bin/rails b/bin/rails index 3f8a9be..1e10832 100755 --- a/bin/rails +++ b/bin/rails @@ -1,11 +1,13 @@ +# frozen_string_literal: true + #!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/rails_lti2_provider/engine', __FILE__) +ENGINE_ROOT = File.expand_path('..', __dir__) +ENGINE_PATH = File.expand_path('../lib/rails_lti2_provider/engine', __dir__) # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) require 'rails/all' diff --git a/bin/rspec b/bin/rspec index 0c86b5c..c69f352 100755 --- a/bin/rspec +++ b/bin/rspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + #!/usr/bin/env ruby # # This file was generated by Bundler. @@ -7,8 +9,8 @@ # require 'pathname' -ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) require 'rubygems' require 'bundler/setup' diff --git a/config/routes.rb b/config/routes.rb index f2516f5..3b59513 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ -RailsLti2Provider::Engine.routes.draw do +# frozen_string_literal: true +RailsLti2Provider::Engine.routes.draw do Rails.application.routes.draw do RailsLti2Provider::RESOURCE_HANDLERS.each do |config| config[:messages].each do |message| @@ -17,6 +18,4 @@ put 'tool_proxy/:tool_proxy_guid', to: 'tool#apply_rereg', as: :rereg_confirmation delete 'tool_proxy/:tool_proxy_guid', to: 'tool#delete_rereg' - - end diff --git a/db/migrate/20141014213753_create_rails_lti2_provider_tool_proxies.rb b/db/migrate/20141014213753_create_rails_lti2_provider_tool_proxies.rb index bf149ad..2d7313b 100644 --- a/db/migrate/20141014213753_create_rails_lti2_provider_tool_proxies.rb +++ b/db/migrate/20141014213753_create_rails_lti2_provider_tool_proxies.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class CreateRailsLti2ProviderToolProxies < ActiveRecord::Migration[6.0] def change create_table :rails_lti2_provider_tool_proxies do |t| - t.string :uuid - t.string :shared_secret - t.text :proxy_json + t.string(:uuid) + t.string(:shared_secret) + t.text(:proxy_json) t.timestamps end diff --git a/db/migrate/20141015204601_create_rails_lti2_provider_lti_launches.rb b/db/migrate/20141015204601_create_rails_lti2_provider_lti_launches.rb index 728800a..e9f144d 100644 --- a/db/migrate/20141015204601_create_rails_lti2_provider_lti_launches.rb +++ b/db/migrate/20141015204601_create_rails_lti2_provider_lti_launches.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class CreateRailsLti2ProviderLtiLaunches < ActiveRecord::Migration[6.0] def change create_table :rails_lti2_provider_lti_launches do |t| - t.string :tool_proxy_id - t.string :nonce - t.text :message + t.string(:tool_proxy_id) + t.string(:nonce) + t.text(:message) t.timestamps end diff --git a/db/migrate/20141024195011_create_rails_lti2_provider_registrations.rb b/db/migrate/20141024195011_create_rails_lti2_provider_registrations.rb index b200d03..06bdcf2 100644 --- a/db/migrate/20141024195011_create_rails_lti2_provider_registrations.rb +++ b/db/migrate/20141024195011_create_rails_lti2_provider_registrations.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class CreateRailsLti2ProviderRegistrations < ActiveRecord::Migration[6.0] def change create_table :rails_lti2_provider_registrations do |t| - t.string :uuid - t.text :registration_request_params - t.text :tool_proxy_json - t.string :workflow_state + t.string(:uuid) + t.text(:registration_request_params) + t.text(:tool_proxy_json) + t.string(:workflow_state) t.timestamps end diff --git a/db/migrate/20141103173121_add_registration_tool_proxy.rb b/db/migrate/20141103173121_add_registration_tool_proxy.rb index cb9538e..5a3a8d1 100644 --- a/db/migrate/20141103173121_add_registration_tool_proxy.rb +++ b/db/migrate/20141103173121_add_registration_tool_proxy.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class AddRegistrationToolProxy < ActiveRecord::Migration[6.0] def change - add_column :rails_lti2_provider_registrations, :tool_proxy_id, :integer + add_column(:rails_lti2_provider_registrations, :tool_proxy_id, :integer) end end diff --git a/db/migrate/20150402153006_add_version_and_rename_tool_proxy_model.rb b/db/migrate/20150402153006_add_version_and_rename_tool_proxy_model.rb index 6b6f30d..b92c9a5 100644 --- a/db/migrate/20150402153006_add_version_and_rename_tool_proxy_model.rb +++ b/db/migrate/20150402153006_add_version_and_rename_tool_proxy_model.rb @@ -1,23 +1,24 @@ +# frozen_string_literal: true + class AddVersionAndRenameToolProxyModel < ActiveRecord::Migration[6.0] def change - rename_table :rails_lti2_provider_tool_proxies, :rails_lti2_provider_tools - add_column :rails_lti2_provider_tools, :lti_version, :string - rename_column :rails_lti2_provider_tools, :proxy_json, :tool_settings - rename_column :rails_lti2_provider_registrations, :tool_proxy_id, :tool_id - rename_column :rails_lti2_provider_lti_launches, :tool_proxy_id, :tool_id + rename_table(:rails_lti2_provider_tool_proxies, :rails_lti2_provider_tools) + add_column(:rails_lti2_provider_tools, :lti_version, :string) + rename_column(:rails_lti2_provider_tools, :proxy_json, :tool_settings) + rename_column(:rails_lti2_provider_registrations, :tool_proxy_id, :tool_id) + rename_column(:rails_lti2_provider_lti_launches, :tool_proxy_id, :tool_id) reversible do |dir| dir.up do - #set lti_version to LTI-2p0 + # set lti_version to LTI-2p0 execute <<-SQL UPDATE rails_lti2_provider_tools SET lti_version = 'LTI-2p0'; SQL end dir.down do - #lti_version will get dropped so no need to do anything + # lti_version will get dropped so no need to do anything end end - end end diff --git a/db/migrate/20150817183400_update_tool_proxy_shared_secret.rb b/db/migrate/20150817183400_update_tool_proxy_shared_secret.rb index 659aea0..d79675d 100644 --- a/db/migrate/20150817183400_update_tool_proxy_shared_secret.rb +++ b/db/migrate/20150817183400_update_tool_proxy_shared_secret.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class UpdateToolProxySharedSecret < ActiveRecord::Migration[6.0] def change - change_column :rails_lti2_provider_tools, :shared_secret, :text, limit: nil + change_column(:rails_lti2_provider_tools, :shared_secret, :text, limit: nil) end end diff --git a/db/migrate/20151203231519_update_tool_id_type.rb b/db/migrate/20151203231519_update_tool_id_type.rb index 36fbc0a..6836bc3 100644 --- a/db/migrate/20151203231519_update_tool_id_type.rb +++ b/db/migrate/20151203231519_update_tool_id_type.rb @@ -1,14 +1,14 @@ +# frozen_string_literal: true + class UpdateToolIdType < ActiveRecord::Migration[6.0] def change if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && - ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) - change_column :rails_lti2_provider_lti_launches, :tool_id, "bigint USING CAST(tool_id AS bigint)" - change_column :rails_lti2_provider_registrations, :tool_id, "bigint USING CAST(tool_id AS bigint)" + ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) + change_column(:rails_lti2_provider_lti_launches, :tool_id, 'bigint USING CAST(tool_id AS bigint)') + change_column(:rails_lti2_provider_registrations, :tool_id, 'bigint USING CAST(tool_id AS bigint)') else - change_column :rails_lti2_provider_lti_launches, :tool_id, :integer, limit: 8 - change_column :rails_lti2_provider_registrations, :tool_id, :integer, limit: 8 + change_column(:rails_lti2_provider_lti_launches, :tool_id, :integer, limit: 8) + change_column(:rails_lti2_provider_registrations, :tool_id, :integer, limit: 8) end - - end end diff --git a/db/migrate/20151204000125_add_rails_lti2_provider_registration_correlation_id.rb b/db/migrate/20151204000125_add_rails_lti2_provider_registration_correlation_id.rb index b2cac96..cb4e7d5 100644 --- a/db/migrate/20151204000125_add_rails_lti2_provider_registration_correlation_id.rb +++ b/db/migrate/20151204000125_add_rails_lti2_provider_registration_correlation_id.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class AddRailsLti2ProviderRegistrationCorrelationId < ActiveRecord::Migration[6.0] def change - add_column :rails_lti2_provider_registrations, :correlation_id, :text - add_index :rails_lti2_provider_registrations, :correlation_id, :unique => true + add_column(:rails_lti2_provider_registrations, :correlation_id, :text) + add_index(:rails_lti2_provider_registrations, :correlation_id, unique: true) end end diff --git a/db/migrate/20200831191833_create_rails_lti2_provider_tenants.rb b/db/migrate/20200831191833_create_rails_lti2_provider_tenants.rb index 98360fb..814d499 100644 --- a/db/migrate/20200831191833_create_rails_lti2_provider_tenants.rb +++ b/db/migrate/20200831191833_create_rails_lti2_provider_tenants.rb @@ -1,16 +1,18 @@ +# frozen_string_literal: true + class CreateRailsLti2ProviderTenants < ActiveRecord::Migration[6.0] def self.up create_table :rails_lti2_provider_tenants, if_not_exists: true do |t| - t.string :uid + t.string(:uid) t.timestamps end - add_index 'rails_lti2_provider_tenants', ['uid'], :name => 'index_tenant_uid', unique: true - RailsLti2Provider::Tenant.create uid: '' + add_index('rails_lti2_provider_tenants', ['uid'], name: 'index_tenant_uid', unique: true) + RailsLti2Provider::Tenant.create(uid: '') end def self.down - remove_index 'rails_lti2_provider_tenants', ['uid'] - drop_table :rails_lti2_provider_tenants + remove_index('rails_lti2_provider_tenants', ['uid']) + drop_table(:rails_lti2_provider_tenants) end end diff --git a/db/migrate/20200831193410_add_tool_association_to_tenant.rb b/db/migrate/20200831193410_add_tool_association_to_tenant.rb index 6c57db5..37afa3d 100644 --- a/db/migrate/20200831193410_add_tool_association_to_tenant.rb +++ b/db/migrate/20200831193410_add_tool_association_to_tenant.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + class AddToolAssociationToTenant < ActiveRecord::Migration[6.0] def self.up - add_column :rails_lti2_provider_tools, :tenant_id, :integer - add_index 'rails_lti2_provider_tools', ['tenant_id'], :name => 'index_tenant_id' - add_index 'rails_lti2_provider_tools', ['id', 'tenant_id'], name: 'index_tool_id_tenant_id', unique: true + add_column(:rails_lti2_provider_tools, :tenant_id, :integer) + add_index('rails_lti2_provider_tools', ['tenant_id'], name: 'index_tenant_id') + add_index('rails_lti2_provider_tools', %w[id tenant_id], name: 'index_tool_id_tenant_id', unique: true) end def self.down - remove_index 'rails_lti2_provider_tools', ['id', 'tenant_id'] - remove_index 'rails_lti2_provider_tools', ['tenant_id'] - remove_column :rails_lti2_provider_tools, :tenant_id + remove_index('rails_lti2_provider_tools', %w[id tenant_id]) + remove_index('rails_lti2_provider_tools', ['tenant_id']) + remove_column(:rails_lti2_provider_tools, :tenant_id) end end diff --git a/lib/generators/rails_lti2_provider/install/install_generator.rb b/lib/generators/rails_lti2_provider/install/install_generator.rb index 961b608..ffa8f6c 100644 --- a/lib/generators/rails_lti2_provider/install/install_generator.rb +++ b/lib/generators/rails_lti2_provider/install/install_generator.rb @@ -1,17 +1,21 @@ -class RailsLti2Provider::InstallGenerator < Rails::Generators::Base - source_root File.expand_path('../templates', __FILE__) +# frozen_string_literal: true - def create_product_instance_json - template "product_instance.json.erb", "config/product_instance.json" - end +class RailsLti2Provider + class InstallGenerator < Rails::Generators::Base + source_root File.expand_path('templates', __dir__) - private - def uuid - SecureRandom.uuid - end + def create_product_instance_json + template('product_instance.json.erb', 'config/product_instance.json') + end - def created_at - Time.now.xmlschema - end + private + def uuid + SecureRandom.uuid + end + + def created_at + Time.now.xmlschema + end + end end diff --git a/lib/generators/rails_lti2_provider/resource_handler/resource_handler_generator.rb b/lib/generators/rails_lti2_provider/resource_handler/resource_handler_generator.rb index 87d736c..4772b35 100644 --- a/lib/generators/rails_lti2_provider/resource_handler/resource_handler_generator.rb +++ b/lib/generators/rails_lti2_provider/resource_handler/resource_handler_generator.rb @@ -1,16 +1,17 @@ -class RailsLti2Provider::ResourceHandlerGenerator < Rails::Generators::NamedBase - source_root File.expand_path('../templates', __FILE__) - argument :name, type: :string - class_option :code, type: :string - class_option :description, type: :string - class_option :route_path, type: :string - class_option :controller, type: :string - class_option :action, type: :string +# frozen_string_literal: true +class RailsLti2Provider + class ResourceHandlerGenerator < Rails::Generators::NamedBase + source_root File.expand_path('templates', __dir__) + argument :name, type: :string + class_option :code, type: :string + class_option :description, type: :string + class_option :route_path, type: :string + class_option :controller, type: :string + class_option :action, type: :string - - def create_resource_handler - template "resource_handler.yml.erb", "config/resource_handlers/#{name.underscore}.yml" + def create_resource_handler + template('resource_handler.yml.erb', "config/resource_handlers/#{name.underscore}.yml") + end end - -end \ No newline at end of file +end diff --git a/lib/rails_lti2_provider.rb b/lib/rails_lti2_provider.rb index 5bdc444..7670c57 100644 --- a/lib/rails_lti2_provider.rb +++ b/lib/rails_lti2_provider.rb @@ -1,8 +1,9 @@ -require "ims/lti" +# frozen_string_literal: true -module RailsLti2Provider - require "rails_lti2_provider/engine" - require "rails_lti2_provider/tool_proxy_registration" - require "rails_lti2_provider/controller_helpers" +require 'ims/lti' +module RailsLti2Provider + require 'rails_lti2_provider/engine' + require 'rails_lti2_provider/tool_proxy_registration' + require 'rails_lti2_provider/controller_helpers' end diff --git a/lib/rails_lti2_provider/controller_helpers.rb b/lib/rails_lti2_provider/controller_helpers.rb index d924ebe..491c3ea 100644 --- a/lib/rails_lti2_provider/controller_helpers.rb +++ b/lib/rails_lti2_provider/controller_helpers.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true + module RailsLti2Provider module ControllerHelpers - def lti_authentication lti_message = IMS::LTI::Models::Messages::Message.generate(request.request_parameters) lti_message.launch_url = request.url @@ -8,25 +9,24 @@ def lti_authentication end def disable_xframe_header - response.headers.except! 'X-Frame-Options' + response.headers.except!('X-Frame-Options') end def registration_request registration_request = IMS::LTI::Models::Messages::Message.generate(params) @registration = RailsLti2Provider::Registration.new( - registration_request_params: registration_request.post_params, - tool_proxy_json: RailsLti2Provider::ToolProxyRegistration.new(registration_request, self).tool_proxy.as_json + registration_request_params: registration_request.post_params, + tool_proxy_json: RailsLti2Provider::ToolProxyRegistration.new(registration_request, self).tool_proxy.as_json ) - if registration_request.is_a? IMS::LTI::Models::Messages::ToolProxyUpdateRequest + if registration_request.is_a?(IMS::LTI::Models::Messages::ToolProxyUpdateRequest) @registration.tool = Tool.where(uuid: params['oauth_consumer_key']).first @registration.correlation_id = SecureRandom.hex(64) end @registration.save! - end def register_proxy(registration) - if registration.registration_request.is_a? IMS::LTI::Models::Messages::ToolProxyUpdateRequest + if registration.registration_request.is_a?(IMS::LTI::Models::Messages::ToolProxyUpdateRequest) RailsLti2Provider::ToolProxyRegistration.reregister(registration, self) else RailsLti2Provider::ToolProxyRegistration.register(registration, self) @@ -36,13 +36,12 @@ def register_proxy(registration) def redirect_to_consumer(registration_result) url = registration_result[:return_url] url = add_param(url, 'tool_proxy_guid', registration_result[:tool_proxy_uuid]) - if registration_result[:status] == 'success' - url = add_param(url, 'status', 'success') - redirect_to url - else - url = add_param(url, 'status', 'error') - redirect_to url - end + url = if registration_result[:status] == 'success' + add_param(url, 'status', 'success') + else + add_param(url, 'status', 'error') + end + redirect_to(url) end def add_param(url, param_name, param_value) @@ -51,6 +50,5 @@ def add_param(url, param_name, param_value) uri.query = URI.encode_www_form(params) uri.to_s end - end end diff --git a/lib/rails_lti2_provider/engine.rb b/lib/rails_lti2_provider/engine.rb index d1edffd..a670871 100644 --- a/lib/rails_lti2_provider/engine.rb +++ b/lib/rails_lti2_provider/engine.rb @@ -1,30 +1,30 @@ +# frozen_string_literal: true + module RailsLti2Provider - RESOURCE_HANDLERS = [] + RESOURCE_HANDLERS = [].freeze class Engine < ::Rails::Engine isolate_namespace RailsLti2Provider config.generators do |g| - g.test_framework :rspec, :fixture => false - g.assets false - g.helper false + g.test_framework(:rspec, fixture: false) + g.assets(false) + g.helper(false) end - initializer :resource_handlers do |app| - controllers = {} - Dir[Rails.root.join('config', 'resource_handlers', '*.yml')].each do |yml| - config = YAML.load(File.read(yml)).with_indifferent_access + initializer :resource_handlers do |_app| + Dir[Rails.root.join('config/resource_handlers/*.yml')].each do |yml| + config = YAML.safe_load(File.read(yml)).with_indifferent_access RESOURCE_HANDLERS << config end end initializer :append_migrations do |app| - unless app.root.to_s.match root.to_s - config.paths["db/migrate"].expanded.each do |expanded_path| - app.config.paths["db/migrate"] << expanded_path + unless app.root.to_s.match(root.to_s) + config.paths['db/migrate'].expanded.each do |expanded_path| + app.config.paths['db/migrate'] << expanded_path end end end - end end diff --git a/lib/rails_lti2_provider/tool_proxy_registration.rb b/lib/rails_lti2_provider/tool_proxy_registration.rb index ec26438..f696277 100644 --- a/lib/rails_lti2_provider/tool_proxy_registration.rb +++ b/lib/rails_lti2_provider/tool_proxy_registration.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true + module RailsLti2Provider class ToolProxyRegistration - attr_reader :tool_consumer_profile, :registration_state, :return_url attr_writer :shared_secret, :tool_proxy, :tool_profile, :security_contract, :product_instance, :resource_handlers @@ -20,11 +21,11 @@ def shared_secret def tool_proxy unless @tool_proxy @tool_proxy ||= IMS::LTI::Models::ToolProxy.new( - id: 'defined_by_tool_consumer', - lti_version: 'LTI-2p0', - security_contract: security_contract, - tool_consumer_profile: tool_consumer_profile.id, - tool_profile: tool_profile, + id: 'defined_by_tool_consumer', + lti_version: 'LTI-2p0', + security_contract: security_contract, + tool_consumer_profile: tool_consumer_profile.id, + tool_profile: tool_profile ) if @tool_consumer_profile.capabilities_offered.include?('OAuth.splitSecret') @tool_proxy.enabled_capability ||= [] @@ -37,10 +38,10 @@ def tool_proxy def tool_profile @tool_profile ||= IMS::LTI::Models::ToolProfile.new( - lti_version: 'LTI-2p0', - product_instance: product_instance, - resource_handler: resource_handlers, - base_url_choice: base_url_choice + lti_version: 'LTI-2p0', + product_instance: product_instance, + resource_handler: resource_handlers, + base_url_choice: base_url_choice ) end @@ -49,28 +50,30 @@ def base_url_choice end def product_instance - unless @product_instance - product_instance_config = Rails.root.join('config', 'product_instance.json') - raise 'MissingProductInstaceConfig' unless File.exist? product_instance_config - @product_instance = IMS::LTI::Models::ProductInstance.new.from_json(File.read(product_instance_config)) - end + return if @product_instance + + product_instance_config = Rails.root.join('config/product_instance.json') + raise 'MissingProductInstaceConfig' unless File.exist?(product_instance_config) + + @product_instance = IMS::LTI::Models::ProductInstance.new.from_json(File.read(product_instance_config)) end def security_contract - unless @security_contract - if @tool_consumer_profile.capabilities_offered.include?('OAuth.splitSecret') - @security_contract = IMS::LTI::Models::SecurityContract.new(tp_half_shared_secret: shared_secret) - else - @security_contract = IMS::LTI::Models::SecurityContract.new(shared_secret: shared_secret) - end - else + if @security_contract @security_contract + else + @security_contract = if @tool_consumer_profile.capabilities_offered.include?('OAuth.splitSecret') + IMS::LTI::Models::SecurityContract.new(tp_half_shared_secret: shared_secret) + else + IMS::LTI::Models::SecurityContract.new(shared_secret: shared_secret) + end end end def self.register(registration, controller) registration_request = registration.registration_request raise 'ToolProxyAlreadyRegisteredException' if registration.workflow_state == :registered + registration_service = IMS::LTI::Services::ToolProxyRegistrationService.new(registration_request) tool_proxy = registration.tool_proxy return_url = registration.registration_request.launch_presentation_return_url @@ -78,37 +81,44 @@ def self.register(registration, controller) registered_proxy = registration_service.register_tool_proxy(tool_proxy) tool_proxy.tool_proxy_guid = registered_proxy.tool_proxy_guid tool_proxy.id = controller.send(engine_name).show_tool_url(registered_proxy.tool_proxy_guid) - if tc_secret = registered_proxy.tc_half_shared_secret - shared_secret = tc_secret + tool_proxy.security_contract.tp_half_shared_secret - else - shared_secret = tool_proxy.security_contract.shared_secret - end - tp = Tool.create!(shared_secret: shared_secret, uuid: registered_proxy.tool_proxy_guid, tool_settings: tool_proxy.as_json, lti_version: tool_proxy.lti_version) + shared_secret = if (tc_secret = registered_proxy.tc_half_shared_secret) + tc_secret + tool_proxy.security_contract.tp_half_shared_secret + else + tool_proxy.security_contract.shared_secret + end + tp = Tool.create!( + shared_secret: shared_secret, + uuid: registered_proxy.tool_proxy_guid, + tool_settings: tool_proxy.as_json, + lti_version: tool_proxy.lti_version + ) registration.update(workflow_state: 'registered', tool: tp) { - tool_proxy_uuid: tool_proxy.tool_proxy_guid, - return_url: return_url, - status: 'success' + tool_proxy_uuid: tool_proxy.tool_proxy_guid, + return_url: return_url, + status: 'success', } end end def self.reregister(registration, controller) registration_request = registration.registration_request - raise 'ToolProxyAlreadyRegisteredException' if [:registered, :rereg_pending].include?(registration.workflow_state) + raise 'ToolProxyAlreadyRegisteredException' if %i[registered rereg_pending].include?(registration.workflow_state) + registration_service = IMS::LTI::Services::ToolProxyRegistrationService.new(registration_request) tool_proxy = registration.tool_proxy tool_proxy.tool_proxy_guid = registration.tool.uuid return_url = registration.registration_request.launch_presentation_return_url tool = registration.tool begin - confirmation_url = controller.send(engine_name).rereg_confirmation_url(tool.uuid, correlation_id: registration.correlation_id) + confirmation_url = controller.send(engine_name) + .rereg_confirmation_url(tool.uuid, correlation_id: registration.correlation_id) registered_proxy = registration_service.register_tool_proxy(tool_proxy, confirmation_url, tool.shared_secret) registration.update(workflow_state: 'rereg_pending', tool_proxy_json: registered_proxy.as_json) { - tool_proxy_uuid: tool_proxy.tool_proxy_guid, - return_url: return_url, - status: 'success' + tool_proxy_uuid: tool_proxy.tool_proxy_guid, + return_url: return_url, + status: 'success', } end end @@ -116,51 +126,56 @@ def self.reregister(registration, controller) def resource_handlers @resource_handlers ||= RailsLti2Provider::RESOURCE_HANDLERS.map do |handler| IMS::LTI::Models::ResourceHandler.from_json( - { - resource_type: {code: handler['code']}, - resource_name: handler['name'], - message: messages(handler['messages']) - } + resource_type: { code: handler['code'] }, + resource_name: handler['name'], + message: messages(handler['messages']) ) end end - private + class << self + private - def messages(messages) - messages.map do |m| - { + def messages(messages) + messages.map do |m| + { message_type: m['type'], - path: Rails.application.routes.url_for(only_path: true, host: @controller.request.host_with_port, controller: m['route']['controller'], action: m['route']['action']), + path: Rails.application.routes.url_for( + only_path: true, + host: @controller.request.host_with_port, + controller: m['route']['controller'], + action: m['route']['action'] + ), parameter: parameters(m['parameters']), - enabled_capability: capabilities(m) - } + enabled_capability: capabilities(m), + } + end end - end - def parameters(params) - (params || []).map do |p| - #TODO: check if variable parameters are in the capabilities offered - IMS::LTI::Models::Parameter.new(p.symbolize_keys) + def parameters(params) + (params || []).map do |p| + # TODO: check if variable parameters are in the capabilities offered + IMS::LTI::Models::Parameter.new(p.symbolize_keys) + end end - end - def capabilities(message) - req_capabilities = message['required_capabilities'] || [] - opt_capabilities = message['optional_capabilities'] || [] - raise UnsupportedCapabilitiesError unless (req_capabilities - (tool_consumer_profile.capability_offered || [])).size == 0 - req_capabilities + opt_capabilities - end + def capabilities(message) + req_capabilities = message['required_capabilities'] || [] + opt_capabilities = message['optional_capabilities'] || [] + raise UnsupportedCapabilitiesError unless (req_capabilities - (tool_consumer_profile.capability_offered || [])).empty? - def self.engine_name - engine = Rails.application.routes.named_routes.find do |r| - r[1].app.instance_variable_defined?("@app") && r[1].app.app == RailsLti2Provider::Engine + req_capabilities + opt_capabilities end - engine[1].name - end - class UnsupportedCapabilitiesError < StandardError - end + def self.engine_name + engine = Rails.application.routes.named_routes.find do |r| + r[1].app.instance_variable_defined?('@app') && r[1].app.app == RailsLti2Provider::Engine + end + engine[1].name + end + class UnsupportedCapabilitiesError < StandardError + end + end end end diff --git a/lib/rails_lti2_provider/version.rb b/lib/rails_lti2_provider/version.rb index ed9eceb..df7c610 100644 --- a/lib/rails_lti2_provider/version.rb +++ b/lib/rails_lti2_provider/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RailsLti2Provider - VERSION = "0.0.7" + VERSION = '0.0.7' end diff --git a/lib/tasks/rails_lti2_provider_tasks.rake b/lib/tasks/rails_lti2_provider_tasks.rake index 353f935..29fc46a 100644 --- a/lib/tasks/rails_lti2_provider_tasks.rake +++ b/lib/tasks/rails_lti2_provider_tasks.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # desc "Explaining what the task does" # task :rails_lti2_provider do # # Task goes here diff --git a/rails_lti2_provider.gemspec b/rails_lti2_provider.gemspec index a96482f..7405083 100644 --- a/rails_lti2_provider.gemspec +++ b/rails_lti2_provider.gemspec @@ -1,23 +1,28 @@ -$:.push File.expand_path("../lib", __FILE__) +# frozen_string_literal: true + +$LOAD_PATH.push(File.expand_path('lib', __dir__)) # Maintain your gem's version: -require "rails_lti2_provider/version" +require 'rails_lti2_provider/version' # Describe your gem and declare its dependencies: Gem::Specification.new do |s| - s.name = "rails_lti2_provider" - s.summary = "An aidee for implementing an LTI Tool provider" + s.name = 'rails_lti2_provider' + s.summary = 'An aidee for implementing an LTI Tool provider' s.version = RailsLti2Provider::VERSION - s.authors = ["Nathan Mills"] - s.homepage = %q{http://github.com/rivernate/rails_lti2_provider} - s.license = "MIT" + s.required_ruby_version = '>= 2.6' + s.authors = ['Nathan Mills'] + s.homepage = 'http://github.com/rivernate/rails_lti2_provider' + s.license = 'MIT' - s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] + s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.rdoc'] - s.add_dependency "rails", "~> 6.0.3" - s.add_dependency "ims-lti", "~> 2.3.0" + s.add_dependency('ims-lti', '~> 2.3.0') + s.add_dependency('rails', '~> 6.0.3') - s.add_development_dependency "sqlite3", "~> 1.3" - s.add_development_dependency "rspec-rails", "~> 4.0" + s.add_development_dependency('rspec-rails', '~> 4.0') + s.add_development_dependency('sqlite3', '~> 1.3') + s.add_development_dependency('rubocop', '~> 0.79.0') + s.add_development_dependency('rubocop-rails', '~> 2.4.0') end diff --git a/spec/lib/rails_lti2_provider/tool_proxy_registration_spec.rb b/spec/lib/rails_lti2_provider/tool_proxy_registration_spec.rb index 3d5088e..e3854f4 100644 --- a/spec/lib/rails_lti2_provider/tool_proxy_registration_spec.rb +++ b/spec/lib/rails_lti2_provider/tool_proxy_registration_spec.rb @@ -1,7 +1,6 @@ -require "rails_helper" - -describe RailsLti2Provider::ToolProxyRegistration do +# frozen_string_literal: true +require 'rails_helper' - -end \ No newline at end of file +describe RailsLti2Provider::ToolProxyRegistration do +end diff --git a/spec/models/rails_lti2_provider/registration_spec.rb b/spec/models/rails_lti2_provider/registration_spec.rb index 9d0f5e4..aaf778d 100644 --- a/spec/models/rails_lti2_provider/registration_spec.rb +++ b/spec/models/rails_lti2_provider/registration_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'rails_helper' module RailsLti2Provider - RSpec.describe Registration, :type => :model do + RSpec.describe(Registration, type: :model) do pending "add some examples to (or delete) #{__FILE__}" end end diff --git a/spec/models/rails_lti2_provider/tenant_spec.rb b/spec/models/rails_lti2_provider/tenant_spec.rb index dc09fd3..c6f8d4f 100644 --- a/spec/models/rails_lti2_provider/tenant_spec.rb +++ b/spec/models/rails_lti2_provider/tenant_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'rails_helper' module RailsLti2Provider - RSpec.describe Tenant, type: :model do + RSpec.describe(Tenant, type: :model) do pending "add some examples to (or delete) #{__FILE__}" end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 28d6499..41b28d7 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' -ENV["RAILS_ENV"] ||= 'test' +ENV['RAILS_ENV'] ||= 'test' require 'spec_helper' -require File.expand_path("../test_app/config/environment", __FILE__) +require File.expand_path('test_app/config/environment', __dir__) require 'rspec/rails' -ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../') +ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are @@ -13,7 +15,7 @@ # run twice. It is recommended that you do not name files matching this glob to # end with _spec.rb. You can configure this pattern with the --pattern # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. -Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f } +Dir[File.join(ENGINE_RAILS_ROOT, 'spec/support/**/*.rb')].sort.each { |f| require f } # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cfb18dc..ace408d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause this @@ -15,64 +17,62 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # These two settings work together to allow you to limit a spec run - # to individual examples or groups you care about by tagging them with - # `:focus` metadata. When nothing is tagged with `:focus`, all examples - # get run. - config.filter_run :focus - config.run_all_when_everything_filtered = true - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = 'doc' - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed - - # rspec-expectations config goes here. You can use an alternate - # assertion/expectation library such as wrong or the stdlib/minitest - # assertions if you prefer. - config.expect_with :rspec do |expectations| - # Enable only the newer, non-monkey-patching expect syntax. - # For more details, see: - # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax - expectations.syntax = :expect - end - - # rspec-mocks config goes here. You can use an alternate test double - # library (such as bogus or mocha) by changing the `mock_with` option here. - config.mock_with :rspec do |mocks| - # Enable only the newer, non-monkey-patching expect syntax. - # For more details, see: - # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - mocks.syntax = :expect - - # Prevents you from mocking or stubbing a method that does not exist on - # a real object. This is generally recommended. - mocks.verify_partial_doubles = true - end -=end + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # These two settings work together to allow you to limit a spec run + # # to individual examples or groups you care about by tagging them with + # # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # # get run. + # config.filter_run :focus + # config.run_all_when_everything_filtered = true + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = 'doc' + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed + # + # # rspec-expectations config goes here. You can use an alternate + # # assertion/expectation library such as wrong or the stdlib/minitest + # # assertions if you prefer. + # config.expect_with :rspec do |expectations| + # # Enable only the newer, non-monkey-patching expect syntax. + # # For more details, see: + # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + # expectations.syntax = :expect + # end + # + # # rspec-mocks config goes here. You can use an alternate test double + # # library (such as bogus or mocha) by changing the `mock_with` option here. + # config.mock_with :rspec do |mocks| + # # Enable only the newer, non-monkey-patching expect syntax. + # # For more details, see: + # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # mocks.syntax = :expect + # + # # Prevents you from mocking or stubbing a method that does not exist on + # # a real object. This is generally recommended. + # mocks.verify_partial_doubles = true + # end end diff --git a/spec/test_app/Rakefile b/spec/test_app/Rakefile index ba6b733..e51cf0e 100644 --- a/spec/test_app/Rakefile +++ b/spec/test_app/Rakefile @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path('../config/application', __FILE__) +require File.expand_path('config/application', __dir__) Rails.application.load_tasks diff --git a/spec/test_app/app/assets/config/manifest.js b/spec/test_app/app/assets/config/manifest.js new file mode 100644 index 0000000..5cc2c08 --- /dev/null +++ b/spec/test_app/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css \ No newline at end of file diff --git a/spec/test_app/app/controllers/application_controller.rb b/spec/test_app/app/controllers/application_controller.rb index d83690e..1ff0944 100644 --- a/spec/test_app/app/controllers/application_controller.rb +++ b/spec/test_app/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. diff --git a/spec/test_app/app/controllers/registration_controller.rb b/spec/test_app/app/controllers/registration_controller.rb index ea8535b..4595a35 100644 --- a/spec/test_app/app/controllers/registration_controller.rb +++ b/spec/test_app/app/controllers/registration_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RegistrationController < ApplicationController include RailsLti2Provider::ControllerHelpers @@ -5,10 +7,7 @@ class RegistrationController < ApplicationController protect_from_forgery except: :register after_action :disable_xframe_header, only: :register - def register - redirect_to rails_lti2_provider.submit_proxy_path(@registration.id) + redirect_to(rails_lti2_provider.submit_proxy_path(@registration.id)) end - - end diff --git a/spec/test_app/app/controllers/sample_controller.rb b/spec/test_app/app/controllers/sample_controller.rb index 775675d..198a1e2 100644 --- a/spec/test_app/app/controllers/sample_controller.rb +++ b/spec/test_app/app/controllers/sample_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SampleController < ApplicationController include RailsLti2Provider::ControllerHelpers @@ -6,8 +8,6 @@ class SampleController < ApplicationController after_action :disable_xframe_header, only: :launch def launch - - render text: 'Hello World' + render(text: 'Hello World') end - end diff --git a/spec/test_app/app/helpers/application_helper.rb b/spec/test_app/app/helpers/application_helper.rb index de6be79..15b06f0 100644 --- a/spec/test_app/app/helpers/application_helper.rb +++ b/spec/test_app/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/spec/test_app/bin/bundle b/spec/test_app/bin/bundle index 66e9889..4d5efdf 100755 --- a/spec/test_app/bin/bundle +++ b/spec/test_app/bin/bundle @@ -1,3 +1,5 @@ +# frozenn_string_literal: true + #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/spec/test_app/bin/rails b/spec/test_app/bin/rails index 728cd85..d422d94 100755 --- a/spec/test_app/bin/rails +++ b/spec/test_app/bin/rails @@ -1,4 +1,6 @@ +# frozen_string_literal: true + #!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/spec/test_app/bin/rake b/spec/test_app/bin/rake index 1724048..e591ebd 100755 --- a/spec/test_app/bin/rake +++ b/spec/test_app/bin/rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + #!/usr/bin/env ruby require_relative '../config/boot' require 'rake' diff --git a/spec/test_app/config.ru b/spec/test_app/config.ru index 5bc2a61..071a5c8 100644 --- a/spec/test_app/config.ru +++ b/spec/test_app/config.ru @@ -1,4 +1,6 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) -run Rails.application +require ::File.expand_path('config/environment', __dir__) +run(Rails.application) diff --git a/spec/test_app/config/application.rb b/spec/test_app/config/application.rb index 78902c6..0255856 100644 --- a/spec/test_app/config/application.rb +++ b/spec/test_app/config/application.rb @@ -1,15 +1,17 @@ -require File.expand_path('../boot', __FILE__) +# frozen_string_literal: true + +require File.expand_path('boot', __dir__) # Pick the frameworks you want: -require "active_record/railtie" -require "action_controller/railtie" -require "action_mailer/railtie" -require "action_view/railtie" -require "sprockets/railtie" +require 'active_record/railtie' +require 'action_controller/railtie' +require 'action_mailer/railtie' +require 'action_view/railtie' +require 'sprockets/railtie' # require "rails/test_unit/railtie" Bundler.require(*Rails.groups) -require "rails_lti2_provider" +require 'rails_lti2_provider' module TestApp class Application < Rails::Application @@ -26,4 +28,3 @@ class Application < Rails::Application # config.i18n.default_locale = :de end end - diff --git a/spec/test_app/config/boot.rb b/spec/test_app/config/boot.rb index 6266cfc..2c548c9 100644 --- a/spec/test_app/config/boot.rb +++ b/spec/test_app/config/boot.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) -$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) +$LOAD_PATH.unshift(File.expand_path('../../../lib', __dir__)) diff --git a/spec/test_app/config/environment.rb b/spec/test_app/config/environment.rb index ee8d90d..32d57aa 100644 --- a/spec/test_app/config/environment.rb +++ b/spec/test_app/config/environment.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Load the Rails application. -require File.expand_path('../application', __FILE__) +require File.expand_path('application', __dir__) # Initialize the Rails application. Rails.application.initialize! diff --git a/spec/test_app/config/environments/development.rb b/spec/test_app/config/environments/development.rb index ddf0e90..8296624 100644 --- a/spec/test_app/config/environments/development.rb +++ b/spec/test_app/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/spec/test_app/config/environments/production.rb b/spec/test_app/config/environments/production.rb index b93a877..1bd152f 100644 --- a/spec/test_app/config/environments/production.rb +++ b/spec/test_app/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/spec/test_app/config/environments/test.rb b/spec/test_app/config/environments/test.rb index 053f5b6..bd94238 100644 --- a/spec/test_app/config/environments/test.rb +++ b/spec/test_app/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/spec/test_app/config/initializers/assets.rb b/spec/test_app/config/initializers/assets.rb index d2f4ec3..761905a 100644 --- a/spec/test_app/config/initializers/assets.rb +++ b/spec/test_app/config/initializers/assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/spec/test_app/config/initializers/backtrace_silencers.rb b/spec/test_app/config/initializers/backtrace_silencers.rb index 59385cd..4b63f28 100644 --- a/spec/test_app/config/initializers/backtrace_silencers.rb +++ b/spec/test_app/config/initializers/backtrace_silencers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/spec/test_app/config/initializers/cookies_serializer.rb b/spec/test_app/config/initializers/cookies_serializer.rb index 7a06a89..0a23b25 100644 --- a/spec/test_app/config/initializers/cookies_serializer.rb +++ b/spec/test_app/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. -Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/spec/test_app/config/initializers/filter_parameter_logging.rb b/spec/test_app/config/initializers/filter_parameter_logging.rb index 4a994e1..7a4f47b 100644 --- a/spec/test_app/config/initializers/filter_parameter_logging.rb +++ b/spec/test_app/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/spec/test_app/config/initializers/inflections.rb b/spec/test_app/config/initializers/inflections.rb index ac033bf..dc84742 100644 --- a/spec/test_app/config/initializers/inflections.rb +++ b/spec/test_app/config/initializers/inflections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/spec/test_app/config/initializers/mime_types.rb b/spec/test_app/config/initializers/mime_types.rb index dc18996..be6fedc 100644 --- a/spec/test_app/config/initializers/mime_types.rb +++ b/spec/test_app/config/initializers/mime_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/spec/test_app/config/initializers/session_store.rb b/spec/test_app/config/initializers/session_store.rb index 438994f..c6f2e57 100644 --- a/spec/test_app/config/initializers/session_store.rb +++ b/spec/test_app/config/initializers/session_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: '_test_app_session' +Rails.application.config.session_store(:cookie_store, key: '_test_app_session') diff --git a/spec/test_app/config/initializers/wrap_parameters.rb b/spec/test_app/config/initializers/wrap_parameters.rb index 33725e9..246168a 100644 --- a/spec/test_app/config/initializers/wrap_parameters.rb +++ b/spec/test_app/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/spec/test_app/config/routes.rb b/spec/test_app/config/routes.rb index c49e426..7c04859 100644 --- a/spec/test_app/config/routes.rb +++ b/spec/test_app/config/routes.rb @@ -1,6 +1,7 @@ -Rails.application.routes.draw do +# frozen_string_literal: true - post "/register", to: "registration#register" +Rails.application.routes.draw do + post '/register', params: { to: 'registration#register' } - mount RailsLti2Provider::Engine => "/rails_lti2_provider", as: :rails_lti2_provider + mount RailsLti2Provider::Engine => '/rails_lti2_provider', as: :rails_lti2_provider end diff --git a/spec/test_app/db/schema.rb b/spec/test_app/db/schema.rb index fd843a9..84f9110 100644 --- a/spec/test_app/db/schema.rb +++ b/spec/test_app/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -10,35 +12,33 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2015_12_04_000125) do - - create_table "rails_lti2_provider_lti_launches", force: :cascade do |t| - t.integer "tool_id", limit: 8 - t.string "nonce" - t.text "message" - t.datetime "created_at" - t.datetime "updated_at" +ActiveRecord::Schema.define(version: 20_151_204_000_125) do + create_table 'rails_lti2_provider_lti_launches', force: :cascade do |t| + t.integer('tool_id', limit: 8) + t.string('nonce') + t.text('message') + t.datetime('created_at') + t.datetime('updated_at') end - create_table "rails_lti2_provider_registrations", force: :cascade do |t| - t.string "uuid" - t.text "registration_request_params" - t.text "tool_proxy_json" - t.string "workflow_state" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "tool_id", limit: 8 - t.text "correlation_id" - t.index ["correlation_id"], name: "index_rails_lti2_provider_registrations_on_correlation_id", unique: true + create_table 'rails_lti2_provider_registrations', force: :cascade do |t| + t.string('uuid') + t.text('registration_request_params') + t.text('tool_proxy_json') + t.string('workflow_state') + t.datetime('created_at') + t.datetime('updated_at') + t.integer('tool_id', limit: 8) + t.text('correlation_id') + t.index(['correlation_id'], name: 'index_rails_lti2_provider_registrations_on_correlation_id', unique: true) end - create_table "rails_lti2_provider_tools", force: :cascade do |t| - t.string "uuid" - t.text "shared_secret" - t.text "tool_settings" - t.datetime "created_at" - t.datetime "updated_at" - t.string "lti_version" + create_table 'rails_lti2_provider_tools', force: :cascade do |t| + t.string('uuid') + t.text('shared_secret') + t.text('tool_settings') + t.datetime('created_at') + t.datetime('updated_at') + t.string('lti_version') end - end