mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Ensure cors headers are also returned for other requests
This commit is contained in:
parent
e3c83c601c
commit
09e0a96b70
3 changed files with 18 additions and 0 deletions
|
@ -5,6 +5,7 @@ module Api
|
||||||
module V1
|
module V1
|
||||||
module Registrant
|
module Registrant
|
||||||
class AuthController < ActionController::API
|
class AuthController < ActionController::API
|
||||||
|
before_action :set_cors_header
|
||||||
before_action :check_ip_whitelist
|
before_action :check_ip_whitelist
|
||||||
|
|
||||||
rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
|
rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
|
||||||
|
@ -27,6 +28,10 @@ module Api
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_cors_header
|
||||||
|
response.headers['Access-Control-Allow-Origin'] = '*'
|
||||||
|
end
|
||||||
|
|
||||||
def eid_params
|
def eid_params
|
||||||
required_params = %i[ident first_name last_name]
|
required_params = %i[ident first_name last_name]
|
||||||
required_params.each_with_object(params) do |key, obj|
|
required_params.each_with_object(params) do |key, obj|
|
||||||
|
|
|
@ -5,6 +5,7 @@ module Api
|
||||||
module V1
|
module V1
|
||||||
module Registrant
|
module Registrant
|
||||||
class BaseController < ActionController::API
|
class BaseController < ActionController::API
|
||||||
|
before_action :set_cors_header
|
||||||
before_action :authenticate
|
before_action :authenticate
|
||||||
before_action :set_paper_trail_whodunnit
|
before_action :set_paper_trail_whodunnit
|
||||||
|
|
||||||
|
@ -17,6 +18,10 @@ module Api
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_cors_header
|
||||||
|
response.headers['Access-Control-Allow-Origin'] = '*'
|
||||||
|
end
|
||||||
|
|
||||||
def bearer_token
|
def bearer_token
|
||||||
pattern = /^Bearer /
|
pattern = /^Bearer /
|
||||||
header = request.headers['Authorization']
|
header = request.headers['Authorization']
|
||||||
|
|
|
@ -24,4 +24,12 @@ class RegistrantApiCorsHeadersTest < ApplicationIntegrationTest
|
||||||
|
|
||||||
assert_equal('', response.body)
|
assert_equal('', response.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_it_returns_cors_headers_for_other_requests
|
||||||
|
post '/api/v1/registrant/auth/eid', {}
|
||||||
|
assert_equal('*', response.headers['Access-Control-Allow-Origin'])
|
||||||
|
|
||||||
|
get '/api/v1/registrant/contacts', {}
|
||||||
|
assert_equal('*', response.headers['Access-Control-Allow-Origin'])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue