diff --git a/Gemfile b/Gemfile index 44cd9543..716918f1 100644 --- a/Gemfile +++ b/Gemfile @@ -68,8 +68,8 @@ gem 'grape_on_rails_routes' gem 'hydra-role-management' gem 'hyrax', '2.9.6' gem 'mysql2', '~> 0.4.10' -gem 'omniauth-openid' -gem 'omniauth-shibboleth' + gem 'omniauth-openid' + gem 'omniauth-shibboleth' gem 'orcid', git: 'https://github.com/uclibs/orcid', branch: 'rails-5.x' gem 'riiif', '~> 2.0' gem 'rsolr', '>= 1.0' @@ -81,10 +81,10 @@ group :development, :test do gem 'bixby', '>= 1.0.0' gem 'byebug', platform: :mri gem 'fcrepo_wrapper' - gem 'rails-controller-testing' + gem 'rails-controller-testing' gem 'rspec-its' gem 'rspec-rails' - gem 'show_me_the_cookies' + gem 'show_me_the_cookies' gem 'solr_wrapper', '>= 0.3' gem 'vcr' gem 'webmock' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 010629f5..c83555d4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,30 +15,30 @@ class ApplicationController < ActionController::Base with_themed_layout '1_column' protect_from_forgery with: :exception - private + private - # override devise helper and route to CC.new when parameter is set - def after_sign_in_path_for(resource) - cookies[:login_type] = { - value: "local", - secure: Rails.env.production? - } - if !resource.waived_welcome_page - Rails.application.routes.url_helpers.welcome_page_index_path - else - Rails.application.routes.url_helpers.new_classify_concern_path + # override devise helper and route to CC.new when parameter is set + def after_sign_in_path_for(resource) + cookies[:login_type] = { + value: "local", + secure: Rails.env.production? + } + if !resource.waived_welcome_page + Rails.application.routes.url_helpers.welcome_page_index_path + else + Rails.application.routes.url_helpers.new_classify_concern_path + end end - end - def after_sign_out_path_for(_resource_or_scope) - if cookies[:login_type] == "shibboleth" - "/Shibboleth.sso/Logout?return=https%3A%2F%2F" + ENV['SCHOLAR_SHIBBOLETH_LOGOUT'] - else - root_path + def after_sign_out_path_for(_resource_or_scope) + if cookies[:login_type] == "shibboleth" + "/Shibboleth.sso/Logout?return=https%3A%2F%2F" + ENV['SCHOLAR_SHIBBOLETH_LOGOUT'] + else + root_path + end end - end - def auth_shib_user! - redirect_to login_path unless user_signed_in? - end + def auth_shib_user! + redirect_to login_path unless user_signed_in? + end end diff --git a/app/controllers/callbacks_controller.rb b/app/controllers/callbacks_controller.rb index c08a591b..94d19d2a 100644 --- a/app/controllers/callbacks_controller.rb +++ b/app/controllers/callbacks_controller.rb @@ -7,79 +7,79 @@ def orcid redirect_to root_path, notice: "You have successfully connected with your ORCID record" end - def shibboleth - if current_user - redirect_to Hyrax::Engine.routes.url_helpers.dashboard_path - else - retrieve_shibboleth_attributes - create_or_update_user - sign_in_shibboleth_user + def shibboleth + if current_user + redirect_to Hyrax::Engine.routes.url_helpers.dashboard_path + else + retrieve_shibboleth_attributes + create_or_update_user + sign_in_shibboleth_user + end end - end - private + private - def retrieve_shibboleth_attributes - @omni = request.env["omniauth.auth"] - @email = use_uid_if_email_is_blank - end + def retrieve_shibboleth_attributes + @omni = request.env["omniauth.auth"] + @email = use_uid_if_email_is_blank + end - def create_or_update_user - unless user_exists? - create_user - send_welcome_email + def create_or_update_user + unless user_exists? + create_user + send_welcome_email + end + update_user_shibboleth_attributes if user_has_never_logged_in? + update_user_shibboleth_perishable_attributes end - update_user_shibboleth_attributes if user_has_never_logged_in? - update_user_shibboleth_perishable_attributes - end - def sign_in_shibboleth_user - sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated - cookies[:login_type] = { - value: "shibboleth", - secure: Rails.env.production? - } - flash[:notice] = "You are now signed in as #{@user.name} (#{@user.email})" - end + def sign_in_shibboleth_user + sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated + cookies[:login_type] = { + value: "shibboleth", + secure: Rails.env.production? + } + flash[:notice] = "You are now signed in as #{@user.name} (#{@user.email})" + end - def use_uid_if_email_is_blank - # If user has no email address use their sixplus2@uc.edu instead - # Some test accounts on QA/dev don't have email addresses - return @omni.extra.raw_info.mail if defined?(@omni.extra.raw_info.mail) && @omni.extra.raw_info.mail.present? - @omni.uid - end + def use_uid_if_email_is_blank + # If user has no email address use their sixplus2@uc.edu instead + # Some test accounts on QA/dev don't have email addresses + return @omni.extra.raw_info.mail if defined?(@omni.extra.raw_info.mail) && @omni.extra.raw_info.mail.present? + @omni.uid + end - def user_exists? - @user = User.where(provider: @omni['provider'], uid: @omni['uid']).first - end + def user_exists? + @user = User.where(provider: @omni['provider'], uid: @omni['uid']).first + end - def user_has_never_logged_in? - @user.sign_in_count.zero? - end + def user_has_never_logged_in? + @user.sign_in_count.zero? + end - def create_user - @user = User.create provider: @omni.provider, - uid: @omni.uid, - email: @email, - password: Devise.friendly_token[0, 20], - profile_update_not_required: false - end + def create_user + @user = User.create provider: @omni.provider, + uid: @omni.uid, + email: @email, + password: Devise.friendly_token[0, 20], + profile_update_not_required: false + end - def update_user_shibboleth_attributes - @user.title = @omni.extra.raw_info.title - @user.telephone = @omni.extra.raw_info.telephoneNumber - @user.first_name = @omni.extra.raw_info.givenName - @user.last_name = @omni.extra.raw_info.sn - @user.save - end + def update_user_shibboleth_attributes + @user.title = @omni.extra.raw_info.title + @user.telephone = @omni.extra.raw_info.telephoneNumber + @user.first_name = @omni.extra.raw_info.givenName + @user.last_name = @omni.extra.raw_info.sn + @user.save + end - def update_user_shibboleth_perishable_attributes - @user.uc_affiliation = @omni.extra.raw_info.uceduPrimaryAffiliation - @user.ucdepartment = @omni.extra.raw_info.ou - @user.save - end + def update_user_shibboleth_perishable_attributes + @user.uc_affiliation = @omni.extra.raw_info.uceduPrimaryAffiliation + @user.ucdepartment = @omni.extra.raw_info.ou + @user.save + end - def send_welcome_email - WelcomeMailer.welcome_email(@user).deliver - end + def send_welcome_email + WelcomeMailer.welcome_email(@user).deliver + end end diff --git a/app/controllers/devise/passwords_controller.rb b/app/controllers/devise/passwords_controller.rb index 9dafaa1c..1ed210dd 100644 --- a/app/controllers/devise/passwords_controller.rb +++ b/app/controllers/devise/passwords_controller.rb @@ -1,21 +1,21 @@ -# frozen_string_literal: true + # frozen_string_literal: true -require Devise::Engine.root.join('app/controllers/devise/passwords_controller.rb') -class Devise::PasswordsController - # POST /resource/password - def create - if resource_params['email'].end_with? '@uc.edu' - redirect_to login_path - flash[:notice] = "You cannot reset passwords for @uc.edu accounts. Use your UC Central Login instead." - else - self.resource = resource_class.send_reset_password_instructions(resource_params) - yield resource if block_given? - - if successfully_sent?(resource) - respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name)) + require Devise::Engine.root.join('app/controllers/devise/passwords_controller.rb') + class Devise::PasswordsController + # POST /resource/password + def create + if resource_params['email'].end_with? '@uc.edu' + redirect_to login_path + flash[:notice] = "You cannot reset passwords for @uc.edu accounts. Use your UC Central Login instead." else - respond_with(resource) + self.resource = resource_class.send_reset_password_instructions(resource_params) + yield resource if block_given? + + if successfully_sent?(resource) + respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name)) + else + respond_with(resource) + end end end end -end diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 4433a9a0..5580de77 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -49,15 +49,15 @@ def doi_help render "static/doi_help" end - def login - if current_user - redirect_to Hyrax::Engine.routes.url_helpers.dashboard_path - elsif AUTH_CONFIG['shibboleth_enabled'] - render "static/login" - else - redirect_to new_user_session_path + def login + if current_user + redirect_to Hyrax::Engine.routes.url_helpers.dashboard_path + elsif AUTH_CONFIG['shibboleth_enabled'] + render "static/login" + else + redirect_to new_user_session_path + end end - end def whats_new render "static/whats_new" diff --git a/app/models/user.rb b/app/models/user.rb index b980335a..c8aef0ff 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,8 +15,8 @@ class User < ApplicationRecord include Blacklight::User # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable - devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, :omniauthable, omniauth_providers: [:orcid, :shibboleth] + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable, :omniauthable, omniauth_providers: [:orcid, :shibboleth] # Method added by Blacklight; Blacklight uses #to_s on your # user class to get a user-displayable login/identifier for diff --git a/app/views/_user_util_links.html.erb b/app/views/_user_util_links.html.erb index f4d22a26..bdfe0d5f 100644 --- a/app/views/_user_util_links.html.erb +++ b/app/views/_user_util_links.html.erb @@ -19,9 +19,9 @@
  • <%= link_to t("hyrax.toolbar.profile.view"), hyrax.dashboard_profile_path(current_user) %>
  • <%= link_to t("hyrax.toolbar.profile.edit"), hyrax.edit_dashboard_profile_path(current_user) %>
  • - <% unless current_user.provider == "shibboleth" %> -
  • <%= link_to t("hyku.toolbar.profile.edit_registration"), main_app.edit_user_registration_path %>
  • - <% end %> + <% unless current_user.provider == "shibboleth" %> +
  • <%= link_to t("hyku.toolbar.profile.edit_registration"), main_app.edit_user_registration_path %>
  • + <% end %>
  • <%= link_to t("hyrax.toolbar.profile.logout"), main_app.destroy_user_session_path %>
  • diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index f282ee0b..6a963df1 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -1,16 +1,16 @@ -

    Forgot your password?

    +

    Forgot your password?

    -

    Note: If you have a uc.edu email address, do not use this form to reset your password. Use the <%= link_to 'Central Login form', user_shibboleth_omniauth_authorize_path %> instead.

    +

    Note: If you have a uc.edu email address, do not use this form to reset your password. Use the <%= link_to 'Central Login form', user_shibboleth_omniauth_authorize_path %> instead.

    -<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> - <%= render "devise/shared/error_messages", resource: resource %> + <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> -
    - <%= f.label :email %>
    - <%= f.email_field :email, autofocus: true %> -
    +
    + <%= f.label :email %>
    + <%= f.email_field :email, autofocus: true %> +
    -
    -

    <%= f.submit "Send me reset password instructions" %>

    -
    -<% end %> +
    +

    <%= f.submit "Send me reset password instructions" %>

    +
    + <% end %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index f1993f64..53881dfe 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,37 +1,37 @@ -

    Edit <%= resource_name.to_s.humanize %>

    -<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> - <%= render "devise/shared/error_messages", resource: resource %> -
    - <%= f.label :email %>
    - <%= f.email_field :email, autofocus: true, autocomplete: "email" %> -
    +

    Edit <%= resource_name.to_s.humanize %>

    + <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> +
    + <%= f.label :email %>
    + <%= f.email_field :email, autofocus: true, autocomplete: "email" %> +
    - <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> -
    Currently waiting confirmation for: <%= resource.unconfirmed_email %>
    - <% end %> - -
    - <%= f.label :password %> (leave blank if you don't want to change it)
    - <%= f.password_field :password, autocomplete: "new-password" %> - <% if @minimum_password_length %> -
    - <%= @minimum_password_length %> characters minimum + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
    Currently waiting confirmation for: <%= resource.unconfirmed_email %>
    <% end %> -
    -
    - <%= f.label :password_confirmation %>
    - <%= f.password_field :password_confirmation, autocomplete: "new-password" %> -
    +
    + <%= f.label :password %> (leave blank if you don't want to change it)
    + <%= f.password_field :password, autocomplete: "new-password" %> + <% if @minimum_password_length %> +
    + <%= @minimum_password_length %> characters minimum + <% end %> +
    -
    - <%= f.label :current_password %> (we need your current password to confirm your changes)
    - <%= f.password_field :current_password, autocomplete: "current-password" %> -
    +
    + <%= f.label :password_confirmation %>
    + <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
    -
    - <%= f.submit "Update" %> -
    -<% end %> +
    + <%= f.label :current_password %> (we need your current password to confirm your changes)
    + <%= f.password_field :current_password, autocomplete: "current-password" %> +
    + +
    + <%= f.submit "Update" %> +
    + <% end %> -<%= link_to "Back", :back %> + <%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index f60f75ac..72cb919f 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,31 +1,31 @@ -

    Sign up

    +

    Sign up

    -<% if AUTH_CONFIG['signups_enabled'] %> - <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> - <%= render "devise/shared/error_messages", resource: resource %> + <% if AUTH_CONFIG['signups_enabled'] %> + <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= render "devise/shared/error_messages", resource: resource %> -
    - <%= f.label :email %>
    - <%= f.email_field :email, autofocus: true %> -
    +
    + <%= f.label :email %>
    + <%= f.email_field :email, autofocus: true %> +
    -
    - <%= f.label :password %> - <% if @minimum_password_length %> - (<%= @minimum_password_length %> characters minimum) - <% end %>
    - <%= f.password_field :password, autocomplete: "new-password" %> -
    +
    + <%= f.label :password %> + <% if @minimum_password_length %> + (<%= @minimum_password_length %> characters minimum) + <% end %>
    + <%= f.password_field :password, autocomplete: "new-password" %> +
    -
    - <%= f.label :password_confirmation %>
    - <%= f.password_field :password_confirmation, autocomplete: "new-password" %> -
    +
    + <%= f.label :password_confirmation %>
    + <%= f.password_field :password_confirmation, autocomplete: "new-password" %> +
    -
    - <%= f.submit "Sign up" %> -
    +
    + <%= f.submit "Sign up" %> +
    + <% end %> + <% else %> +

    To request an account, <%= link_to 'use the contact page', contact_path %>.

    <% end %> -<% else %> -

    To request an account, <%= link_to 'use the contact page', contact_path %>.

    -<% end %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 254fb364..04cabff4 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,39 +1,39 @@ -
    -
    -

    Local Account Log in

    +
    +
    +

    Local Account Log in

    - <% if AUTH_CONFIG['shibboleth_enabled'] %> -

    Note: If you are affiliated with UC, use the <%= link_to 'Central Login form', user_shibboleth_omniauth_authorize_path %> instead.

    - <% end %> - - <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> -
    - <%= f.label :email %>
    - <%= f.email_field :email, autofocus: true %> -
    + <% if AUTH_CONFIG['shibboleth_enabled'] %> +

    Note: If you are affiliated with UC, use the <%= link_to 'Central Login form', user_shibboleth_omniauth_authorize_path %> instead.

    + <% end %> -
    - <%= f.label :password %>
    - <%= f.password_field :password, autocomplete: "current-password" %> -
    + <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
    + <%= f.label :email %>
    + <%= f.email_field :email, autofocus: true %> +
    - <% if devise_mapping.rememberable? %>
    - <%= f.check_box :remember_me %> - <%= f.label :remember_me %> + <%= f.label :password %>
    + <%= f.password_field :password, autocomplete: "current-password" %>
    - <% end %> -
    -

    <%= f.submit "Log in" %>

    -
    - <% end %> + <% if devise_mapping.rememberable? %> +
    + <%= f.check_box :remember_me %> + <%= f.label :remember_me %> +
    + <% end %> - <% if AUTH_CONFIG['signups_enabled'] %> - <%= link_to 'Sign up', new_user_registration_path %> -
    - <% end %> +
    +

    <%= f.submit "Log in" %>

    +
    + <% end %> + + <% if AUTH_CONFIG['signups_enabled'] %> + <%= link_to 'Sign up', new_user_registration_path %> +
    + <% end %> -

    <%= link_to 'Reset/Forgot your password?', new_user_password_path %>

    +

    <%= link_to 'Reset/Forgot your password?', new_user_password_path %>

    +
    -
    \ No newline at end of file diff --git a/app/views/static/login.html.erb b/app/views/static/login.html.erb index ef84dedd..2ac6f24b 100644 --- a/app/views/static/login.html.erb +++ b/app/views/static/login.html.erb @@ -1,16 +1,16 @@ -
    -
    -

    Log In

    +
    +
    +

    Log In

    -
    -

    If you have a UC Central Login username, you can use it to log in to Scholar@UC.

    -

    <%= link_to 'Log in using your UC Central Login', '/users/auth/shibboleth', class: 'btn btn-primary', style: 'font-size: larger' %>

    -
    +
    +

    If you have a UC Central Login username, you can use it to log in to Scholar@UC.

    +

    <%= link_to 'Log in using your UC Central Login', '/users/auth/shibboleth', class: 'btn btn-primary', style: 'font-size: larger' %>

    +
    -
    -  
    -

    Other Users

    -

    If you're not affiliated with UC, but have been given an account for <%= t('hyrax.product_name') %>, you can <%= link_to 'log in using a local account', new_user_session_path %>. To request an account, <%= link_to 'use the contact page', contact_path %>.

    +
    +  
    +

    Other Users

    +

    If you're not affiliated with UC, but have been given an account for <%= t('hyrax.product_name') %>, you can <%= link_to 'log in using a local account', new_user_session_path %>. To request an account, <%= link_to 'use the contact page', contact_path %>.

    +
    -
    \ No newline at end of file diff --git a/config/authentication.yml b/config/authentication.yml index ac4e1395..503fed26 100644 --- a/config/authentication.yml +++ b/config/authentication.yml @@ -1,11 +1,11 @@ -development: - shibboleth_enabled: <%= ENV["SCHOLAR_SHIBBOLETH_ENABLED"] %> - signups_enabled: <%= ENV["SCHOLAR_SIGNUPS_ENABLED"] %> + development: + shibboleth_enabled: <%= ENV["SCHOLAR_SHIBBOLETH_ENABLED"] %> + signups_enabled: <%= ENV["SCHOLAR_SIGNUPS_ENABLED"] %> -test: - shibboleth_enabled: <%= ENV["SCHOLAR_SHIBBOLETH_ENABLED"] %> - signups_enabled: <%= ENV["SCHOLAR_SIGNUPS_ENABLED"] %> + test: + shibboleth_enabled: <%= ENV["SCHOLAR_SHIBBOLETH_ENABLED"] %> + signups_enabled: <%= ENV["SCHOLAR_SIGNUPS_ENABLED"] %> -production: - shibboleth_enabled: <%= ENV["SCHOLAR_SHIBBOLETH_ENABLED"] %> - signups_enabled: <%= ENV["SCHOLAR_SIGNUPS_ENABLED"] %> + production: + shibboleth_enabled: <%= ENV["SCHOLAR_SHIBBOLETH_ENABLED"] %> + signups_enabled: <%= ENV["SCHOLAR_SIGNUPS_ENABLED"] %> diff --git a/config/initializers/authentication_config.rb b/config/initializers/authentication_config.rb index f995c0b5..3808d3f4 100644 --- a/config/initializers/authentication_config.rb +++ b/config/initializers/authentication_config.rb @@ -1,3 +1,3 @@ -# frozen_string_literal: true + # frozen_string_literal: true -AUTH_CONFIG = YAML.safe_load(ERB.new(File.read(Rails.root.join('config', 'authentication.yml'))).result)[Rails.env] + AUTH_CONFIG = YAML.safe_load(ERB.new(File.read(Rails.root.join('config', 'authentication.yml'))).result)[Rails.env] diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index dda9c261..e8f96b2c 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -259,37 +259,37 @@ # The default HTTP method used to sign out a resource. Default is :delete. config.sign_out_via = :get - # ==> OmniAuth - # Add a new OmniAuth provider. Check the wiki for more information on setting - # up on your models and hooks. - # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' - config.omniauth :shibboleth, - shib_session_id_field: "Shib-Session-ID", - shib_application_id_field: "Shib-Application-ID", - uid_field: "eppn", - name_field: "displayName", - debug: false, - extra_fields: [ - :cn, - :eppn, - :givenName, - :ou, - :'persistent-id', - :sn, - :street, - :title, - :uceduAffiliation, - :uceduPrimaryAffiliation, - :uceduUCID, - :mail, - :affiliation, - :remoteuser, - :telephoneNumber, - :uceduAcademicProgram, - :uceduFERPACode, - :uceduPrimaryCollege, - :uceduSISPersonID - ] + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + config.omniauth :shibboleth, + shib_session_id_field: "Shib-Session-ID", + shib_application_id_field: "Shib-Application-ID", + uid_field: "eppn", + name_field: "displayName", + debug: false, + extra_fields: [ + :cn, + :eppn, + :givenName, + :ou, + :'persistent-id', + :sn, + :street, + :title, + :uceduAffiliation, + :uceduPrimaryAffiliation, + :uceduUCID, + :mail, + :affiliation, + :remoteuser, + :telephoneNumber, + :uceduAcademicProgram, + :uceduFERPACode, + :uceduPrimaryCollege, + :uceduSISPersonID + ] # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/routes.rb b/config/routes.rb index e91082c5..bf377667 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,12 +26,12 @@ mount Sidekiq::Web => '/sidekiq' end - devise_for :users, controllers: { omniauth_callbacks: 'callbacks', registrations: "registrations" } + devise_for :users, controllers: { omniauth_callbacks: 'callbacks', registrations: "registrations" } mount Hydra::RoleManagement::Engine => '/' resources :users, only: [:index], constraints: { format: :html }, controller: 'display_users' - get 'login' => 'static#login' + get 'login' => 'static#login' get 'about' => 'static#about' get 'help' => 'static#help' get 'contact' => 'hyrax/contact_form#new' diff --git a/db/migrate/20170718204534_add_columns_to_users.rb b/db/migrate/20170718204534_add_columns_to_users.rb index ccda9662..b2761c68 100644 --- a/db/migrate/20170718204534_add_columns_to_users.rb +++ b/db/migrate/20170718204534_add_columns_to_users.rb @@ -1,6 +1,6 @@ -class AddColumnsToUsers < ActiveRecord::Migration[5.1] - def change - add_column :users, :provider, :string - add_column :users, :uid, :string + class AddColumnsToUsers < ActiveRecord::Migration[5.1] + def change + add_column :users, :provider, :string + add_column :users, :uid, :string + end end -end diff --git a/spec/controllers/callbacks_controller_spec.rb b/spec/controllers/callbacks_controller_spec.rb index 94298e3a..92883ac5 100644 --- a/spec/controllers/callbacks_controller_spec.rb +++ b/spec/controllers/callbacks_controller_spec.rb @@ -42,82 +42,17 @@ end end - describe 'omniauth-shibboleth' do - let(:uid) { 'sixplus2@test.com' } - let(:provider) { :shibboleth } - - before do - @request.env["devise.mapping"] = Devise.mappings[:user] - omniauth_hash = { provider: 'shibboleth', - uid: uid, - extra: { - raw_info: { - mail: uid, - title: 'title', - telephoneNumber: '123-456-7890', - givenName: 'Fake', - sn: 'User', - uceduPrimaryAffiliation: 'staff', - ou: 'department' - } - } } - OmniAuth.config.add_mock(provider, omniauth_hash) - request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider] - end - - context 'with a user who is already logged in' do - let(:user) { FactoryBot.create(:user) } - - before do - controller.stub(:current_user).and_return(user) - end - it 'redirects to the dashboard' do - get provider - expect(response).to redirect_to(Hyrax::Engine.routes.url_helpers.dashboard_path) - end - end - - shared_examples 'Shibboleth login' do - it 'assigns the user and redirects' do - get provider - expect(flash[:notice]).to match(/You are now signed in as */) - expect(cookies[:login_type]).not_to eq(nil) - expect(assigns(:user).email).to eq(email) - expect(assigns(:user).provider).to eq('shibboleth') - expect(assigns(:user).uid).to eq(request.env["omniauth.auth"]["uid"]) - expect(assigns(:user).profile_update_not_required).to eq(false) - expect(response).to be_redirect - end - end - - context 'with a brand new user' do - let(:email) { uid } - - it_behaves_like 'Shibboleth login' - - it 'updates the shibboleth attributes' do - get provider - expect(assigns(:user).title).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["title"]) - expect(assigns(:user).telephone).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["telephoneNumber"]) - expect(assigns(:user).first_name).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["givenName"]) - expect(assigns(:user).last_name).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["sn"]) - expect(assigns(:user).uc_affiliation).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["uceduPrimaryAffiliation"]) - expect(assigns(:user).ucdepartment).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["ou"]) - end + describe 'omniauth-shibboleth' do + let(:uid) { 'sixplus2@test.com' } + let(:provider) { :shibboleth } - it 'sends a welcome email' do - ActionMailer::Base.deliveries = [] - get provider - expect(ActionMailer::Base.deliveries.count).to eq(1) - end - end - - context 'with a brand new user when Shibboleth email is not defined' do before do + @request.env["devise.mapping"] = Devise.mappings[:user] omniauth_hash = { provider: 'shibboleth', uid: uid, extra: { raw_info: { + mail: uid, title: 'title', telephoneNumber: '123-456-7890', givenName: 'Fake', @@ -129,81 +64,146 @@ OmniAuth.config.add_mock(provider, omniauth_hash) request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider] end - let(:email) { uid } - it_behaves_like 'Shibboleth login' - end + context 'with a user who is already logged in' do + let(:user) { FactoryBot.create(:user) } - context 'with a brand new user when Shibboleth email is blank' do - before do - omniauth_hash = { provider: 'shibboleth', - uid: uid, - extra: { - raw_info: { - mail: '', - title: 'title', - telephoneNumber: '123-456-7890', - givenName: 'Fake', - sn: 'User', - uceduPrimaryAffiliation: 'staff', - ou: 'department' - } - } } - OmniAuth.config.add_mock(provider, omniauth_hash) - request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider] + before do + controller.stub(:current_user).and_return(user) + end + it 'redirects to the dashboard' do + get provider + expect(response).to redirect_to(Hyrax::Engine.routes.url_helpers.dashboard_path) + end end - let(:email) { uid } - it_behaves_like 'Shibboleth login' - end + shared_examples 'Shibboleth login' do + it 'assigns the user and redirects' do + get provider + expect(flash[:notice]).to match(/You are now signed in as */) + expect(cookies[:login_type]).not_to eq(nil) + expect(assigns(:user).email).to eq(email) + expect(assigns(:user).provider).to eq('shibboleth') + expect(assigns(:user).uid).to eq(request.env["omniauth.auth"]["uid"]) + expect(assigns(:user).profile_update_not_required).to eq(false) + expect(response).to be_redirect + end + end - context 'with a registered user who has previously logged in' do - let!(:user) { FactoryBot.create(:shibboleth_user, count: 1, profile_update_not_required: false) } - let(:email) { user.email } + context 'with a brand new user' do + let(:email) { uid } + + it_behaves_like 'Shibboleth login' + + it 'updates the shibboleth attributes' do + get provider + expect(assigns(:user).title).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["title"]) + expect(assigns(:user).telephone).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["telephoneNumber"]) + expect(assigns(:user).first_name).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["givenName"]) + expect(assigns(:user).last_name).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["sn"]) + expect(assigns(:user).uc_affiliation).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["uceduPrimaryAffiliation"]) + expect(assigns(:user).ucdepartment).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["ou"]) + end + + it 'sends a welcome email' do + ActionMailer::Base.deliveries = [] + get provider + expect(ActionMailer::Base.deliveries.count).to eq(1) + end + end - it_behaves_like 'Shibboleth login' - end + context 'with a brand new user when Shibboleth email is not defined' do + before do + omniauth_hash = { provider: 'shibboleth', + uid: uid, + extra: { + raw_info: { + title: 'title', + telephoneNumber: '123-456-7890', + givenName: 'Fake', + sn: 'User', + uceduPrimaryAffiliation: 'staff', + ou: 'department' + } + } } + OmniAuth.config.add_mock(provider, omniauth_hash) + request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider] + end + let(:email) { uid } + + it_behaves_like 'Shibboleth login' + end - context 'with a registered user who has never logged in' do - let!(:user) { FactoryBot.create(:shibboleth_user, count: 0, profile_update_not_required: false) } - let(:email) { user.email } + context 'with a brand new user when Shibboleth email is blank' do + before do + omniauth_hash = { provider: 'shibboleth', + uid: uid, + extra: { + raw_info: { + mail: '', + title: 'title', + telephoneNumber: '123-456-7890', + givenName: 'Fake', + sn: 'User', + uceduPrimaryAffiliation: 'staff', + ou: 'department' + } + } } + OmniAuth.config.add_mock(provider, omniauth_hash) + request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider] + end + let(:email) { uid } + + it_behaves_like 'Shibboleth login' + end - it_behaves_like 'Shibboleth login' + context 'with a registered user who has previously logged in' do + let!(:user) { FactoryBot.create(:shibboleth_user, count: 1, profile_update_not_required: false) } + let(:email) { user.email } - it 'updates the shibboleth attributes' do - get provider - expect(assigns(:user).title).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["title"]) - expect(assigns(:user).telephone).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["telephoneNumber"]) - expect(assigns(:user).first_name).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["givenName"]) - expect(assigns(:user).last_name).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["sn"]) - expect(assigns(:user).uc_affiliation).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["uceduPrimaryAffiliation"]) - expect(assigns(:user).ucdepartment).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["ou"]) + it_behaves_like 'Shibboleth login' end - end - context 'with a registered user who has previously logged in and has updated shibboleth data' do - before do - omniauth_hash = { provider: 'shibboleth', - uid: uid, - extra: { - raw_info: { - uceduPrimaryAffiliation: 'Second Affiliation', - ou: 'Second Department' - } - } } - OmniAuth.config.add_mock(provider, omniauth_hash) - request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider] + context 'with a registered user who has never logged in' do + let!(:user) { FactoryBot.create(:shibboleth_user, count: 0, profile_update_not_required: false) } + let(:email) { user.email } + + it_behaves_like 'Shibboleth login' + + it 'updates the shibboleth attributes' do + get provider + expect(assigns(:user).title).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["title"]) + expect(assigns(:user).telephone).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["telephoneNumber"]) + expect(assigns(:user).first_name).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["givenName"]) + expect(assigns(:user).last_name).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["sn"]) + expect(assigns(:user).uc_affiliation).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["uceduPrimaryAffiliation"]) + expect(assigns(:user).ucdepartment).to eq(request.env["omniauth.auth"]["extra"]["raw_info"]["ou"]) + end end - let!(:user) { FactoryBot.create(:shibboleth_user, count: 1, uc_affiliation: "First Affiliation", ucdepartment: "First Department") } - let!(:email) { user.email } - - it 'has the correct metadata' do - get provider - user = User.find(1) - expect(user["uc_affiliation"]).to eq "Second Affiliation" - expect(user["ucdepartment"]).to eq "Second Department" + context 'with a registered user who has previously logged in and has updated shibboleth data' do + before do + omniauth_hash = { provider: 'shibboleth', + uid: uid, + extra: { + raw_info: { + uceduPrimaryAffiliation: 'Second Affiliation', + ou: 'Second Department' + } + } } + OmniAuth.config.add_mock(provider, omniauth_hash) + request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider] + end + + let!(:user) { FactoryBot.create(:shibboleth_user, count: 1, uc_affiliation: "First Affiliation", ucdepartment: "First Department") } + let!(:email) { user.email } + + it 'has the correct metadata' do + get provider + user = User.find(1) + expect(user["uc_affiliation"]).to eq "Second Affiliation" + expect(user["ucdepartment"]).to eq "Second Department" + end end end - end end diff --git a/spec/controllers/static_controller_spec.rb b/spec/controllers/static_controller_spec.rb index a2bd144a..6c57afa2 100644 --- a/spec/controllers/static_controller_spec.rb +++ b/spec/controllers/static_controller_spec.rb @@ -89,17 +89,17 @@ expect(response).to render_template('static/doi_help') end end - describe '#login' do - let(:user) { FactoryBot.create(:user) } + describe '#login' do + let(:user) { FactoryBot.create(:user) } - before do - controller.stub(:current_user).and_return(user) + before do + controller.stub(:current_user).and_return(user) + end + it 'redirects to dashboard when already logged in' do + get :login + expect(response).to redirect_to(Hyrax::Engine.routes.url_helpers.dashboard_path) + end end - it 'redirects to dashboard when already logged in' do - get :login - expect(response).to redirect_to(Hyrax::Engine.routes.url_helpers.dashboard_path) - end - end describe '#whats_new' do it "renders the what's new page" do diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 4e5d6f7c..c5c496a0 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -59,20 +59,20 @@ end end - factory :shibboleth_user, class: 'User' do - transient do - count { 1 } - person_pid { nil } + factory :shibboleth_user, class: 'User' do + transient do + count { 1 } + person_pid { nil } + end + email { 'sixplus2@test.com' } + password { '12345678' } + first_name { 'Fake' } + last_name { 'User' } + password_confirmation { '12345678' } + sign_in_count { count.to_s } + provider { 'shibboleth' } + uid { 'sixplus2@test.com' } end - email { 'sixplus2@test.com' } - password { '12345678' } - first_name { 'Fake' } - last_name { 'User' } - password_confirmation { '12345678' } - sign_in_count { count.to_s } - provider { 'shibboleth' } - uid { 'sixplus2@test.com' } - end trait :guest do guest { true } diff --git a/spec/features/uc_shibboleth_spec.rb b/spec/features/uc_shibboleth_spec.rb index 42e87f2a..ba7b0f4b 100644 --- a/spec/features/uc_shibboleth_spec.rb +++ b/spec/features/uc_shibboleth_spec.rb @@ -1,159 +1,159 @@ -# frozen_string_literal: true - -require 'rails_helper' + # frozen_string_literal: true + + require 'rails_helper' + + describe 'UC account workflow', type: :feature do + let(:user) { FactoryBot.create(:user) } + let(:password) { FactoryBot.attributes_for(:user).fetch(:password) } + let(:locale) { 'en' } + + describe 'overridden devise password reset page' do + context 'with a uc.edu email address' do + email_address = 'fake.user@uc.edu' + it 'rejects password reset for @.uc.edu user' do + visit new_user_password_path + fill_in('user[email]', with: email_address) + click_on('Send me reset password instructions') + expect(page).to have_content('You cannot reset passwords for @uc.edu accounts. Use your UC Central Login instead') + end + end -describe 'UC account workflow', type: :feature do - let(:user) { FactoryBot.create(:user) } - let(:password) { FactoryBot.attributes_for(:user).fetch(:password) } - let(:locale) { 'en' } + context 'with a non uc.edu email address' do + it 'allows a password reset' do + visit new_user_password_path + fill_in('user[email]', with: user.email) + click_on('Send me reset password instructions') + expect(page).to have_content('You will receive an email with instructions on how to reset your password in a few minutes.') + end + end - describe 'overridden devise password reset page' do - context 'with a uc.edu email address' do - email_address = 'fake.user@uc.edu' - it 'rejects password reset for @.uc.edu user' do - visit new_user_password_path - fill_in('user[email]', with: email_address) - click_on('Send me reset password instructions') - expect(page).to have_content('You cannot reset passwords for @uc.edu accounts. Use your UC Central Login instead') + context 'with an invalid email address' do + email_address = 'fake.user@mail.edu' + it 'allows a password reset' do + visit new_user_password_path + fill_in('user[email]', with: email_address) + click_on('Send me reset password instructions') + expect(page).to have_content('Email not found') + end end end - context 'with a non uc.edu email address' do - it 'allows a password reset' do + describe 'overridden devise password reset page' do + it 'shows a Central Login option with shibboleth enabled' do + AUTH_CONFIG['shibboleth_enabled'] = true visit new_user_password_path - fill_in('user[email]', with: user.email) - click_on('Send me reset password instructions') - expect(page).to have_content('You will receive an email with instructions on how to reset your password in a few minutes.') + expect(page).to have_content('Central Login form') end - end - context 'with an invalid email address' do - email_address = 'fake.user@mail.edu' - it 'allows a password reset' do + it 'does not show a Central Login option with shibboleth disabled' do + AUTH_CONFIG['shibboleth_enabled'] = false visit new_user_password_path - fill_in('user[email]', with: email_address) - click_on('Send me reset password instructions') - expect(page).to have_content('Email not found') + skip "this string displays without regard to shibboleth status" + expect(page).not_to have_content('Central Login form') # This string appears in the help text on the page end - end - end - describe 'overridden devise password reset page' do - it 'shows a Central Login option with shibboleth enabled' do - AUTH_CONFIG['shibboleth_enabled'] = true - visit new_user_password_path - expect(page).to have_content('Central Login form') - end - - it 'does not show a Central Login option with shibboleth disabled' do - AUTH_CONFIG['shibboleth_enabled'] = false - visit new_user_password_path - skip "this string displays without regard to shibboleth status" - expect(page).not_to have_content('Central Login form') # This string appears in the help text on the page - end - - it 'does not display the Shared links at the bottom' do - visit new_user_password_path - expect(page).not_to have_link('Sign in', href: '/users/sign_in') - expect(page).not_to have_link('Sign up', href: '/users/sign_up') - end - end - - describe 'overridden devise registration page' do - it 'shows a sign up form if signups are enabled' do - AUTH_CONFIG['signups_enabled'] = true - visit new_user_registration_path - expect(page).to have_field('user[email]') - end - - it 'shows a request link of signups are disabled' do - AUTH_CONFIG['signups_enabled'] = false - visit new_user_registration_path - expect(page).to have_link('use the contact page', href: contact_path(locale: locale)) + it 'does not display the Shared links at the bottom' do + visit new_user_password_path + expect(page).not_to have_link('Sign in', href: '/users/sign_in') + expect(page).not_to have_link('Sign up', href: '/users/sign_up') + end end - end - describe 'overridden devise sign-in page' do - it 'shows a shibboleth login link if shibboleth is enabled' do - AUTH_CONFIG['shibboleth_enabled'] = true - visit new_user_session_path - expect(page).to have_link('Central Login form', href: user_shibboleth_omniauth_authorize_path(locale: locale)) - end + describe 'overridden devise registration page' do + it 'shows a sign up form if signups are enabled' do + AUTH_CONFIG['signups_enabled'] = true + visit new_user_registration_path + expect(page).to have_field('user[email]') + end - it 'does not show a shibboleth login link if shibboleth is disabled' do - AUTH_CONFIG['shibboleth_enabled'] = false - visit new_user_session_path - expect(page).not_to have_link('Central Login form', href: user_shibboleth_omniauth_authorize_path(locale: locale)) + it 'shows a request link of signups are disabled' do + AUTH_CONFIG['signups_enabled'] = false + visit new_user_registration_path + expect(page).to have_link('use the contact page', href: contact_path(locale: locale)) + end end - it 'shows a signup link if signups are enabled' do - AUTH_CONFIG['signups_enabled'] = true - visit new_user_session_path - expect(page).to have_link('Sign up', href: new_user_registration_path(locale: locale)) - end + describe 'overridden devise sign-in page' do + it 'shows a shibboleth login link if shibboleth is enabled' do + AUTH_CONFIG['shibboleth_enabled'] = true + visit new_user_session_path + expect(page).to have_link('Central Login form', href: user_shibboleth_omniauth_authorize_path(locale: locale)) + end - it 'does not show signup link if signups are disabled' do - AUTH_CONFIG['signups_enabled'] = false - visit new_user_session_path - expect(page).not_to have_link('Sign up', href: new_user_registration_path(locale: locale)) - end - end + it 'does not show a shibboleth login link if shibboleth is disabled' do + AUTH_CONFIG['shibboleth_enabled'] = false + visit new_user_session_path + expect(page).not_to have_link('Central Login form', href: user_shibboleth_omniauth_authorize_path(locale: locale)) + end - describe 'shibboleth login page' do - context 'when shibboleth is enabled' do - before do - AUTH_CONFIG['shibboleth_enabled'] = true - visit login_path + it 'shows a signup link if signups are enabled' do + AUTH_CONFIG['signups_enabled'] = true + visit new_user_session_path + expect(page).to have_link('Sign up', href: new_user_registration_path(locale: locale)) end - it 'shows a shibboleth login link and local login link' do - expect(page).to have_link('UC Central Login username', href: 'https://www.uc.edu/distance/Student_Orientation/One_Stop_Student_Resources/central-log-in-.html') - expect(page).to have_link('log in using a local account', href: new_user_session_path + '?locale=en') + it 'does not show signup link if signups are disabled' do + AUTH_CONFIG['signups_enabled'] = false + visit new_user_session_path + expect(page).not_to have_link('Sign up', href: new_user_registration_path(locale: locale)) end end - context 'when shibboleth is not enabled' do - before do - AUTH_CONFIG['shibboleth_enabled'] = false - visit login_path + describe 'shibboleth login page' do + context 'when shibboleth is enabled' do + before do + AUTH_CONFIG['shibboleth_enabled'] = true + visit login_path + end + + it 'shows a shibboleth login link and local login link' do + expect(page).to have_link('UC Central Login username', href: 'https://www.uc.edu/distance/Student_Orientation/One_Stop_Student_Resources/central-log-in-.html') + expect(page).to have_link('log in using a local account', href: new_user_session_path + '?locale=en') + end end - it 'shows the local log in page' do - expect(page).to have_field('user[email]') + context 'when shibboleth is not enabled' do + before do + AUTH_CONFIG['shibboleth_enabled'] = false + visit login_path + end + + it 'shows the local log in page' do + expect(page).to have_field('user[email]') + end end end - end - describe 'shibboleth password management' do - it 'hides the password change fields for shibboleth users' do - login_as(user) - user.provider = 'shibboleth' - visit hyrax.edit_dashboard_profile_path(user) - expect(page).not_to have_field('user[password]') - expect(page).not_to have_field('user[password_confirmation]') + describe 'shibboleth password management' do + it 'hides the password change fields for shibboleth users' do + login_as(user) + user.provider = 'shibboleth' + visit hyrax.edit_dashboard_profile_path(user) + expect(page).not_to have_field('user[password]') + expect(page).not_to have_field('user[password_confirmation]') + end end - end - describe 'home page login button' do - it 'shows the correct login link' do - visit root_path - expect(page).to have_link('Login', href: login_path + '?locale=en') + describe 'home page login button' do + it 'shows the correct login link' do + visit root_path + expect(page).to have_link('Login', href: login_path + '?locale=en') + end end - end - describe 'a user using a UC Shibboleth login' do - it "redirects to the UC Shibboleth logout page after logout" do - create_cookie('login_type', 'shibboleth') - visit('/users/sign_out') - expect(page).to have_content("You have been logged out of the University of Cincinnati's Login Service") + describe 'a user using a UC Shibboleth login' do + it "redirects to the UC Shibboleth logout page after logout" do + create_cookie('login_type', 'shibboleth') + visit('/users/sign_out') + expect(page).to have_content("You have been logged out of the University of Cincinnati's Login Service") + end end - end - describe 'a user using a local login' do - it "redirects to the home page after logout" do - create_cookie('login_type', 'local') - visit('/users/sign_out') - expect(page).to have_title("Scholar@UC") + describe 'a user using a local login' do + it "redirects to the home page after logout" do + create_cookie('login_type', 'local') + visit('/users/sign_out') + expect(page).to have_title("Scholar@UC") + end end end -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index f9547cfc..40a0d549 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -145,7 +145,7 @@ def ci_build? config.include OptionalExample config.include Devise::Test::IntegrationHelpers, type: :feature - config.include Devise::Test::ControllerHelpers, type: :controller + config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :helper config.before :suite do @@ -190,8 +190,8 @@ def ci_build? config.order = :random Kernel.srand config.seed - # Allow cookies to be set in feature tests (for UC Shibboleth testing) - config.include ShowMeTheCookies, type: :feature + # Allow cookies to be set in feature tests (for UC Shibboleth testing) + config.include ShowMeTheCookies, type: :feature config.include Shoulda::Matchers::Independent end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f8a85e0a..638a762f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -59,7 +59,7 @@ # Prevents you from mocking or stubbing a method that does not exist on # a real object. This is generally recommended, and will default to # `true` in RSpec 4. - # mocks.verify_partial_doubles = true + # mocks.verify_partial_doubles = true end # This option will default to `:apply_to_host_groups` in RSpec 4 (and will diff --git a/spec/support/test_routes.rb b/spec/support/test_routes.rb index 1836a400..019658b2 100644 --- a/spec/support/test_routes.rb +++ b/spec/support/test_routes.rb @@ -1,13 +1,13 @@ -# frozen_string_literal: true + # frozen_string_literal: true -class ShibbolethLogoutController < ApplicationController - def show - render plain: "You have been logged out of the University of Cincinnati's Login Service" + class ShibbolethLogoutController < ApplicationController + def show + render plain: "You have been logged out of the University of Cincinnati's Login Service" + end end -end -test_routes = proc do - get '/Shibboleth.sso/Logout' => 'shibboleth_logout#show' -end + test_routes = proc do + get '/Shibboleth.sso/Logout' => 'shibboleth_logout#show' + end -Rails.application.routes.send :eval_block, test_routes + Rails.application.routes.send :eval_block, test_routes diff --git a/spec/views/_user_util_links.html.erb_spec.rb b/spec/views/_user_util_links.html.erb_spec.rb index f9a6b203..5fbd8604 100644 --- a/spec/views/_user_util_links.html.erb_spec.rb +++ b/spec/views/_user_util_links.html.erb_spec.rb @@ -26,27 +26,27 @@ expect(rendered).to have_link 'Edit Profile', href: hyrax.edit_dashboard_profile_path('userX') end - context 'when the user is using shibboleth' do - before do - allow(view).to receive(:current_user).and_return(stub_model(User, user_key: 'userX', provider: 'shibboleth')) - render - end + context 'when the user is using shibboleth' do + before do + allow(view).to receive(:current_user).and_return(stub_model(User, user_key: 'userX', provider: 'shibboleth')) + render + end - it 'does not show the change password manu option' do - expect(rendered).not_to have_link 'Change password' + it 'does not show the change password manu option' do + expect(rendered).not_to have_link 'Change password' + end end - end - context 'when the user is not using shibboleth' do - before do - allow(view).to receive(:current_user).and_return(stub_model(User, user_key: 'userX', provider: nil)) - render - end + context 'when the user is not using shibboleth' do + before do + allow(view).to receive(:current_user).and_return(stub_model(User, user_key: 'userX', provider: nil)) + render + end - it 'shows the change password manu option' do - expect(rendered).to have_link 'Change password', href: edit_user_registration_path + it 'shows the change password manu option' do + expect(rendered).to have_link 'Change password', href: edit_user_registration_path + end end - end it 'shows the number of outstanding messages' do render diff --git a/spec/views/devise/registrations/edit.html.erb_spec.rb b/spec/views/devise/registrations/edit.html.erb_spec.rb index 7592b251..abd9f2bb 100644 --- a/spec/views/devise/registrations/edit.html.erb_spec.rb +++ b/spec/views/devise/registrations/edit.html.erb_spec.rb @@ -1,20 +1,20 @@ -# frozen_string_literal: true + # frozen_string_literal: true -require 'rails_helper' + require 'rails_helper' -RSpec.describe 'devise/registrations/edit.html.erb', type: :view do - let(:resource) { stub_model(User, user_key: 'mjg') } - let(:resource_name) { :user } - let(:devise_mapping) { Devise.mappings[:user] } + RSpec.describe 'devise/registrations/edit.html.erb', type: :view do + let(:resource) { stub_model(User, user_key: 'mjg') } + let(:resource_name) { :user } + let(:devise_mapping) { Devise.mappings[:user] } - before do - allow(view).to receive(:resource).and_return(resource) - allow(view).to receive(:resource_name).and_return(resource_name) - allow(view).to receive(:devise_mapping).and_return(devise_mapping) - render - end + before do + allow(view).to receive(:resource).and_return(resource) + allow(view).to receive(:resource_name).and_return(resource_name) + allow(view).to receive(:devise_mapping).and_return(devise_mapping) + render + end - it "does not allow the user to cancel their account" do - expect(rendered).not_to have_content('Cancel my account') + it "does not allow the user to cancel their account" do + expect(rendered).not_to have_content('Cancel my account') + end end -end