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

Bugfix/API failure with bogus auth header #179

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ontologies_linked_data/security/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def find_apikey(env, params)
apikey = params["apikey"]
elsif apikey.nil? && header_auth
token = Rack::Utils.parse_query(header_auth.split(" ")[1])
return unless token["token"]

# Strip spaces from start and end of string
apikey = token["token"].gsub(/\"/, "")
# If the user apikey is passed, use that instead
Expand Down
27 changes: 14 additions & 13 deletions test/rack/test_request_authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,32 @@ def _delete_user

def test_authorize
get "/ontologies"
assert last_response.status == 401
assert_equal 401, last_response.status
get "/ontologies", {}, {"Authorization" => "bogus auth header"}
assert_equal 401, last_response.status
get "/ontologies", {}, {"Authorization" => 'apikey token="'+@apikey+''+'"'}
assert last_response.status == 200
assert_equal 200, last_response.status
apikey = MultiJson.load(last_response.body)
assert @apikey.eql?(apikey)
get "/ontologies", {}, {"Authorization" => "apikey token=#{@apikey}"}
assert last_response.status == 200
assert_equal 200, last_response.status
apikey = MultiJson.load(last_response.body)
assert @apikey.eql?(apikey)
assert_equal @apikey, apikey
get "/ontologies?apikey=#{@apikey}"
assert last_response.status == 200
assert_equal 200, last_response.status
apikey = MultiJson.load(last_response.body)
assert @apikey.eql?(apikey)
assert_equal @apikey, apikey
get "/ontologies", {}, {"Authorization" => 'apikey token="'+@apikey+'&userapikey='+@userapikey+'"'}
assert last_response.status == 200
assert_equal 200, last_response.status
apikey = MultiJson.load(last_response.body)
assert @userapikey.eql?(apikey)
assert_equal @userapikey, apikey
get "/ontologies", {}, {"Authorization" => "apikey token=#{@apikey}&userapikey=#{@userapikey}"}
assert last_response.status == 200
assert_equal 200, last_response.status
apikey = MultiJson.load(last_response.body)
assert @userapikey.eql?(apikey)
assert_equal @userapikey, apikey
get "/ontologies?apikey=#{@apikey}&userapikey=#{@userapikey}"
assert last_response.status == 200
assert_equal 200, last_response.status
apikey = MultiJson.load(last_response.body)
assert @userapikey.eql?(apikey)
assert_equal @userapikey, apikey
end

end