Skip to content

Commit caf63f3

Browse files
authored
Merge pull request #6965 from avalonmediasystem/8.2.1RC3
[8.2.1 RC3] Restrict browse-everything routes to users who are members of a collection or unit
2 parents 4763eb1 + 3070b2f commit caf63f3

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

config/initializers/dropbox_context.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@
1010
end
1111
end
1212
end
13+
14+
BrowseEverythingController.prepend_before_action do
15+
authorize! :create, MediaObject
16+
end
1317
end
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2011-2026, The Trustees of Indiana University and Northwestern
2+
# University. Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
#
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software distributed
10+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
# specific language governing permissions and limitations under the License.
13+
# --- END LICENSE_HEADER BLOCK ---
14+
15+
require 'rails_helper'
16+
17+
RSpec.describe BrowseEverythingController, type: :controller do
18+
19+
routes { BrowseEverything::Engine.routes }
20+
21+
let(:user) { FactoryBot.create(:user) }
22+
23+
describe 'security' do
24+
context 'with unauthenticated user' do
25+
it 'returns 401 unauthorized' do
26+
expect(get :index).to be_unauthorized
27+
expect(get :index, xhr: true).to be_unauthorized
28+
expect(get :show, params: { provider: 'file_system' }).to be_unauthorized
29+
expect(get :show, params: { provider: 'file_system' }, xhr: true).to be_unauthorized
30+
expect(get :show, params: { provider: 'file_system', context: 'abcd1234' }, xhr: true).to be_unauthorized
31+
expect(get :show, params: { provider: 'file_system', context: 'abcd1234', path: 'subfolder' }, xhr: true).to be_unauthorized
32+
expect(get :auth).to be_unauthorized
33+
expect(get :auth, xhr: true).to be_unauthorized
34+
expect(get :resolve).to be_unauthorized
35+
expect(get :resolve, xhr: true).to be_unauthorized
36+
end
37+
end
38+
39+
context 'with end-user' do
40+
before { login_user user.user_key }
41+
42+
it 'returns 401 unauthorized' do
43+
expect(get :index).to be_unauthorized
44+
expect(get :index, xhr: true).to be_unauthorized
45+
expect(get :show, params: { provider: 'file_system' }).to be_unauthorized
46+
expect(get :show, params: { provider: 'file_system' }, xhr: true).to be_unauthorized
47+
expect(get :show, params: { provider: 'file_system', context: 'abcd1234' }, xhr: true).to be_unauthorized
48+
expect(get :show, params: { provider: 'file_system', context: 'abcd1234', path: 'subfolder' }, xhr: true).to be_unauthorized
49+
expect(get :auth).to be_unauthorized
50+
expect(get :auth, xhr: true).to be_unauthorized
51+
expect(get :resolve).to be_unauthorized
52+
expect(get :resolve, xhr: true).to be_unauthorized
53+
end
54+
end
55+
56+
context 'with collection memeber' do
57+
let!(:collection) { FactoryBot.create(:collection, depositors: [user.to_s]) }
58+
59+
before { login_user user.user_key }
60+
61+
it 'responds' do
62+
expect(get :index).to be_successful
63+
expect(get :index, xhr: true).to be_successful
64+
#expect(get :show, params: { provider: 'file_system' }).to be_successful # raises ActionView::MissingTemplate
65+
expect(get :show, params: { provider: 'file_system' }, xhr: true).to be_successful
66+
expect(get :show, params: { provider: 'file_system', context: collection.id}, xhr: true).to be_successful
67+
expect(get :show, params: { provider: 'file_system', context: collection.id, path: 'subfolder' }, xhr: true).to be_successful
68+
expect(get :auth).to be_successful
69+
expect(get :auth, xhr: true).to be_successful
70+
#expect(get :resolve).to be_successful # raises ActionView::MissingTemplate
71+
expect(get :resolve, format: :json, xhr: true).to be_successful
72+
end
73+
end
74+
end
75+
end

0 commit comments

Comments
 (0)