Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Rails 5.0+ Support (Drops Rails 4.2 Support) #192

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0a36e48
Add context argument for an authenticator to use
meanphil Aug 25, 2015
e618b1c
Created configurable authenticator context
joelvh Sep 26, 2015
1305bab
Don't assume the context is a `Hash`
joelvh Sep 26, 2015
5a99dac
Merge pull request #2 from identification-io/add_context
joelvh Nov 15, 2017
a724942
Added CHANGELOG.md
joelvh Nov 15, 2017
c946cbe
Fix deprecations and settings for Rails 4.2
joelvh Nov 15, 2017
ba37677
Fix test that never should have worked - failed after fixing deprecat…
joelvh Nov 15, 2017
9db91d9
Add testing for Ruby 2.4.0 and 2.4.1
joelvh Nov 15, 2017
47d685f
Rubocop cleanup
joelvh Nov 15, 2017
30c6485
FactoryGirl is deprecated and replaced with FactoryBot (renamed)
joelvh Nov 15, 2017
3a486e2
Loosen gem versioning
joelvh Nov 15, 2017
1db1c00
Ran `bundle exec rake rails:update` to upgrade to Rails 4.2 settings
joelvh Nov 15, 2017
aae994e
Merge pull request #3 from identification-io/feature/rails42_upgrade
joelvh Nov 15, 2017
75dfbe8
Version bump v4.2.0
joelvh Nov 15, 2017
ce179ee
Updated CHANGELOG for v4.2.0
joelvh Nov 15, 2017
e582de5
Implemented Appraisal tests for Rails 4.2, 5.0, and 5.1
joelvh Nov 15, 2017
f5b7732
Don't explicitly set this option that is not available in Rails 5.x
joelvh Nov 15, 2017
32cd2ef
Reference Rails Engine path (when mounted inside one)
joelvh Sep 25, 2015
b78aa74
Copy migrations with a generator because `rake casino:install:migrati…
joelvh Sep 25, 2015
65d2192
Simplified adding namespace to paths
joelvh Sep 26, 2015
3acb52e
Rails 5.0 deprecations fixed
joelvh Nov 15, 2017
5aa6f5d
Add extracted gem to fix failing tests
joelvh Nov 15, 2017
875a389
Updated lambda stynax
joelvh Nov 15, 2017
e0f9ec8
Use `all` scope for scope chaining instead of class
joelvh Nov 15, 2017
8b4ddf4
Updated RSpec version for specific Rails versions
joelvh Nov 15, 2017
83c84ff
Remove version constraint to allow for Rails 5.x
joelvh Nov 15, 2017
53de3b7
Add ApplicationRecord base class for models
joelvh Nov 16, 2017
93ae39b
Add migration version to migrations
joelvh Nov 16, 2017
df6f60d
Use `data_source_exists?` to check for tables and views - gets rid of…
joelvh Nov 16, 2017
7ce8f37
Set new option explicitly
joelvh Nov 16, 2017
4bf1512
Fix deprecated queries for Rails 5.0
joelvh Nov 16, 2017
f13ea3d
Use keyword arguments in integration tests for Rails 5.0
joelvh Nov 16, 2017
ef11cfc
Fixing check for empty params - IntegrationTest converts `nil` params…
joelvh Nov 16, 2017
e748e1e
Call `super` without implicit arguments
joelvh Nov 16, 2017
f0c6be1
Invert logic
joelvh Nov 16, 2017
7b20d83
Fix checks to look for blank values instead of `nil` to address Integ…
joelvh Nov 16, 2017
45bc718
Explicitly respond with 406 status because this changed in Rails 5.0 …
joelvh Nov 16, 2017
0781ba7
Drop Rails 4.2 support - mainly because of keyword arguments in RSpec…
joelvh Nov 16, 2017
3cc12e8
Version bump v5.0.0 (Rails 5.0+ support)
joelvh Nov 16, 2017
f473af1
Merge pull request #4 from identification-io/feature/rails5_upgrade
joelvh Nov 16, 2017
c233077
Remove Rails 4.2 tests
joelvh Nov 16, 2017
2e989ae
Allow Ruby 2.4.x failures
joelvh Nov 16, 2017
01cd1b4
Consolidate logic
joelvh Nov 16, 2017
723dd0d
Updated CHANGELOG
joelvh Nov 16, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global

# Ignore bundler config
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
*.gem
*.rbc
.bundle
.config
.yardoc
.rails_generators~

/coverage

/pkg

# http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
/Gemfile.lock

# Dummy application crap
/spec/dummy/log/*.log
/spec/dummy/tmp
/spec/dummy/db/*.sqlite3
gemfiles/vendor
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
*.lock
.idea/
.ruby-version
*.sqlite*
*.log
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
language: ruby
rvm:
- 2.1.0
- 2.2.2
- 2.4.0
- 2.4.1
bundler_args: --without development
gemfile:
- gemfiles/rails_5.0.gemfile
- gemfiles/rails_5.1.gemfile
matrix:
allow_failures:
- rvm: 2.4.0
- rvm: 2.4.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there failures on 2.4.0 and 2.4.1? Seems slightly concerning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pencil something is causing the appraisal gem to not load properly on Travis to be able to run the tests - started looking into it, but not conclusive yet

# gemfile: gemfiles/rails_5.0.gemfile
# gemfile: gemfiles/rails_5.1.gemfile
notifications:
hipchat:
rooms:
Expand Down
11 changes: 11 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
appraise 'rails-5.0' do
gem 'activerecord', '~> 5.0.0'
gem 'rails-controller-testing'
gem 'rspec-rails', '>= 3.5'
end

appraise 'rails-5.1' do
gem 'activerecord', '~> 5.1.0'
gem 'rails-controller-testing'
gem 'rspec-rails', '>= 3.5'
end
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 11/15/2017 - v5.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We maintain the change log for CASino using GitHub's release page.


* Drop Rails 4.2 support
* Add Appraisals
* Fix tests to use keyword arguments
* Fix bugs revealed by IntegrationTest converting `nil` to blank strings
* Addressed deprecations
* Upgraded dummy app

# 11/14/2017 - v4.2.0

* Add Ruby 2.4.0 and 2.4.1 support
* Drop Rails 4.1 support
* Update tests to address deprecations
* Replaced FactoryGirl with FactoryBot
* Fixed test that likely never worked, but did not fail because of deprecated gems
* Loosen gem versions
* Rubocop cleanup

# 9/26/2015

* Added ability to pass a `context` object when verifying user login, allowing to pass extra data such as HTTP request (e.g. subdomain) if needed [5a99dac8f83492d643c20719f2d911d27c933a68](https://github.com/identification-io/CASino/commit/5a99dac8f83492d643c20719f2d911d27c933a68)
16 changes: 16 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
source 'https://rubygems.org'

group :test do
gem 'appraisal', '>= 2.1'
gem 'capybara', '>= 2.1'
gem 'coveralls', '>= 0.7'
gem 'factory_bot', '>= 4.1'
gem 'rake', '>= 10.0'
gem 'rspec-its', '>= 1.0'
gem 'webmock', '>= 1.9'
end

# Specify your gem's dependencies in groupify.gemspec
gemspec

platforms :ruby do
gem 'sqlite3', '>= 1.3'
end
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ It currently supports [CAS 1.0 and CAS 2.0](http://apereo.github.io/cas) as well

Please check our [documentation](http://casino.rbcas.com/) for setup and configuration instructions.

## Test Suite

Run the RSpec test suite by installing the `appraisal` gem and dependencies:

$ gem install appraisal
$ appraisal install

And then running tests using `appraisal`:

$ appraisal rake

## License

CASino is released under the [MIT License](http://www.opensource.org/licenses/MIT). See LICENSE.txt for further details.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'rake'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

task :default => :spec
task default: :spec

desc 'Run all specs'
RSpec::Core::RakeTask.new(:spec) do |spec|
Expand Down
1 change: 1 addition & 0 deletions app/controllers/casino/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CASino::ApplicationController < ::ApplicationController

unless Rails.env.development?
rescue_from ActionView::MissingTemplate, with: :missing_template
rescue_from ActionController::UnknownFormat, with: :missing_template
end

def cookies
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/casino/controller_concern/ticket_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def validate_ticket(ticket)
validation_result = validate_ticket_for_service(ticket, params[:service], renew: params[:renew])
if validation_result.success?
options = { ticket: ticket }
options[:proxy_granting_ticket] = acquire_proxy_granting_ticket(params[:pgtUrl], ticket) unless params[:pgtUrl].nil?
options[:proxy_granting_ticket] = acquire_proxy_granting_ticket(params[:pgtUrl], ticket) if params[:pgtUrl].present?
build_ticket_validation_response(true, options)
else
build_ticket_validation_response(false,
Expand All @@ -21,7 +21,7 @@ def build_ticket_validation_response(success, options = {})
end

def ensure_service_ticket_parameters_present
if params[:ticket].nil? || params[:service].nil?
if params[:ticket].blank? || params[:service].blank?
build_ticket_validation_response(false,
error_code: 'INVALID_REQUEST',
error_message: '"ticket" and "service" parameters are both required')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/casino/proxy_tickets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def build_proxy_response(success, options = {})
end

def ensure_proxy_parameters_present
if params[:pgt].nil? || params[:targetService].nil?
if params[:pgt].blank? || params[:targetService].blank?
build_proxy_response(false,
error_code: 'INVALID_REQUEST',
error_message: '"pgt" and "targetService" parameters are both required')
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/casino/sessions_controller.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def index

def new
tgt = current_ticket_granting_ticket
return handle_signed_in(tgt) unless params[:renew] || tgt.nil?
redirect_to(params[:service]) if params[:gateway] && params[:service].present?
return handle_signed_in(tgt) unless params[:renew].present? || tgt.nil?
redirect_to(params[:service]) if params[:gateway].present? && params[:service].present?
end

def create
validation_result = validate_login_credentials(params[:username], params[:password])
validation_result = validate_login_credentials(params[:username], params[:password], current_authenticator_context)
if !validation_result
log_failed_login params[:username]
show_login_error I18n.t('login_credential_acceptor.invalid_login_credentials')
Expand All @@ -41,7 +41,7 @@ def destroy_others
.ticket_granting_tickets
.where('id != ?', current_ticket_granting_ticket.id)
.destroy_all if signed_in?
redirect_to params[:service] || sessions_path
redirect_to params[:service].present? ? params[:service] : sessions_path
end

def logout
Expand Down
12 changes: 8 additions & 4 deletions app/helpers/casino/sessions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def current_user
tgt.user
end

def current_authenticator_context
CASino.config.authenticator_context_builder.call(params, request)
end

def ensure_signed_in
redirect_to login_path unless signed_in?
end
Expand Down Expand Up @@ -83,12 +87,12 @@ def handle_signed_in(tgt, options = {})
end

def handle_signed_in_with_service(tgt, options)
if !service_allowed?(params[:service])
@service = params[:service]
render 'casino/sessions/service_not_allowed', status: 403
else
if service_allowed?(params[:service])
url = acquire_service_ticket(tgt, params[:service], options).service_with_ticket_url
redirect_to url, status: :see_other
else
@service = params[:service]
render 'casino/sessions/service_not_allowed', status: 403
end
end
end
3 changes: 3 additions & 0 deletions app/models/casino/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class CASino::ApplicationRecord < ActiveRecord::Base
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage of using this class over ActiveRecord::Base directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pencil Followed the Rails 5.0+ best practice. Also could serve as a better entry point for potential monkey-patching if needed.

self.abstract_class = true
end
7 changes: 3 additions & 4 deletions app/models/casino/auth_token_ticket.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
class CASino::AuthTokenTicket < ActiveRecord::Base
class CASino::AuthTokenTicket < CASino::ApplicationRecord
include CASino::ModelConcern::Ticket
include CASino::ModelConcern::ConsumableTicket

self.ticket_prefix = 'ATT'.freeze

def self.cleanup
delete_all(['created_at < ?', CASino.config.auth_token_ticket[:lifetime].seconds.ago])
where(['created_at < ?', CASino.config.auth_token_ticket[:lifetime].seconds.ago]).delete_all
end

def expired?
(Time.now - (self.created_at || Time.now)) > CASino.config.auth_token_ticket[:lifetime].seconds
(Time.now - (created_at || Time.now)) > CASino.config.auth_token_ticket[:lifetime].seconds
end

end
2 changes: 1 addition & 1 deletion app/models/casino/login_attempt.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CASino::LoginAttempt < ActiveRecord::Base
class CASino::LoginAttempt < CASino::ApplicationRecord
include CASino::ModelConcern::BrowserInfo

belongs_to :user
Expand Down
6 changes: 3 additions & 3 deletions app/models/casino/login_ticket.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class CASino::LoginTicket < ActiveRecord::Base
class CASino::LoginTicket < CASino::ApplicationRecord
include CASino::ModelConcern::Ticket
include CASino::ModelConcern::ConsumableTicket

self.ticket_prefix = 'LT'.freeze

def self.cleanup
delete_all(['created_at < ?', CASino.config.login_ticket[:lifetime].seconds.ago])
where(['created_at < ?', CASino.config.login_ticket[:lifetime].seconds.ago]).delete_all
end

def expired?
(Time.now - (self.created_at || Time.now)) > CASino.config.login_ticket[:lifetime].seconds
(Time.now - (created_at || Time.now)) > CASino.config.login_ticket[:lifetime].seconds
end
end
2 changes: 1 addition & 1 deletion app/models/casino/proxy_granting_ticket.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class CASino::ProxyGrantingTicket < ActiveRecord::Base
class CASino::ProxyGrantingTicket < CASino::ApplicationRecord
include CASino::ModelConcern::Ticket

self.ticket_prefix = 'PGT'.freeze
Expand Down
6 changes: 3 additions & 3 deletions app/models/casino/proxy_ticket.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'addressable/uri'

class CASino::ProxyTicket < ActiveRecord::Base
class CASino::ProxyTicket < CASino::ApplicationRecord
include CASino::ModelConcern::Ticket

self.ticket_prefix = 'PT'.freeze
Expand All @@ -10,11 +10,11 @@ class CASino::ProxyTicket < ActiveRecord::Base
has_many :proxy_granting_tickets, as: :granter, dependent: :destroy

def self.cleanup_unconsumed
self.destroy_all(['created_at < ? AND consumed = ?', CASino.config.proxy_ticket[:lifetime_unconsumed].seconds.ago, false])
where(['created_at < ? AND consumed = ?', CASino.config.proxy_ticket[:lifetime_unconsumed].seconds.ago, false]).destroy_all
end

def self.cleanup_consumed
self.destroy_all(['created_at < ? AND consumed = ?', CASino.config.proxy_ticket[:lifetime_consumed].seconds.ago, true])
where(['created_at < ? AND consumed = ?', CASino.config.proxy_ticket[:lifetime_consumed].seconds.ago, true]).destroy_all
end

def expired?
Expand Down
2 changes: 1 addition & 1 deletion app/models/casino/service_rule.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class CASino::ServiceRule < ActiveRecord::Base
class CASino::ServiceRule < CASino::ApplicationRecord
validates :name, presence: true
validates :url, uniqueness: true, presence: true

Expand Down
23 changes: 12 additions & 11 deletions app/models/casino/service_ticket.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'addressable/uri'

class CASino::ServiceTicket < ActiveRecord::Base
class CASino::ServiceTicket < CASino::ApplicationRecord
include CASino::ModelConcern::Ticket

self.ticket_prefix = 'ST'.freeze
Expand All @@ -10,15 +10,15 @@ class CASino::ServiceTicket < ActiveRecord::Base
has_many :proxy_granting_tickets, as: :granter, dependent: :destroy

def self.cleanup_unconsumed
self.delete_all(['created_at < ? AND consumed = ?', CASino.config.service_ticket[:lifetime_unconsumed].seconds.ago, false])
where(['created_at < ? AND consumed = ?', CASino.config.service_ticket[:lifetime_unconsumed].seconds.ago, false]).delete_all
end

def self.cleanup_consumed
self.destroy_all(['(ticket_granting_ticket_id IS NULL OR created_at < ?) AND consumed = ?', CASino.config.service_ticket[:lifetime_consumed].seconds.ago, true])
where(['(ticket_granting_ticket_id IS NULL OR created_at < ?) AND consumed = ?', CASino.config.service_ticket[:lifetime_consumed].seconds.ago, true]).destroy_all
end

def self.cleanup_consumed_hard
self.delete_all(['created_at < ? AND consumed = ?', (CASino.config.service_ticket[:lifetime_consumed] * 2).seconds.ago, true])
where(['created_at < ? AND consumed = ?', (CASino.config.service_ticket[:lifetime_consumed] * 2).seconds.ago, true]).delete_all
end

def service=(service)
Expand All @@ -27,21 +27,22 @@ def service=(service)
end

def service_with_ticket_url
service_uri = Addressable::URI.parse(self.service)
service_uri.query_values = (service_uri.query_values(Array) || []) << ['ticket', self.ticket]
service_uri = Addressable::URI.parse(service)
service_uri.query_values = (service_uri.query_values(Array) || []) << ['ticket', ticket]
service_uri.to_s
end

def expired?
lifetime = if consumed?
CASino.config.service_ticket[:lifetime_consumed]
else
CASino.config.service_ticket[:lifetime_unconsumed]
end
(Time.now - (self.created_at || Time.now)) > lifetime
CASino.config.service_ticket[:lifetime_consumed]
else
CASino.config.service_ticket[:lifetime_unconsumed]
end
(Time.now - (created_at || Time.now)) > lifetime
end

private

def send_single_sign_out_notification
notifier = SingleSignOutNotifier.new(self)
notifier.notify
Expand Down
2 changes: 1 addition & 1 deletion app/models/casino/ticket_granting_ticket.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'user_agent'

class CASino::TicketGrantingTicket < ActiveRecord::Base
class CASino::TicketGrantingTicket < CASino::ApplicationRecord
include CASino::ModelConcern::Ticket
include CASino::ModelConcern::BrowserInfo

Expand Down
Loading