Skip to content

Commit

Permalink
change the 3 day authentication to 1 year
Browse files Browse the repository at this point in the history
  • Loading branch information
jendiamond committed Nov 15, 2023
1 parent d109a24 commit 5dbfa7f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
14 changes: 9 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def display_banner?
end

def sinai_authn_check
return true if [version_path].include?(request.path) || sinai_authenticated_3day?
return true if [version_path].include?(request.path) || sinai_authenticated_1year?
if ENV['SINAI_ID_BYPASS'] # skip auth in development
cookies[:sinai_authenticated_3day] = 'true'
cookies[:sinai_authenticated_1year] = 'true'
return true
end
# check_document_paths
Expand Down Expand Up @@ -69,6 +69,10 @@ def sinai_authenticated_3day?
cookies[:sinai_authenticated_3day]
end

def sinai_authenticated_1year?
cookies[:sinai_authenticated_1year]
end

def ucla_token?
# does the request have a querystring containing a param named token and, if so, was it previously written to the database?
return true if params[:token].present? && SinaiToken.find_by(sinai_token: params[:token])
Expand All @@ -83,14 +87,14 @@ def ucla_token?
end

def set_auth_cookies
cookies[:sinai_authenticated_3day] = {
cookies[:sinai_authenticated_1year] = {
value: create_encrypted_string.unpack('H*')[0].upcase,
expires: Time.zone.now + 3.days,
expires: Time.zone.now + 1.year,
domain: ENV['DOMAIN']
}
cookies[:initialization_vector] = {
value: cipher_iv.unpack('H*')[0].upcase,
expires: Time.zone.now + 3.days,
expires: Time.zone.now + 1.year,
domain: ENV['DOMAIN']
}
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/catalog/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%# THUMBNAIL %>
<% if presenter(document).thumbnail.exists? && tn = presenter(document).thumbnail.thumbnail_tag({}, counter: document_counter_with_offset(document_counter)) %>
<%# Thumnail NOT logged in %>
<% if !cookies[:sinai_authenticated_3day] %>
<% if !cookies[:sinai_authenticated_1year] %>
<div class='document__gallery-thumbnail document__gallery-thumbnail--sinai-generic'>
<a href='#' data-toggle='modal' data-target='#exampleModalCenter'>
<%= image_tag('sinai/sinai-generic-thumbnail.png', class: 'document__gallery-thumbnail--sinai-generic') %>
Expand All @@ -22,7 +22,7 @@
<%# ----------------------------------------------- %>
<%# METADATA %>
<% if !cookies[:sinai_authenticated_3day] %>
<% if !cookies[:sinai_authenticated_1year] %>
<%# Sinai NOT LOGGED IN %>
<%# cookies[:request_original_url] = request.original_url %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_index_gallery.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if Flipflop.sinai? %>
<div class="document document__gallery-item document__gallery-item--sinai">
<div class="document__gallery-item-wrapper">
<% if !cookies[:sinai_authenticated_3day] %>
<% if !cookies[:sinai_authenticated_1year] %>
<a href="#" class="document__gallery-item-thumbnail-link--sinai" data-toggle="modal" data-target="#exampleModalCenter">
<%= image_tag("sinai/sinai-generic-thumbnail.png") %>
</a>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/header/_header_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ul class='nav'>
<li class='nav-item site-navbar__item--sinai'><%= link_to "Search#{image_tag('sinai-logos/search-icon-bold.svg', class: 'site-header__search-icon--sinai', alt: 'Search icon')}".html_safe, '/catalog?utf8=%E2%9C%93&q=&search_field=all_fields' %></li>
<li class='nav-item site-navbar__item--sinai'><%= link_to 'About', about_path %></li>
<% if !cookies[:sinai_authenticated_3day] %>
<% if !cookies[:sinai_authenticated_1year] %>
<%
cookies[:requested_path] = request.original_url
login_service = LoginService.new
Expand Down
16 changes: 8 additions & 8 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
allow(controller).to receive(:redirect_to)
allow(controller).to receive(:request).and_return(instance_double('ActionDispatch::Request', path: '/'))
allow(controller).to receive(:set_auth_cookies)
allow(controller).to receive(:sinai_authenticated_3day?).and_return(false)
allow(controller).to receive(:sinai_authenticated_1year?).and_return(false)
allow(controller).to receive(:version_path).and_return('/test_version')
allow(controller).to receive(:solr_document_path).with('ark:').and_return('/catalog/ark:')
allow(controller).to receive(:params).and_return(id: nil)
Expand Down Expand Up @@ -97,7 +97,7 @@

context 'if we are already authenticated' do
before do
allow(controller).to receive(:sinai_authenticated_3day?).and_return(true)
allow(controller).to receive(:sinai_authenticated_1year?).and_return(true)
end
it 'allows Rails to continue' do
expect(controller.sinai_authn_check).to be true
Expand All @@ -107,7 +107,7 @@
context 'if the requested path is solr_document_path' do
before do
allow(controller).to receive(:params).and_return(id: 'ark:')
allow(controller).to receive(:sinai_authenticated_3day?).and_return(false)
allow(controller).to receive(:sinai_authenticated_1year?).and_return(false)
allow(controller).to receive(:request).and_return(instance_double('ActionDispatch::Request', path: controller.solr_document_path('ark:')))
end
it 'directs to requested path' do
Expand Down Expand Up @@ -178,7 +178,7 @@
end # describe ucla_token?

describe 'set_auth_cookies' do
context 'creates the sinai_authenticated_3day cookie' do
context 'creates the sinai_authenticated_1year cookie' do
let(:cookies) { {} }
before do
allow(controller).to receive(:cookies).and_return(cookies)
Expand All @@ -190,14 +190,14 @@
allow(controller).to receive(:cipher_iv).and_return('mock_cipher_iv')
end

it 'sets the sinai_authenticated_3day cookie value' do
it 'sets the sinai_authenticated_1year cookie value' do
controller.set_auth_cookies
expect(cookies[:sinai_authenticated_3day][:value]).to eq('mock_encrypted_string'.unpack('H*')[0].upcase)
expect(cookies[:sinai_authenticated_1year][:value]).to eq('mock_encrypted_string'.unpack('H*')[0].upcase)
end

it 'sets an expiration date for the sinai_authenticated_3day cookie' do
it 'sets an expiration date for the sinai_authenticated_1year cookie' do
controller.set_auth_cookies
expect(cookies[:sinai_authenticated_3day][:expires]).to be_kind_of(Time)
expect(cookies[:sinai_authenticated_1year][:expires]).to be_kind_of(Time)
end

it 'sets the initialization_vector cookie value' do
Expand Down

0 comments on commit 5dbfa7f

Please sign in to comment.