Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expands tests for various users #1049

Merged
merged 12 commits into from
Sep 5, 2024
4 changes: 2 additions & 2 deletions app/helpers/access_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def retrieve_admin_credentials(document)
return nil if current_user.nil?
# #{ENV['MANAGEMENT_HOST']}
# for local debugging - http://yul-dc-management-1:3001/management or http://yul-dc_management_1:3001/management
url = URI.parse("#{ENV['MANAGEMENT_HOST']}/api/permission_sets/#{document.id}/#{current_user.netid}")
url = URI.parse("#{ENV['MANAGEMENT_HOST']}/api/permission_sets/#{document.id}/#{current_user.uid}")
response = Net::HTTP.get_response(url, { 'Authorization' => "Bearer #{ENV['OWP_AUTH_TOKEN']}" })
JSON.parse(response.body)
end
Expand All @@ -101,7 +101,7 @@ def retrieve_admin_fulltext_credentials(document)
return nil if current_user.nil?
# #{ENV['MANAGEMENT_HOST']}
# for local debugging - http://yul-dc-management-1:3001/management or http://yul-dc_management_1:3001/management
url = URI.parse("#{ENV['MANAGEMENT_HOST']}/api/permission_sets/#{document}/#{current_user.netid}")
url = URI.parse("#{ENV['MANAGEMENT_HOST']}/api/permission_sets/#{document}/#{current_user.uid}")
response = Net::HTTP.get_response(url, { 'Authorization' => "Bearer #{ENV['OWP_AUTH_TOKEN']}" })
JSON.parse(response.body)
end
Expand Down
1 change: 0 additions & 1 deletion spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
factory :user do
uid { FFaker::Internet.user_name }
sub { "123" }
netid { "az123" }
provider { "openid" }
end
end
207 changes: 163 additions & 44 deletions spec/requests/annotation_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

# WebMock.allow_net_connect!
RSpec.describe 'AnnotationsController', type: :request, clean: true, js: true do
let(:user) { FactoryBot.create(:user, netid: "net_id") }
let(:yale_user) { FactoryBot.create(:user, netid: "net_id") }
let(:non_yale_user) { FactoryBot.create(:user) }
let(:public_work) do
{
"id": "2034600",
Expand Down Expand Up @@ -94,59 +95,177 @@
end
end

describe 'GET /annotation/ .. /fulltext while on campus' do
before do
allow(User).to receive(:on_campus?).and_return(true)
end
it 'returns a full text annotation' do
get '/annotation/oid/2034600/canvas/998833/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text public")
describe 'GET /annotation/ .. /fulltext not logged in' do
context 'while on campus' do
before do
allow(User).to receive(:on_campus?).and_return(true)
end
it 'returns a full text annotation' do
get '/annotation/oid/2034600/canvas/998833/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text public")
end
it 'returns a full text annotation on yale only' do
get '/annotation/oid/1618909/canvas/998834/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text Yale only")
end
it 'returns 401 for a full text annotation on Open with Permission parent' do
get '/annotation/oid/1618909/canvas/9988344/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation because of mismatch parent' do
get '/annotation/oid/2034600/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation unknown visibility' do
get '/annotation/oid/1618904/canvas/998835/fulltext'
expect(response).to have_http_status(:unauthorized)
end
end
it 'returns a full text annotation on yale only' do
get '/annotation/oid/1618909/canvas/998834/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text Yale only")
end
it 'returns 401 for a full text annotation on Open with Permission parent' do
get '/annotation/oid/1618909/canvas/9988344/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation because of mismatch parent' do
get '/annotation/oid/2034600/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation unknown visibility' do
get '/annotation/oid/1618904/canvas/998835/fulltext'
expect(response).to have_http_status(:unauthorized)
context 'while not on campus' do
before do
allow(User).to receive(:on_campus?).and_return(false)
end
it 'returns a full text annotation' do
get '/annotation/oid/2034600/canvas/998833/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text public")
end
it 'returns a full text annotation on yale only' do
get '/annotation/oid/1618909/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation on Open with Permission parent' do
get '/annotation/oid/1618909/canvas/9988344/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation because of mismatch parent' do
get '/annotation/oid/2034600/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation unknown visibility' do
get '/annotation/oid/1618904/canvas/998835/fulltext'
expect(response).to have_http_status(:unauthorized)
end
end
end

describe 'GET /annotation/ .. /fulltext while logged in' do
describe 'GET /annotation/ .. /fulltext while logged in as yale user' do
before do
sign_in user
sign_in yale_user
end
it 'returns a full text annotation' do
get '/annotation/oid/2034600/canvas/998833/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text public")
context 'while on campus' do
before do
allow(User).to receive(:on_campus?).and_return(true)
end
it 'returns a full text annotation' do
get '/annotation/oid/2034600/canvas/998833/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text public")
end
it 'returns a full text annotation on yale only' do
get '/annotation/oid/1618909/canvas/998834/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text Yale only")
end
it 'returns 401 for a full text annotation on Open with Permission parent' do
get '/annotation/oid/1618909/canvas/9988344/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation because of mismatch parent' do
get '/annotation/oid/2034600/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation unknown visibility' do
get '/annotation/oid/1618904/canvas/998835/fulltext'
expect(response).to have_http_status(:unauthorized)
end
end
it 'returns a full text annotation on yale only' do
get '/annotation/oid/1618909/canvas/998834/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text Yale only")
context 'while not on campus' do
before do
allow(User).to receive(:on_campus?).and_return(false)
end
it 'returns a full text annotation' do
get '/annotation/oid/2034600/canvas/998833/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text public")
end
it 'returns a full text annotation on yale only' do
get '/annotation/oid/1618909/canvas/998834/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text Yale only")
end
it 'returns 401 for a full text annotation on Open with Permission parent' do
get '/annotation/oid/1618909/canvas/9988344/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation because of mismatch parent' do
get '/annotation/oid/2034600/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation unknown visibility' do
get '/annotation/oid/1618904/canvas/998835/fulltext'
expect(response).to have_http_status(:unauthorized)
end
end
it 'returns 401 for a full text annotation on Open with Permission parent' do
get '/annotation/oid/1618909/canvas/9988344/fulltext'
expect(response).to have_http_status(:unauthorized)
end
describe 'GET /annotation/ .. /fulltext while logged in as non yale user' do
before do
sign_in non_yale_user
end
it 'returns 401 for a full text annotation because of mismatch parent' do
get '/annotation/oid/2034600/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
context 'while on campus' do
before do
allow(User).to receive(:on_campus?).and_return(true)
end
it 'returns a full text annotation' do
get '/annotation/oid/2034600/canvas/998833/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text public")
end
it 'returns a full text annotation on yale only' do
get '/annotation/oid/1618909/canvas/998834/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text Yale only")
end
it 'returns 401 for a full text annotation on Open with Permission parent' do
get '/annotation/oid/1618909/canvas/9988344/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation because of mismatch parent' do
get '/annotation/oid/2034600/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation unknown visibility' do
get '/annotation/oid/1618904/canvas/998835/fulltext'
expect(response).to have_http_status(:unauthorized)
end
end
it 'returns 401 for a full text annotation unknown visibility' do
get '/annotation/oid/1618904/canvas/998835/fulltext'
expect(response).to have_http_status(:unauthorized)
context 'while not on campus' do
before do
allow(User).to receive(:on_campus?).and_return(false)
end
it 'returns a full text annotation' do
get '/annotation/oid/2034600/canvas/998833/fulltext'
expect(response).to have_http_status(:success)
expect(response.body).to include("This is the full text public")
end
it 'returns 401 for a full text annotation on yale only' do
get '/annotation/oid/1618909/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation on Open with Permission parent' do
get '/annotation/oid/1618909/canvas/9988344/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation because of mismatch parent' do
get '/annotation/oid/2034600/canvas/998834/fulltext'
expect(response).to have_http_status(:unauthorized)
end
it 'returns 401 for a full text annotation unknown visibility' do
get '/annotation/oid/1618904/canvas/998835/fulltext'
expect(response).to have_http_status(:unauthorized)
end
end
end
end
Expand Down
Loading