Skip to content

Commit

Permalink
HTTP headers for Mediaflux authentication (#866)
Browse files Browse the repository at this point in the history
* Added new HTTP header for mediaflux and a test for it

* Simplified the test (and changed it to really send the HTTP header to Mediaflux)
  • Loading branch information
hectorcorrea authored Jul 30, 2024
1 parent 00d90f7 commit 4531253
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 1 addition & 3 deletions app/models/mediaflux/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ def build_http_request(name:, form_file: nil)
def set_authentication_headers(request)
return if @session_user.nil?

request["TIGERDATA_NETID"] = @session_user.uid
request["TIGERDATA_DOMAIN"] = "princeton.edu"
request["TIGERDATA_TIMEOUT"] = "tbd"
request["mediaflux.sso.user"] = @session_user.uid
end
end
end
23 changes: 23 additions & 0 deletions spec/models/mediaflux/asset_exist_request_headers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true
require "rails_helper"

RSpec.describe Mediaflux::AssetExistRequest, type: :model, connect_to_mediaflux: false do
let(:user) { FactoryBot.create(:user) }
let(:namespace_root) { Rails.configuration.mediaflux["api_root_collection_namespace"] }

context "when we give a user to the class" do
it "sends the custom HTTP headers to Mediaflux" do
subject = described_class.new(session_token: nil, session_user: user, path: namespace_root)
http_request = subject.send("http_request")
expect(http_request["mediaflux.sso.user"]).to eq user.uid
end
end

context "when we give a session token to the class" do
it "does NOT send the custom HTTP headers to Mediaflux" do
subject = described_class.new(session_token: user.mediaflux_session, session_user: nil, path: namespace_root)
http_request = subject.send("http_request")
expect(http_request["mediaflux.sso.user"]).to be nil
end
end
end
2 changes: 1 addition & 1 deletion spec/support/connect_to_mediaflux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def create_test_root_namespace(user)
end
end

config.after(:suite) do |_ex|
config.after(:suite) do |_ex|
original_api_host = Rails.configuration.mediaflux["api_host"]
Rails.configuration.mediaflux["api_host"] = "0.0.0.0"
reset_mediaflux_root
Expand Down

0 comments on commit 4531253

Please sign in to comment.