Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Address key length issue with refworks/bookmarks after ruby upgrade (#…
Browse files Browse the repository at this point in the history
…1562)

Monkey patch BookmarksController#export_secret_token to use 
AS::KeyGenerator and set a 32 bit key

Also add some bookmark feature tests so that we can catch regressions of 
this feature.

Consistant style of bookmarks actions
  • Loading branch information
pgwillia authored Mar 29, 2019
1 parent 8dfbb16 commit 209ac57
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and releases in Discovery project adheres to [Semantic Versioning](http://semver

### Fixed
- use safe navigation operator fixes nil error in Symphony Service summary holdings [#1571](https://github.com/ualbertalib/discovery/issues/1571)
- refworks export with encrypted user behavior restored [#1549](https://github.com/ualbertalib/discovery/issues/1549)

## [3.0.104] - 2019-03-27
### Fixed
Expand Down
15 changes: 14 additions & 1 deletion app/controllers/bookmarks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@

class BookmarksController < CatalogController
include Blacklight::Bookmarks

def action_success_redirect_path
bookmarks_path
end

# monkey patch this method which is throwing `key must be 32 bytes` error after upgrading to Ruby 2.5
def export_secret_token(salt)
secret_key_generator.generate_key(salt)[0..(ActiveSupport::MessageEncryptor.key_len - 1)]
end

# cribbed from https://github.com/projectblacklight/blacklight/blob/8b9041544553ce0dd0d979f9f39f78d94b30b46d/app/controllers/concerns/blacklight/token_based_user.rb#L46-L76
def secret_key_generator
@secret_key_generator ||= begin
# TODO: this is appropriate for Rails <= 5.1
# update to Rails.application.credentials.secret_key_base for Rails 5.2+
ActiveSupport::KeyGenerator.new(Rails.application.secrets.secret_key_base)
end
end
end
2 changes: 1 addition & 1 deletion app/views/bookmarks/_refworks.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if @document_list.any? {|d| d.exports_as? :refworks_marc_txt } %>
<li class="refworks">
<li class="nav-item">
<%= link_to t('blacklight.tools.refworks'), refworks_export_url(url: bookmarks_export_url(:refworks_marc_txt, params_for_search)), class: 'btn btn-default', id: 'refworksLink', target: '_blank' %>
</li>
<% end %>
6 changes: 2 additions & 4 deletions app/views/bookmarks/_tools.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<ul class="<%= controller_name %>Tools nav nav-pills">
<%= render_show_doc_actions document_list, document: nil, document_list: @document_list, url_opts: sanitize_search_params(params) do |config, inner| %>
<li class="nav-item">
<%= inner %>
<%= inner.insert(3, 'class="btn btn-default"') %>
</li>
<% end %>

<%# March 20 2019: Issue 1549: after the ruby upgdate to 2.5.3, refworks export with encrypted user behavior is broken, we temporarily removed the refwork export to recover the bookmark feature. TO-DO: find a permanent fix for this issue %>
<%# = render_marc_tools %>
<%= render_marc_tools %>
</ul>
57 changes: 57 additions & 0 deletions spec/features/bookmarks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

RSpec.describe 'Bookmarks', type: :feature do
describe 'navigating from the homepage' do
it 'has a link to the history page' do
visit '/'
fill_in 'q', with: 'Shakespeare'
click_button 'search'
click_link 'Go to bookmarks'
expect(page).to have_content 'You have no bookmarks'
end
end

it 'add and remove bookmarks from search results' do
visit '/'
fill_in 'q', with: 'Shakespeare'
click_button 'search'
within first('div.document') do
check 'Bookmark'
expect(page).to have_content 'In Bookmarks'
end

fill_in 'q', with: 'Shakespeare'
click_button 'search'
within first('div.document') do
uncheck 'In Bookmarks'
expect(page).to have_content 'Bookmark'
end
end

it 'adds and delete bookmarks from the show page' do
VCR.use_cassette('item_result') do
visit 'catalog/1001523'
expect(page).to have_content 'Bookmark'
check 'Bookmark'
expect(page).to have_content 'In Bookmarks'
uncheck 'In Bookmarks'
expect(page).to have_content 'Bookmark'
end
end

it 'cites items in current bookmarks page' do
VCR.use_cassette('item_result') do
visit 'catalog/1001523' # Shakespeare : a historical and critical study with annotated texts of twenty-one plays
check 'Bookmark'
end

VCR.use_cassette('item to bookmark') do
visit 'catalog/1002481' # Shakespeare at the Globe : 1599-1609 / Bernard Beckerman
check 'Bookmark'
end

visit '/bookmarks?per_page=1'
expect(page).to have_content 'Shakespeare at the Globe'
expect(page).not_to have_content 'Shakespeare : a historical and critical study with annotated texts of twenty-one plays'
end
end
79 changes: 79 additions & 0 deletions spec/fixtures/vcr_cassettes/item_to_bookmark.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 209ac57

Please sign in to comment.