mirror of
https://github.com/internetee/registry.git
synced 2025-08-12 04:29:33 +02:00
fixed zeitwerk load file issue
This commit is contained in:
parent
e0e9c43575
commit
f384520cbf
5 changed files with 72 additions and 69 deletions
|
@ -3,8 +3,8 @@ require 'auth_token/auth_token_decryptor'
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
module AccreditationCenter
|
module AccreditationCenter
|
||||||
if Feature.allow_accr_endspoints?
|
class BaseController < ActionController::API
|
||||||
class BaseController < ActionController::API
|
if Feature.allow_accr_endspoints?
|
||||||
rescue_from ActiveRecord::RecordNotFound, with: :show_not_found_error
|
rescue_from ActiveRecord::RecordNotFound, with: :show_not_found_error
|
||||||
rescue_from ActiveRecord::RecordInvalid, with: :show_invalid_record_error
|
rescue_from ActiveRecord::RecordInvalid, with: :show_invalid_record_error
|
||||||
rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
|
rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
module Repp
|
module Repp
|
||||||
module V1
|
module V1
|
||||||
module Registrar
|
module Registrar
|
||||||
if Feature.allow_accr_endspoints?
|
class AccreditationInfoController < BaseController
|
||||||
class AccreditationInfoController < BaseController
|
if Feature.allow_accr_endspoints?
|
||||||
api :GET, 'repp/v1/registrar/accreditation/get_info'
|
api :GET, 'repp/v1/registrar/accreditation/get_info'
|
||||||
desc 'check login user and return data'
|
desc 'check login user and return data'
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
module Repp
|
module Repp
|
||||||
module V1
|
module V1
|
||||||
module Registrar
|
module Registrar
|
||||||
if Feature.allow_accr_endspoints?
|
class AccreditationResultsController < ActionController::API
|
||||||
class AccreditationResultsController < ActionController::API
|
if Feature.allow_accr_endspoints?
|
||||||
before_action :authenticate_shared_key
|
before_action :authenticate_shared_key
|
||||||
|
|
||||||
TEMPORARY_SECRET_KEY = ENV['accreditation_secret'].freeze
|
TEMPORARY_SECRET_KEY = ENV['accreditation_secret'].freeze
|
||||||
EXPIRE_DEADLINE = 15.minutes.freeze
|
EXPIRE_DEADLINE = 15.minutes.freeze
|
||||||
|
|
||||||
api :POST, 'repp/v1/registrar/accreditation/push_results'
|
api :POST, 'repp/v1/registrar/accreditation/push_results'
|
||||||
desc 'added datetime results'
|
desc 'added datetime results'
|
||||||
|
@ -25,8 +25,7 @@ module Repp
|
||||||
def record_accreditation_result(username, result)
|
def record_accreditation_result(username, result)
|
||||||
user = ApiUser.find_by(username: username)
|
user = ApiUser.find_by(username: username)
|
||||||
|
|
||||||
raise ActiveRecord::RecordNotFound if user.nil?
|
raise ActiveRecord::RecordNotFound if user.nil?
|
||||||
|
|
||||||
user.accreditation_date = DateTime.current
|
user.accreditation_date = DateTime.current
|
||||||
user.accreditation_expire_date = user.accreditation_date + EXPIRE_DEADLINE
|
user.accreditation_expire_date = user.accreditation_date + EXPIRE_DEADLINE
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,37 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ReppV1AccreditationInfoTest < ActionDispatch::IntegrationTest
|
class ReppV1AccreditationInfoTest < ActionDispatch::IntegrationTest
|
||||||
def setup
|
if Feature.allow_accr_endspoints?
|
||||||
@user = users(:api_bestnames)
|
def setup
|
||||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
@user = users(:api_bestnames)
|
||||||
token = "Basic #{token}"
|
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||||
|
token = "Basic #{token}"
|
||||||
|
|
||||||
@auth_headers = { 'Authorization' => token }
|
@auth_headers = { 'Authorization' => token }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_valid_login
|
def test_valid_login
|
||||||
get '/repp/v1/registrar/accreditation/get_info', headers: @auth_headers
|
get '/repp/v1/registrar/accreditation/get_info', headers: @auth_headers
|
||||||
json = JSON.parse(response.body, symbolize_names: true)
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
assert_equal json[:data][:username], @user.username
|
assert_equal json[:data][:username], @user.username
|
||||||
assert json[:data][:roles].include? 'super'
|
assert json[:data][:roles].include? 'super'
|
||||||
assert_equal json[:data][:registrar_name], 'Best Names'
|
assert_equal json[:data][:registrar_name], 'Best Names'
|
||||||
assert_equal json[:data][:registrar_reg_no], '1234'
|
assert_equal json[:data][:registrar_reg_no], '1234'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_login
|
def test_invalid_login
|
||||||
token = Base64.encode64("#{@user.username}:0066600")
|
token = Base64.encode64("#{@user.username}:0066600")
|
||||||
token = "Basic #{token}"
|
token = "Basic #{token}"
|
||||||
|
|
||||||
auth_headers = { 'Authorization' => token }
|
auth_headers = { 'Authorization' => token }
|
||||||
|
|
||||||
get '/repp/v1/registrar/accreditation/get_info', headers: auth_headers
|
get '/repp/v1/registrar/accreditation/get_info', headers: auth_headers
|
||||||
json = JSON.parse(response.body, symbolize_names: true)
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
assert_response :unauthorized
|
assert_response :unauthorized
|
||||||
assert_equal json[:message], 'Invalid authorization information'
|
assert_equal json[:message], 'Invalid authorization information'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,52 +1,54 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ReppV1AccreditationResultsTest < ActionDispatch::IntegrationTest
|
class ReppV1AccreditationResultsTest < ActionDispatch::IntegrationTest
|
||||||
TEMPORARY_SECRET_KEY = ENV['accreditation_secret'].freeze
|
if Feature.allow_accr_endspoints?
|
||||||
|
TEMPORARY_SECRET_KEY = ENV['accreditation_secret'].freeze
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@user = users(:api_bestnames)
|
@user = users(:api_bestnames)
|
||||||
|
|
||||||
token = "Basic #{TEMPORARY_SECRET_KEY}"
|
token = "Basic #{TEMPORARY_SECRET_KEY}"
|
||||||
|
|
||||||
@auth_headers = { 'Authorization' => token }
|
@auth_headers = { 'Authorization' => token }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_return_valid_response
|
def test_should_return_valid_response
|
||||||
post '/repp/v1/registrar/accreditation/push_results',
|
post '/repp/v1/registrar/accreditation/push_results',
|
||||||
headers: @auth_headers,
|
headers: @auth_headers,
|
||||||
params: {accreditation_result: {username: @user.username, result: true} }
|
params: {accreditation_result: {username: @user.username, result: true} }
|
||||||
json = JSON.parse(response.body, symbolize_names: true)
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
assert_emails 2
|
assert_emails 2
|
||||||
assert_equal json[:data][:user][:username], @user.username
|
assert_equal json[:data][:user][:username], @user.username
|
||||||
assert_equal json[:data][:result], "true"
|
assert_equal json[:data][:result], "true"
|
||||||
assert_equal json[:data][:message], "Accreditation info successfully added"
|
assert_equal json[:data][:message], "Accreditation info successfully added"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_return_valid_response_invalid_authorization
|
def test_should_return_valid_response_invalid_authorization
|
||||||
post '/repp/v1/registrar/accreditation/push_results',
|
post '/repp/v1/registrar/accreditation/push_results',
|
||||||
headers: { 'Authorization' => 'Basic temporary-secret-ke'},
|
headers: { 'Authorization' => 'Basic temporary-secret-ke'},
|
||||||
params: {accreditation_result: {username: @user.username, result: true} }
|
params: {accreditation_result: {username: @user.username, result: true} }
|
||||||
json = JSON.parse(response.body, symbolize_names: true)
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
assert_response :unauthorized
|
assert_response :unauthorized
|
||||||
|
|
||||||
assert_emails 0
|
assert_emails 0
|
||||||
assert_equal json[:code], 2202
|
assert_equal json[:code], 2202
|
||||||
assert_equal json[:message], 'Invalid authorization information'
|
assert_equal json[:message], 'Invalid authorization information'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_return_valid_response_record_exception
|
def test_should_return_valid_response_record_exception
|
||||||
post '/repp/v1/registrar/accreditation/push_results',
|
post '/repp/v1/registrar/accreditation/push_results',
|
||||||
headers: @auth_headers,
|
headers: @auth_headers,
|
||||||
params: {accreditation_result: { username: "chungachanga", result: true} }
|
params: {accreditation_result: { username: "chungachanga", result: true} }
|
||||||
json = JSON.parse(response.body, symbolize_names: true)
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
assert_response :ok
|
assert_response :ok
|
||||||
|
|
||||||
assert_emails 0
|
assert_emails 0
|
||||||
assert_equal json[:code], 2303
|
assert_equal json[:code], 2303
|
||||||
assert_equal json[:message], "Object 'chungachanga' does not exist"
|
assert_equal json[:message], "Object 'chungachanga' does not exist"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue