Skip to content

Commit cbc12f0

Browse files
authored
Merge pull request #1479 from sul-dlss/auth-check-cleanup
remove legacy auth check route, tests, controllers
2 parents be55b47 + acd88c0 commit cbc12f0

File tree

7 files changed

+5
-353
lines changed

7 files changed

+5
-353
lines changed

app/controllers/media_controller.rb

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
class MediaController < ApplicationController
66
skip_forgery_protection
77

8-
before_action :load_media
9-
10-
rescue_from ActionController::MissingFile do
11-
render plain: 'File not found', status: :not_found
12-
end
13-
148
def verify_token
159
# the media service calling verify_token provides the end-user IP address,
1610
# as we care about the (user) IP address that made a request to the media service with the
@@ -22,44 +16,12 @@ def verify_token
2216
end
2317
end
2418

25-
# jsonp response
26-
def auth_check
27-
# IE 11 and Edge on Windows 10 doesn't request the correct format. So just hardcode
28-
# JSON as the return format since that's what we always do.
29-
render json: hash_for_auth_check, callback: allowed_params[:callback]
30-
end
31-
3219
private
3320

3421
def allowed_params
3522
params.permit(:action, :callback, :id, :file_name, :format, :stacks_token, :user_ip)
3623
end
3724

38-
def hash_for_auth_check
39-
if can? :stream, current_media
40-
# we use IP from which request originated -- we want the end user IP, not
41-
# a service on the user's behalf (load-balancer, etc.)
42-
token = URI.encode_www_form_component(current_media.encrypted_token(ip: request.remote_ip))
43-
{
44-
status: :success,
45-
token:,
46-
access_restrictions: {
47-
stanford_restricted: current_media.stanford_restricted?,
48-
restricted_by_location: current_media.restricted_by_location?,
49-
embargoed: current_media.embargoed?,
50-
embargo_release_date: current_media.embargo_release_date
51-
}
52-
}
53-
else
54-
MediaAuthenticationJson.new(
55-
user: current_user,
56-
ability: current_ability,
57-
media: current_media,
58-
auth_url: iiif_auth_api_url
59-
)
60-
end
61-
end
62-
6325
def id
6426
allowed_params[:id]
6527
end
@@ -68,18 +30,6 @@ def file_name
6830
allowed_params[:file_name]
6931
end
7032

71-
def load_media
72-
@media ||= StacksMediaStream.new(stacks_file:)
73-
end
74-
75-
def stacks_file
76-
StacksFile.new(file_name: params[:file_name], cocina: Cocina.find(params[:id]))
77-
end
78-
79-
def current_media
80-
@media
81-
end
82-
8333
def token_valid?(token, expected_id, expected_file_name, expected_user_ip)
8434
StacksMediaToken.verify_encrypted_token? token, expected_id, expected_file_name, expected_user_ip
8535
end

config/routes.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@
2525
end
2626
end
2727

28-
if Settings.features.streaming_media
29-
# stream file_name must include format extension, eg .../oo000oo0000.mp4/verify_token
30-
# other dots do not need to be URL encoded (see media routing specs)
31-
constraints id: druid_regex, file_name: %r{[^/]+\.\w+} do
32-
get '/media/:id/:file_name/verify_token' => 'media#verify_token'
33-
get '/media/:id/:file_name/auth_check' => 'media#auth_check'
34-
35-
get '/media/druid::id/:file_name/verify_token' => 'media#verify_token'
36-
get '/media/druid::id/:file_name/auth_check' => 'media#auth_check'
37-
end
28+
# stream file_name must include format extension, eg .../oo000oo0000.mp4/verify_token
29+
# other dots do not need to be URL encoded (see media routing specs)
30+
constraints id: druid_regex, file_name: %r{[^/]+\.\w+} do
31+
get '/media/:id/:file_name/verify_token' => 'media#verify_token'
32+
get '/media/druid::id/:file_name/verify_token' => 'media#verify_token'
3833
end
3934

4035
root 'stacks#index'

config/settings.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
features:
2-
streaming_media: true
32
metrics: false
43
wowza_token: false
54

spec/controllers/media_controller_spec.rb

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,6 @@
33
require 'rails_helper'
44

55
RSpec.describe MediaController do
6-
before do
7-
allow(Cocina).to receive(:find).and_return(Cocina.new(public_json))
8-
end
9-
10-
let(:public_json) do
11-
{
12-
'structural' => {
13-
'contains' => [
14-
{
15-
'structural' => {
16-
'contains' => [
17-
{
18-
'filename' => 'bb582xs1304_sl.mp4',
19-
'access' => {
20-
'view' => 'world',
21-
'download' => 'world'
22-
}
23-
}
24-
]
25-
}
26-
}
27-
]
28-
}
29-
}
30-
end
316
let(:video) { StacksMediaStream.new(id: 'bb582xs1304', file_name: 'bb582xs1304_sl', format: 'mp4') }
327

338
describe '#verify_token' do
@@ -104,47 +79,4 @@
10479
expect(controller.send(:token_valid?, 'stacks_token', 'id', 'file_name', 'ip_addr')).to be true
10580
end
10681
end
107-
108-
describe '#auth_check' do
109-
let(:id) { 'bd786fy6312' }
110-
let(:file_name) { 'some_file.mp4' }
111-
112-
it 'returns JSON from hash_for_auth_check' do
113-
test_hash = { foo: :bar }
114-
expect(controller).to receive(:hash_for_auth_check).and_return(test_hash)
115-
get :auth_check, params: { id:, file_name:, format: :js }
116-
body = response.parsed_body
117-
expect(body).to eq('foo' => 'bar')
118-
end
119-
120-
context 'success' do
121-
before do
122-
# We could be more integration-y and instead e.g. stub_request(:get, "https://purl.stanford.edu/bd786fy6312.json").to_return(...).
123-
# But the StacksMediaStream code (and the metadata fetching/parsing code it uses) that'd be exercised by that approach is already
124-
# tested elsewhere. This approach is a bit more readable, and less brittle since it doesn't break the StacksMediaStream abstraction.
125-
stacks_media_stream = instance_double(StacksMediaStream, stanford_restricted?: false, restricted_by_location?: false,
126-
embargoed?: false, embargo_release_date: nil,
127-
encrypted_token: 'sekret-token')
128-
allow(controller).to receive_messages(can?: true, current_media: stacks_media_stream)
129-
end
130-
131-
it 'returns json that indicates a successful auth check (including token)' do
132-
get :auth_check, params: { id:, file_name:, format: :js }
133-
body = response.parsed_body
134-
expect(body['status']).to eq 'success'
135-
expect(body['token']).to eq 'sekret-token'
136-
end
137-
138-
it 'returns info about applicable access restrictions' do
139-
get :auth_check, params: { id:, file_name:, format: :js }
140-
body = response.parsed_body
141-
expect(body['access_restrictions']).to eq({
142-
'stanford_restricted' => false,
143-
'restricted_by_location' => false,
144-
'embargoed' => false,
145-
'embargo_release_date' => nil
146-
})
147-
end
148-
end
149-
end
15082
end

spec/requests/media_auth_request_spec.rb

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)