mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Refactor user to admin and api user
This commit is contained in:
parent
f3215680d5
commit
037cb57e00
34 changed files with 551 additions and 551 deletions
|
@ -4,11 +4,11 @@ module Repp
|
|||
prefix :repp
|
||||
|
||||
http_basic do |username, password|
|
||||
@current_api_user ||= ApiUser.find_by(username: username, password: password)
|
||||
@current_user ||= ApiUser.find_by(username: username, password: password)
|
||||
end
|
||||
|
||||
helpers do
|
||||
attr_reader :current_api_user
|
||||
attr_reader :current_user
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -18,8 +18,8 @@ module Repp
|
|||
request_params: request.params.except('route_info').to_json,
|
||||
response: @response.to_json,
|
||||
response_code: status,
|
||||
api_user_name: current_api_user.try(:username),
|
||||
api_user_registrar: current_api_user.try(:registrar).try(:to_s),
|
||||
api_user_name: current_user.try(:username),
|
||||
api_user_registrar: current_user.try(:registrar).try(:to_s),
|
||||
ip: request.ip
|
||||
})
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module Repp
|
|||
resource :contacts do
|
||||
desc 'Return list of contact'
|
||||
get '/' do
|
||||
contacts = current_api_user.registrar.contacts.page(params[:page])
|
||||
contacts = current_user.registrar.contacts.page(params[:page])
|
||||
@response = {
|
||||
contacts: contacts,
|
||||
total_pages: contacts.total_pages
|
||||
|
|
|
@ -5,7 +5,7 @@ module Repp
|
|||
resource :domains do
|
||||
desc 'Return list of domains'
|
||||
get '/' do
|
||||
domains = current_api_user.registrar.domains.page(params[:page])
|
||||
domains = current_user.registrar.domains.page(params[:page])
|
||||
@response = {
|
||||
domains: domains,
|
||||
total_pages: domains.total_pages
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
class Admin::UsersController < AdminController
|
||||
class Admin::AdminUsersController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@q = User.search(params[:q])
|
||||
@users = @q.result.page(params[:page])
|
||||
@q = AdminUser.search(params[:q])
|
||||
@admin_users = @q.result.page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
@admin_user = AdminUser.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
@admin_user = AdminUser.new(admin_user_params)
|
||||
|
||||
if @user.save
|
||||
if @admin_user.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @user]
|
||||
redirect_to [:admin, @admin_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_create_record')
|
||||
render 'new'
|
||||
|
@ -28,9 +28,9 @@ class Admin::UsersController < AdminController
|
|||
def edit; end
|
||||
|
||||
def update
|
||||
if @user.update(user_params)
|
||||
if @admin_user.update(admin_user_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @user]
|
||||
redirect_to [:admin, @admin_user]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
|
@ -38,7 +38,7 @@ class Admin::UsersController < AdminController
|
|||
end
|
||||
|
||||
def destroy
|
||||
if @user.destroy
|
||||
if @admin_user.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
redirect_to admin_users_path
|
||||
else
|
||||
|
@ -50,10 +50,10 @@ class Admin::UsersController < AdminController
|
|||
private
|
||||
|
||||
def set_user
|
||||
@user = User.find(params[:id])
|
||||
@admin_user = AdminUser.find(params[:id])
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:username, :password, :identity_code, :email, :country_code, { roles: [] })
|
||||
def admin_user_params
|
||||
params.require(:admin_user).permit(:username, :password, :identity_code, :email, :country_code, { roles: [] })
|
||||
end
|
||||
end
|
|
@ -15,10 +15,10 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def user_for_paper_trail
|
||||
if defined?(current_api_user) && current_api_user.present?
|
||||
# Most of the time it's not loaded in correct time because PaperTrail before filter kicks in
|
||||
# before current_api_user is defined. PaperTrail is triggered also at current_api_user
|
||||
api_user_log_str(current_api_user)
|
||||
if defined?(current_user) && current_user.present?
|
||||
# Most of the time it's not loaded in correct time because PaperTrail before filter kicks in
|
||||
# before current_user is defined. PaperTrail is triggered also at current_user
|
||||
api_user_log_str(current_user)
|
||||
elsif current_user.present?
|
||||
"#{current_user.id}-#{current_user.username}"
|
||||
else
|
||||
|
|
|
@ -5,9 +5,9 @@ module Shared::UserStamper
|
|||
# return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id)
|
||||
|
||||
# if obj.new_record?
|
||||
# obj.created_by_id = current_api_user.id
|
||||
# obj.created_by_id = current_user.id
|
||||
# else
|
||||
# obj.updated_by_id = current_api_user.id
|
||||
# obj.updated_by_id = current_user.id
|
||||
# end
|
||||
|
||||
# true
|
||||
|
|
|
@ -3,7 +3,7 @@ class Epp::ContactsController < EppController
|
|||
|
||||
def create
|
||||
@contact = Contact.new(contact_and_address_attributes)
|
||||
@contact.registrar = current_api_user.registrar
|
||||
@contact.registrar = current_user.registrar
|
||||
render_epp_response '/epp/contacts/create' and return if @contact.save
|
||||
handle_errors(@contact)
|
||||
end
|
||||
|
@ -108,7 +108,7 @@ class Epp::ContactsController < EppController
|
|||
return false unless xml_attrs_present?(@ph, [['id']])
|
||||
@contact = find_contact
|
||||
return false unless @contact
|
||||
return true if current_api_user.registrar == @contact.registrar || xml_attrs_present?(@ph, [%w(authInfo pw)])
|
||||
return true if current_user.registrar == @contact.registrar || xml_attrs_present?(@ph, [%w(authInfo pw)])
|
||||
false
|
||||
end
|
||||
|
||||
|
@ -126,7 +126,7 @@ class Epp::ContactsController < EppController
|
|||
|
||||
def owner?(with_errors = true)
|
||||
return false unless find_contact
|
||||
return true if @contact.registrar == current_api_user.registrar
|
||||
return true if @contact.registrar == current_user.registrar
|
||||
return false unless with_errors
|
||||
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
|
||||
false
|
||||
|
@ -135,7 +135,7 @@ class Epp::ContactsController < EppController
|
|||
def rights?
|
||||
pw = @ph.try(:[], :authInfo).try(:[], :pw)
|
||||
|
||||
return true if current_api_user.try(:registrar) == @contact.try(:registrar)
|
||||
return true if current_user.try(:registrar) == @contact.try(:registrar)
|
||||
return true if pw && @contact.auth_info_matches(pw) # @contact.try(:auth_info_matches, pw)
|
||||
|
||||
epp_errors << { code: '2200', msg: t('errors.messages.epp_authentication_error') }
|
||||
|
|
|
@ -176,7 +176,7 @@ class Epp::DomainsController < EppController
|
|||
|
||||
{
|
||||
name: name,
|
||||
registrar_id: current_api_user.registrar.try(:id),
|
||||
registrar_id: current_user.registrar.try(:id),
|
||||
registered_at: Time.now,
|
||||
period: (period.to_i == 0) ? 1 : period.to_i,
|
||||
period_unit: Epp::EppDomain.parse_period_unit_from_frame(params[:parsed_frame]) || 'y'
|
||||
|
@ -187,7 +187,7 @@ class Epp::DomainsController < EppController
|
|||
res = {}
|
||||
res[:pw] = params[:parsed_frame].css('pw').first.try(:text)
|
||||
res[:action] = params[:parsed_frame].css('transfer').first[:op]
|
||||
res[:current_user] = current_api_user
|
||||
res[:current_user] = current_user
|
||||
res
|
||||
end
|
||||
|
||||
|
@ -206,7 +206,7 @@ class Epp::DomainsController < EppController
|
|||
|
||||
return domain if domain.auth_info == params[:parsed_frame].css('authInfo pw').text
|
||||
|
||||
if (domain.registrar != current_api_user.registrar && secure[:secure] == true) &&
|
||||
if (domain.registrar != current_user.registrar && secure[:secure] == true) &&
|
||||
epp_errors << {
|
||||
code: '2302',
|
||||
msg: I18n.t('errors.messages.domain_exists_but_belongs_to_other_registrar'),
|
||||
|
|
|
@ -6,7 +6,7 @@ class Epp::KeyrelaysController < EppController
|
|||
|
||||
handle_errors(@domain) and return unless @domain
|
||||
handle_errors(@domain) and return unless @domain.authenticate(params[:parsed_frame].css('pw').text)
|
||||
handle_errors(@domain) and return unless @domain.keyrelay(params[:parsed_frame], current_api_user.registrar)
|
||||
handle_errors(@domain) and return unless @domain.keyrelay(params[:parsed_frame], current_user.registrar)
|
||||
|
||||
render_epp_response '/epp/shared/success'
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class Epp::PollsController < EppController
|
|||
end
|
||||
|
||||
def req_poll
|
||||
@message = current_api_user.queued_messages.last
|
||||
@message = current_user.queued_messages.last
|
||||
render_epp_response 'epp/poll/poll_no_messages' and return unless @message
|
||||
|
||||
if @message.attached_obj_type && @message.attached_obj_id
|
||||
|
@ -20,7 +20,7 @@ class Epp::PollsController < EppController
|
|||
end
|
||||
|
||||
def ack_poll
|
||||
@message = current_api_user.queued_messages.find_by(id: params[:parsed_frame].css('poll').first['msgID'])
|
||||
@message = current_user.queued_messages.find_by(id: params[:parsed_frame].css('poll').first['msgID'])
|
||||
|
||||
unless @message
|
||||
epp_errors << {
|
||||
|
|
|
@ -16,7 +16,7 @@ class Epp::SessionsController < EppController
|
|||
end
|
||||
|
||||
def logout
|
||||
@api_user = current_api_user # cache current_api_user for logging
|
||||
@api_user = current_user # cache current_user for logging
|
||||
epp_session[:api_user_id] = nil
|
||||
response.headers['X-EPP-Returncode'] = '1500'
|
||||
render_epp_response('logout')
|
||||
|
|
|
@ -3,7 +3,7 @@ class EppController < ApplicationController
|
|||
before_action :generate_svtrid
|
||||
before_action :validate_request
|
||||
layout false
|
||||
helper_method :current_api_user
|
||||
helper_method :current_user
|
||||
|
||||
def generate_svtrid
|
||||
# rubocop: disable Style/VariableName
|
||||
|
@ -21,13 +21,13 @@ class EppController < ApplicationController
|
|||
EppSession.find_or_initialize_by(session_id: cookie['session'])
|
||||
end
|
||||
|
||||
def current_api_user
|
||||
@current_api_user ||= ApiUser.find_by_id(epp_session[:api_user_id])
|
||||
def current_user
|
||||
@current_user ||= ApiUser.find_by_id(epp_session[:api_user_id])
|
||||
# by default PaperTrail uses before filter and at that
|
||||
# time current_api_user is not yet present
|
||||
::PaperTrail.whodunnit = api_user_log_str(@current_api_user)
|
||||
# time current_user is not yet present
|
||||
::PaperTrail.whodunnit = api_user_log_str(@current_user)
|
||||
::PaperSession.session = epp_session.session_id if epp_session.session_id.present?
|
||||
@current_api_user
|
||||
@current_user
|
||||
end
|
||||
|
||||
# ERROR + RESPONSE HANDLING
|
||||
|
@ -203,8 +203,8 @@ class EppController < ApplicationController
|
|||
request_successful: epp_errors.empty?,
|
||||
request_object: params[:epp_object_type],
|
||||
response: @response,
|
||||
api_user_name: api_user_log_str(@api_user || current_api_user),
|
||||
api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_api_user.try(:registrar).try(:to_s),
|
||||
api_user_name: api_user_log_str(@api_user || current_user),
|
||||
api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_user.try(:registrar).try(:to_s),
|
||||
ip: request.ip
|
||||
})
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ class SessionsController < Devise::SessionsController
|
|||
# TODO: Create ID Card login here:
|
||||
# this is just testing config
|
||||
# if Rails.env.development? || Rails.env.test?
|
||||
@user = User.first if params[:user1]
|
||||
@user = User.second if params[:user2]
|
||||
@user = AdminUser.first if params[:user1]
|
||||
@user = AdminUser.second if params[:user2]
|
||||
|
||||
return redirect_to :back, alert: 'No user' if @user.blank?
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ module WhodunnitHelper
|
|||
user = ApiUser.find(whodunnit)
|
||||
return link_to(user.username, admin_epp_user_path(user))
|
||||
end
|
||||
user = User.find(whodunnit)
|
||||
user = AdminUser.find(whodunnit)
|
||||
return link_to(user.username, admin_user_path(user))
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
return nil
|
||||
|
@ -17,7 +17,7 @@ module WhodunnitHelper
|
|||
user = ApiUser.find(whodunnit)
|
||||
return "#{user.username} (EPP)"
|
||||
end
|
||||
user = User.find(whodunnit)
|
||||
user = AdminUser.find(whodunnit)
|
||||
return user.username
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
return nil
|
||||
|
|
|
@ -4,7 +4,7 @@ class Ability
|
|||
def initialize(user)
|
||||
alias_action :create, :read, :update, :destroy, to: :crud
|
||||
|
||||
@user = user || User.new
|
||||
@user = user || AdminUser.new
|
||||
@user.roles.each { |role| send(role) } if @user.roles
|
||||
|
||||
return if @user.roles || @user.roles.any?
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
class AdminUser < User
|
||||
devise :trackable, :timeoutable
|
||||
# TODO: Foreign user will get email with activation link,email,temp-password.
|
||||
# After activisation, system should require to change temp password.
|
||||
# TODO: Estonian id validation
|
||||
|
|
|
@ -30,7 +30,7 @@ module Versions
|
|||
if creator_str =~ /^\d-api-/
|
||||
ApiUser.find(creator_str)
|
||||
else
|
||||
User.find(creator_str)
|
||||
AdminUser.find(creator_str)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,7 +40,7 @@ module Versions
|
|||
if updator_str =~ /^\d-api-/
|
||||
ApiUser.find(updator_str)
|
||||
else
|
||||
User.find(updator_str)
|
||||
AdminUser.find(updator_str)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
class User < ActiveRecord::Base
|
||||
include Versions # version/user_version.rb
|
||||
devise :trackable, :timeoutable
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
= form_for([:admin, @user]) do |f|
|
||||
- if @user.errors.any?
|
||||
- @user.errors.each do |attr, err|
|
||||
= form_for([:admin, @admin_user]) do |f|
|
||||
- if @admin_user.errors.any?
|
||||
- @admin_user.errors.each do |attr, err|
|
||||
= err
|
||||
%br
|
||||
- if @user.errors.any?
|
||||
- if @admin_user.errors.any?
|
||||
%hr
|
||||
|
||||
.row
|
||||
|
@ -27,7 +27,7 @@
|
|||
= f.text_field(:email, class: 'form-control')
|
||||
.form-group
|
||||
= f.label :role
|
||||
= select_tag 'user[roles][]', options_for_select(User::ROLES.map {|x| [t(x), x] }, @user.roles.try(:first)), class: 'form-control selectize'
|
||||
= select_tag 'admin_user[roles][]', options_for_select(AdminUser::ROLES.map {|x| [t(x), x] }, @admin_user.roles.try(:first)), class: 'form-control selectize'
|
||||
|
||||
%hr
|
||||
.row
|
|
@ -4,6 +4,6 @@
|
|||
= "#{t('edit_user')}"
|
||||
.col-sm-6
|
||||
%h2.text-right.text-center-xs
|
||||
= link_to(t('back_to_user'), [:admin, @user], class: 'btn btn-default')
|
||||
= link_to(t('back_to_user'), [:admin, @admin_user], class: 'btn btn-default')
|
||||
%hr
|
||||
= render 'form'
|
|
@ -1,9 +1,9 @@
|
|||
.row
|
||||
.col-sm-6
|
||||
%h2.text-center-xs= t('users')
|
||||
%h2.text-center-xs= t('admin_users')
|
||||
.col-sm-6
|
||||
%h2.text-right.text-center-xs
|
||||
= link_to(t('create_new_user'), new_admin_user_path, class: 'btn btn-primary')
|
||||
= link_to(t('create_new_user'), new_admin_admin_user_path, class: 'btn btn-primary')
|
||||
%hr
|
||||
.row
|
||||
.col-md-12
|
||||
|
@ -20,7 +20,7 @@
|
|||
%th{class: 'col-xs-2'}
|
||||
= sort_link(@q, 'role', t('role'))
|
||||
%tbody
|
||||
- @users.each do |x|
|
||||
- @admin_users.each do |x|
|
||||
%tr
|
||||
%td= link_to(x, [:admin, x])
|
||||
%td= x.email
|
||||
|
@ -31,4 +31,4 @@
|
|||
%td
|
||||
.row
|
||||
.col-md-12
|
||||
= paginate @users
|
||||
= paginate @admin_users
|
|
@ -4,15 +4,15 @@
|
|||
= "#{t('user_details')}"
|
||||
.col-sm-6
|
||||
%h2.text-right.text-center-xs
|
||||
= link_to(t('edit'), edit_admin_user_path(@user), class: 'btn btn-primary')
|
||||
= link_to(t('delete'), admin_user_path(@user), method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-danger')
|
||||
= link_to(t('edit'), edit_admin_admin_user_path(@admin_user), class: 'btn btn-primary')
|
||||
= link_to(t('delete'), admin_admin_user_path(@admin_user), method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-danger')
|
||||
|
||||
%hr
|
||||
- if @user.errors.any?
|
||||
- @user.errors.each do |attr, err|
|
||||
- if @admin_user.errors.any?
|
||||
- @admin_user.errors.each do |attr, err|
|
||||
= err
|
||||
%br
|
||||
- if @user.errors.any?
|
||||
- if @admin_user.errors.any?
|
||||
%hr
|
||||
.row
|
||||
.col-md-6
|
||||
|
@ -22,13 +22,13 @@
|
|||
.panel-body
|
||||
%dl.dl-horizontal
|
||||
%dt= t('username')
|
||||
%dd= @user.username
|
||||
%dd= @admin_user.username
|
||||
|
||||
%dt= t('password')
|
||||
%dd= @user.password
|
||||
%dd= @admin_user.password
|
||||
|
||||
%dt= t('identity_code')
|
||||
%dd= @user.identity_code
|
||||
%dd= @admin_user.identity_code
|
||||
|
||||
.col-md-6
|
||||
.panel.panel-default
|
||||
|
@ -37,10 +37,10 @@
|
|||
.panel-body
|
||||
%dl.dl-horizontal
|
||||
%dt= t('email')
|
||||
%dd= @user.email
|
||||
%dd= @admin_user.email
|
||||
|
||||
%dt= t('role')
|
||||
- if @user.roles
|
||||
%dd= t(@user.roles.first)
|
||||
- if @admin_user.roles
|
||||
%dd= t(@admin_user.roles.first)
|
||||
- else
|
||||
%dd
|
|
@ -4,7 +4,7 @@ xml.epp_head do
|
|||
xml.msg 'Command completed successfully'
|
||||
end
|
||||
|
||||
xml.tag!('msgQ', 'count' => current_api_user.queued_messages.count, 'id' => @message.id)
|
||||
xml.tag!('msgQ', 'count' => current_user.queued_messages.count, 'id' => @message.id)
|
||||
|
||||
xml << render('/epp/shared/trID')
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ xml.epp(
|
|||
xml.msg 'Command completed successfully; ack to dequeue'
|
||||
end
|
||||
|
||||
xml.tag!('msgQ', 'count' => current_api_user.queued_messages.count, 'id' => @message.id) do
|
||||
xml.tag!('msgQ', 'count' => current_user.queued_messages.count, 'id' => @message.id) do
|
||||
xml.qDate @message.created_at
|
||||
xml.msg @message.body
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ xml.epp_head do
|
|||
xml.msg 'Command completed successfully; ack to dequeue'
|
||||
end
|
||||
|
||||
xml.tag!('msgQ', 'count' => current_api_user.queued_messages.count, 'id' => @message.id) do
|
||||
xml.tag!('msgQ', 'count' => current_user.queued_messages.count, 'id' => @message.id) do
|
||||
xml.qDate @message.created_at
|
||||
xml.msg @message.body
|
||||
end
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
|
||||
%li.divider
|
||||
%li.dropdown-header= t('users')
|
||||
%li= link_to t(:admin_users), admin_users_path
|
||||
%li= link_to t(:admin_users), admin_admin_users_path
|
||||
%li= link_to t(:api_users), admin_api_users_path
|
||||
|
||||
%ul.nav.navbar-nav.navbar-right
|
||||
|
|
|
@ -45,7 +45,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :users
|
||||
resources :admin_users
|
||||
resources :api_users do
|
||||
member do
|
||||
get 'download_csr'
|
||||
|
|
|
@ -31,7 +31,7 @@ ApiUser.where(
|
|||
registrar: registrar2
|
||||
).first_or_create!
|
||||
|
||||
User.where(
|
||||
AdminUser.where(
|
||||
username: 'user1',
|
||||
password: 'test1',
|
||||
email: 'user1@example.ee',
|
||||
|
@ -39,7 +39,7 @@ User.where(
|
|||
country_code: 'EE'
|
||||
).first_or_create!
|
||||
|
||||
User.where(
|
||||
AdminUser.where(
|
||||
username: 'user2',
|
||||
password: 'test2',
|
||||
email: 'user2@example.ee',
|
||||
|
@ -47,7 +47,7 @@ User.where(
|
|||
country_code: 'EE'
|
||||
).first_or_create!
|
||||
|
||||
User.where(
|
||||
AdminUser.where(
|
||||
username: 'user3',
|
||||
password: 'test3',
|
||||
email: 'user3@example.ee',
|
||||
|
@ -55,4 +55,4 @@ User.where(
|
|||
country_code: 'EE'
|
||||
).first_or_create!
|
||||
|
||||
User.update_all(roles: ['admin'])
|
||||
AdminUser.update_all(roles: ['admin'])
|
||||
|
|
|
@ -1,451 +1,451 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe 'EPP Contact', epp: true do
|
||||
before :all do
|
||||
create_settings
|
||||
create_disclosure_settings
|
||||
@registrar1 = Fabricate(:registrar1)
|
||||
@registrar2 = Fabricate(:registrar2)
|
||||
@epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345')
|
||||
|
||||
Fabricate(:api_user, username: 'registrar1', registrar: @registrar1)
|
||||
Fabricate(:api_user, username: 'registrar2', registrar: @registrar2)
|
||||
|
||||
login_as :registrar1
|
||||
|
||||
Contact.skip_callback(:create, :before, :generate_code)
|
||||
Contact.skip_callback(:create, :before, :generate_auth_info)
|
||||
end
|
||||
|
||||
after :all do
|
||||
Contact.set_callback(:create, :before, :generate_code)
|
||||
Contact.set_callback(:create, :before, :generate_auth_info)
|
||||
end
|
||||
|
||||
context 'with valid user' do
|
||||
context 'create command' do
|
||||
it 'fails if request xml is missing' do
|
||||
xml = @epp_xml.create
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:results][0][:msg].should == 'Command syntax error'
|
||||
response[:results][0][:result_code].should == '2001'
|
||||
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
|
||||
it 'fails if request xml is missing' do
|
||||
xml = @epp_xml.create(
|
||||
postalInfo: { addr: { value: nil } }
|
||||
)
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:results][0][:msg].should == 'Required parameter missing: name'
|
||||
response[:results][1][:msg].should == 'Required parameter missing: city'
|
||||
response[:results][2][:msg].should == 'Required parameter missing: cc'
|
||||
response[:results][3][:msg].should == 'Required parameter missing: ident'
|
||||
response[:results][4][:msg].should == 'Required parameter missing: voice'
|
||||
response[:results][5][:msg].should == 'Required parameter missing: email'
|
||||
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
response[:results][1][:result_code].should == '2003'
|
||||
response[:results][2][:result_code].should == '2003'
|
||||
response[:results][3][:result_code].should == '2003'
|
||||
response[:results][4][:result_code].should == '2003'
|
||||
response[:results][5][:result_code].should == '2003'
|
||||
|
||||
response[:results].count.should == 6
|
||||
end
|
||||
|
||||
it 'successfully saves ident type' do
|
||||
xml = { ident: { value: '1990-22-12', attrs: { type: 'birthday' } } }
|
||||
epp_plain_request(create_contact_xml(xml), :xml)
|
||||
|
||||
Contact.last.ident_type.should == 'birthday'
|
||||
end
|
||||
|
||||
it 'successfully creates a contact' do
|
||||
response = epp_plain_request(create_contact_xml, :xml)
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
@contact = Contact.last
|
||||
|
||||
@contact.registrar.should == @registrar1
|
||||
# registrar1.api_users.should include(@contact.created_by)
|
||||
# @contact.updated_by_id.should == nil
|
||||
@contact.ident.should == '37605030299'
|
||||
@contact.address.street.should == '123 Example'
|
||||
|
||||
log = ApiLog::EppLog.last
|
||||
log.request_command.should == 'create'
|
||||
log.request_object.should == 'contact'
|
||||
log.request_successful.should == true
|
||||
log.api_user_name.should == '1-api-registrar1'
|
||||
log.api_user_registrar.should == 'registrar1'
|
||||
end
|
||||
|
||||
it 'successfully adds registrar' do
|
||||
response = epp_plain_request(create_contact_xml, :xml)
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
Contact.last.registrar.should == @registrar1
|
||||
end
|
||||
|
||||
it 'returns result data upon success' do
|
||||
response = epp_plain_request(create_contact_xml, :xml)
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
id = response[:parsed].css('resData creData id').first
|
||||
cr_date = response[:parsed].css('resData creData crDate').first
|
||||
|
||||
id.text.length.should == 8
|
||||
# 5 seconds for what-ever weird lag reasons might happen
|
||||
cr_date.text.to_time.should be_within(5).of(Time.now)
|
||||
end
|
||||
|
||||
it 'creates disclosure data' do
|
||||
xml = {
|
||||
disclose: { value: {
|
||||
voice: { value: '' },
|
||||
addr: { value: '' },
|
||||
name: { value: '' },
|
||||
org_name: { value: '' },
|
||||
email: { value: '' },
|
||||
fax: { value: '' }
|
||||
}, attrs: { flag: '1' }
|
||||
}
|
||||
}
|
||||
|
||||
response = epp_plain_request(create_contact_xml(xml), :xml)
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
@contact = Contact.last
|
||||
@contact.disclosure.name.should == true
|
||||
@contact.disclosure.org_name.should == true
|
||||
@contact.disclosure.phone.should == true
|
||||
@contact.disclosure.fax.should == true
|
||||
@contact.disclosure.email.should == true
|
||||
@contact.disclosure.address.should == true
|
||||
end
|
||||
|
||||
it 'creates disclosure data merging with defaults' do
|
||||
xml = {
|
||||
disclose: { value: {
|
||||
voice: { value: '' },
|
||||
addr: { value: '' }
|
||||
}, attrs: { flag: '1' }
|
||||
}
|
||||
}
|
||||
|
||||
response = epp_plain_request(create_contact_xml(xml), :xml)
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
@contact = Contact.last
|
||||
@contact.disclosure.name.should == nil
|
||||
@contact.disclosure.org_name.should == nil
|
||||
@contact.disclosure.phone.should == true
|
||||
@contact.disclosure.fax.should == nil
|
||||
@contact.disclosure.email.should == nil
|
||||
@contact.disclosure.address.should == true
|
||||
end
|
||||
end
|
||||
|
||||
context 'update command' do
|
||||
before :all do
|
||||
@contact =
|
||||
Fabricate(
|
||||
:contact,
|
||||
# created_by_id: 1,
|
||||
registrar: @registrar1,
|
||||
email: 'not_updated@test.test',
|
||||
code: 'sh8013',
|
||||
auth_info: 'password'
|
||||
)
|
||||
end
|
||||
|
||||
it 'fails if request is invalid' do
|
||||
xml = @epp_xml.update
|
||||
response = epp_plain_request(xml, :xml) # epp_request('contacts/update_missing_attr.xml')
|
||||
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
response[:results][0][:msg].should == 'Required parameter missing: add, rem or chg'
|
||||
response[:results][1][:result_code].should == '2003'
|
||||
response[:results][1][:msg].should == 'Required parameter missing: id'
|
||||
response[:results].count.should == 2
|
||||
end
|
||||
|
||||
it 'fails with wrong authentication info' do
|
||||
login_as :registrar2 do
|
||||
response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml)
|
||||
expect(response[:msg]).to eq('Authorization error')
|
||||
expect(response[:result_code]).to eq('2201')
|
||||
end
|
||||
end
|
||||
|
||||
it 'is succesful' do
|
||||
response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml)
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
@contact.reload
|
||||
@contact.name.should == 'John Doe Edited'
|
||||
@contact.email.should == 'edited@example.example'
|
||||
end
|
||||
|
||||
it 'returns phone and email error' do
|
||||
xml = {
|
||||
id: { value: 'sh8013' },
|
||||
chg: {
|
||||
voice: { value: '123213' },
|
||||
email: { value: 'aaa' }
|
||||
}
|
||||
}
|
||||
|
||||
response = epp_plain_request(update_contact_xml(xml), :xml)
|
||||
|
||||
response[:results][0][:msg].should == 'Phone nr is invalid'
|
||||
response[:results][0][:result_code].should == '2005'
|
||||
|
||||
response[:results][1][:msg].should == 'Email is invalid'
|
||||
response[:results][1][:result_code].should == '2005'
|
||||
end
|
||||
|
||||
it 'updates disclosure items' do
|
||||
Fabricate(
|
||||
:contact,
|
||||
code: 'sh8013disclosure',
|
||||
auth_info: '2fooBAR',
|
||||
registrar: @registrar1,
|
||||
# created_by_id: ApiUser.first.id,
|
||||
disclosure: Fabricate(:contact_disclosure, phone: true, email: true))
|
||||
|
||||
xml = {
|
||||
id: { value: 'sh8013disclosure' },
|
||||
authInfo: { pw: { value: '2fooBAR' } }
|
||||
}
|
||||
@response = epp_plain_request(update_contact_xml(xml), :xml)
|
||||
|
||||
@response[:results][0][:msg].should == 'Command completed successfully'
|
||||
@response[:results][0][:result_code].should == '1000'
|
||||
|
||||
Contact.last.disclosure.phone.should == false
|
||||
Contact.last.disclosure.email.should == false
|
||||
end
|
||||
end
|
||||
|
||||
context 'delete command' do
|
||||
it 'fails if request is invalid' do
|
||||
xml = @epp_xml.delete({ uid: { value: '23123' } })
|
||||
response = epp_plain_request(xml, :xml)
|
||||
|
||||
response[:results][0][:msg].should == 'Required parameter missing: id'
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
|
||||
it 'deletes contact' do
|
||||
@contact_deleted =
|
||||
# Fabricate(:contact, code: 'dwa1234', created_by_id: ApiUser.first.id, registrar: registrar1)
|
||||
Fabricate(:contact, code: 'dwa1234', registrar: @registrar1)
|
||||
|
||||
response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
response[:clTRID].should == 'ABC-12345'
|
||||
|
||||
Contact.find_by_id(@contact_deleted.id).should == nil
|
||||
end
|
||||
|
||||
it 'returns error if obj doesnt exist' do
|
||||
response = epp_plain_request(delete_contact_xml, :xml)
|
||||
response[:msg].should == 'Object does not exist'
|
||||
response[:result_code].should == '2303'
|
||||
end
|
||||
|
||||
it 'fails if contact has associated domain' do
|
||||
Fabricate(
|
||||
:domain,
|
||||
registrar: @registrar1,
|
||||
owner_contact: Fabricate(
|
||||
:contact,
|
||||
code: 'dwa1234',
|
||||
# created_by_id: registrar1.id,
|
||||
registrar: @registrar1)
|
||||
)
|
||||
Domain.last.owner_contact.address.present?.should == true
|
||||
response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
|
||||
|
||||
response[:msg].should == 'Object association prohibits operation'
|
||||
response[:result_code].should == '2305'
|
||||
|
||||
Domain.last.owner_contact.present?.should == true
|
||||
end
|
||||
end
|
||||
|
||||
context 'check command' do
|
||||
it 'fails if request is invalid' do
|
||||
xml = @epp_xml.check({ uid: { value: '123asde' } })
|
||||
response = epp_plain_request(xml, :xml)
|
||||
|
||||
response[:results][0][:msg].should == 'Required parameter missing: id'
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
response[:results].count.should == 1
|
||||
end
|
||||
|
||||
it 'returns info about contact availability' do
|
||||
Fabricate(:contact, code: 'check-1234')
|
||||
|
||||
response = epp_plain_request(check_multiple_contacts_xml, :xml)
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
ids = response[:parsed].css('resData chkData id')
|
||||
|
||||
ids[0].attributes['avail'].text.should == '0'
|
||||
ids[1].attributes['avail'].text.should == '1'
|
||||
|
||||
ids[0].text.should == 'check-1234'
|
||||
ids[1].text.should == 'check-4321'
|
||||
end
|
||||
end
|
||||
|
||||
# context 'info command' do
|
||||
# before :all do
|
||||
# @registrar1_contact = Fabricate(:contact, code: 'info-4444', registrar: @registrar1,
|
||||
# name: 'Johnny Awesome', address: Fabricate(:address))
|
||||
# end
|
||||
|
||||
# fit 'return info about contact' do
|
||||
# login_as :registrar2 do
|
||||
# xml = @epp_xml.info(id: { value: @registrar1_contact.code })
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# contact = response[:parsed].css('resData chkData')
|
||||
# contact.css('name').first.text.should == 'Johnny Awesome'
|
||||
# end
|
||||
# end
|
||||
|
||||
# it 'fails if request invalid' do
|
||||
# response = epp_plain_request(@epp_xml.info({ wrongid: { value: '123123' } }), :xml)
|
||||
# response[:results][0][:msg].should == 'Required parameter missing: id'
|
||||
# response[:results][0][:result_code].should == '2003'
|
||||
# response[:results].count.should == 1
|
||||
# end
|
||||
|
||||
# it 'returns error when object does not exist' do
|
||||
# response = epp_plain_request(info_contact_xml({ id: { value: 'no-contact' } }), :xml)
|
||||
# response[:msg].should == 'Object does not exist'
|
||||
# response[:result_code].should == '2303'
|
||||
# response[:results][0][:value].should == 'no-contact'
|
||||
# end
|
||||
|
||||
# # it 'returns auth error for non-owner with wrong password' do
|
||||
# # @contact = Fabricate(:contact,
|
||||
# # registrar: registrar2, code: 'info-4444', name: 'Johnny Awesome', auth_info: 'asde',
|
||||
# # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# # xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'asdesde' } } })
|
||||
# # response = epp_plain_request(xml, :xml, :registrar1)
|
||||
|
||||
# # expect(response[:result_code]).to eq('2200')
|
||||
# # expect(response[:msg]).to eq('Authentication error')
|
||||
# # end
|
||||
|
||||
# context 'about disclose' do
|
||||
# it 'discloses items with wrong password when queried by owner' do
|
||||
# @contact = Fabricate(:contact,
|
||||
# registrar: registrar1, code: 'info-4444',
|
||||
# name: 'Johnny Awesome', auth_info: 'asde',
|
||||
# address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# xml = @epp_xml.info({ id: { value: @contact.code } })
|
||||
# login_as :registrar1 do
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
# contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# expect(response[:result_code]).to eq('1000')
|
||||
# expect(response[:msg]).to eq('Command completed successfully')
|
||||
# expect(contact.css('name').first.text).to eq('Johnny Awesome')
|
||||
# end
|
||||
# end
|
||||
|
||||
# it 'doesn\'t disclose items to non-owner with right password' do
|
||||
# @contact = Fabricate(:contact, registrar: registrar2, code: 'info-4444',
|
||||
# name: 'Johnny Awesome', auth_info: 'password',
|
||||
# address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'password' } } })
|
||||
# response = epp_plain_request(xml, :xml, :registrar1)
|
||||
# contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# expect(response[:result_code]).to eq('1000')
|
||||
# expect(response[:msg]).to eq('Command completed successfully')
|
||||
# expect(contact.css('chkData postalInfo name').first).to eq(nil)
|
||||
# end
|
||||
|
||||
# it 'discloses items to owner' do
|
||||
# @contact = Fabricate(:contact, registrar: registrar1, code: 'info-4444', name: 'Johnny Awesome',
|
||||
# auth_info: 'password',
|
||||
# address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# xml = @epp_xml.info({ id: { value: @contact.code } })
|
||||
# response = epp_plain_request(xml, :xml, :registrar1)
|
||||
# contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# expect(response[:result_code]).to eq('1000')
|
||||
# expect(response[:msg]).to eq('Command completed successfully')
|
||||
# expect(contact.css('name').first.text).to eq('Johnny Awesome')
|
||||
# end
|
||||
|
||||
# it 'doesn\'t disclose private elements' do
|
||||
# Fabricate(:contact, code: 'info-4444', auth_info: '2fooBAR', registrar: registrar2,
|
||||
# disclosure: Fabricate(:contact_disclosure, name: true, email: false, phone: false))
|
||||
|
||||
# xml = @epp_xml.info({ id: { value: 'info-4444' }, authInfo: { pw: { value: '2fooBAR' } } })
|
||||
|
||||
# response = epp_plain_request(xml, :xml, :registrar1)
|
||||
# contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# expect(response[:result_code]).to eq('1000')
|
||||
|
||||
# expect(contact.css('chkData phone')).to eq(contact.css('chkData disclose phone'))
|
||||
# expect(contact.css('chkData phone').count).to eq(1)
|
||||
# expect(contact.css('chkData email')).to eq(contact.css('chkData disclose email'))
|
||||
# expect(contact.css('chkData email').count).to eq(1)
|
||||
# expect(contact.css('postalInfo name').present?).to be(true)
|
||||
# end
|
||||
# end
|
||||
|
||||
# it 'does not display unassociated object without password' do
|
||||
# xml = @epp_xml.info(id: { value: @registrar1_contact.code })
|
||||
# response = epp_plain_request(xml, :xml, :registrar2)
|
||||
# expect(response[:result_code]).to eq('2003')
|
||||
# expect(response[:msg]).to eq('Required parameter missing: pw')
|
||||
# end
|
||||
|
||||
# it 'does not display unassociated object with wrong password' do
|
||||
# login_as :registrar2
|
||||
# xml = @epp_xml.info(id: { value: @registrar1_contact.code },
|
||||
# authInfo: { pw: { value: 'wrong-pw' } })
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
|
||||
# response[:msg].should == 'Authentication error'
|
||||
# response[:result_code].should == '2200'
|
||||
# end
|
||||
# end
|
||||
|
||||
context 'renew command' do
|
||||
it 'returns 2101-unimplemented command' do
|
||||
response = epp_plain_request('contacts/renew.xml')
|
||||
|
||||
response[:msg].should == 'Unimplemented command'
|
||||
response[:result_code].should == '2101'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# require 'rails_helper'
|
||||
|
||||
# describe 'EPP Contact', epp: true do
|
||||
# before :all do
|
||||
# create_settings
|
||||
# create_disclosure_settings
|
||||
# @registrar1 = Fabricate(:registrar1)
|
||||
# @registrar2 = Fabricate(:registrar2)
|
||||
# @epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345')
|
||||
|
||||
# Fabricate(:api_user, username: 'registrar1', registrar: @registrar1)
|
||||
# Fabricate(:api_user, username: 'registrar2', registrar: @registrar2)
|
||||
|
||||
# login_as :registrar1
|
||||
|
||||
# Contact.skip_callback(:create, :before, :generate_code)
|
||||
# Contact.skip_callback(:create, :before, :generate_auth_info)
|
||||
# end
|
||||
|
||||
# after :all do
|
||||
# Contact.set_callback(:create, :before, :generate_code)
|
||||
# Contact.set_callback(:create, :before, :generate_auth_info)
|
||||
# end
|
||||
|
||||
# context 'with valid user' do
|
||||
# context 'create command' do
|
||||
# it 'fails if request xml is missing' do
|
||||
# xml = @epp_xml.create
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
# response[:results][0][:msg].should == 'Command syntax error'
|
||||
# response[:results][0][:result_code].should == '2001'
|
||||
|
||||
# response[:results].count.should == 1
|
||||
# end
|
||||
|
||||
# it 'fails if request xml is missing' do
|
||||
# xml = @epp_xml.create(
|
||||
# postalInfo: { addr: { value: nil } }
|
||||
# )
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
# response[:results][0][:msg].should == 'Required parameter missing: name'
|
||||
# response[:results][1][:msg].should == 'Required parameter missing: city'
|
||||
# response[:results][2][:msg].should == 'Required parameter missing: cc'
|
||||
# response[:results][3][:msg].should == 'Required parameter missing: ident'
|
||||
# response[:results][4][:msg].should == 'Required parameter missing: voice'
|
||||
# response[:results][5][:msg].should == 'Required parameter missing: email'
|
||||
|
||||
# response[:results][0][:result_code].should == '2003'
|
||||
# response[:results][1][:result_code].should == '2003'
|
||||
# response[:results][2][:result_code].should == '2003'
|
||||
# response[:results][3][:result_code].should == '2003'
|
||||
# response[:results][4][:result_code].should == '2003'
|
||||
# response[:results][5][:result_code].should == '2003'
|
||||
|
||||
# response[:results].count.should == 6
|
||||
# end
|
||||
|
||||
# it 'successfully saves ident type' do
|
||||
# xml = { ident: { value: '1990-22-12', attrs: { type: 'birthday' } } }
|
||||
# epp_plain_request(create_contact_xml(xml), :xml)
|
||||
|
||||
# Contact.last.ident_type.should == 'birthday'
|
||||
# end
|
||||
|
||||
# it 'successfully creates a contact' do
|
||||
# response = epp_plain_request(create_contact_xml, :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# @contact = Contact.last
|
||||
|
||||
# @contact.registrar.should == @registrar1
|
||||
# # registrar1.api_users.should include(@contact.created_by)
|
||||
# # @contact.updated_by_id.should == nil
|
||||
# @contact.ident.should == '37605030299'
|
||||
# @contact.address.street.should == '123 Example'
|
||||
|
||||
# log = ApiLog::EppLog.last
|
||||
# log.request_command.should == 'create'
|
||||
# log.request_object.should == 'contact'
|
||||
# log.request_successful.should == true
|
||||
# log.api_user_name.should == '1-api-registrar1'
|
||||
# log.api_user_registrar.should == 'registrar1'
|
||||
# end
|
||||
|
||||
# it 'successfully adds registrar' do
|
||||
# response = epp_plain_request(create_contact_xml, :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# Contact.last.registrar.should == @registrar1
|
||||
# end
|
||||
|
||||
# it 'returns result data upon success' do
|
||||
# response = epp_plain_request(create_contact_xml, :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# id = response[:parsed].css('resData creData id').first
|
||||
# cr_date = response[:parsed].css('resData creData crDate').first
|
||||
|
||||
# id.text.length.should == 8
|
||||
# # 5 seconds for what-ever weird lag reasons might happen
|
||||
# cr_date.text.to_time.should be_within(5).of(Time.now)
|
||||
# end
|
||||
|
||||
# it 'creates disclosure data' do
|
||||
# xml = {
|
||||
# disclose: { value: {
|
||||
# voice: { value: '' },
|
||||
# addr: { value: '' },
|
||||
# name: { value: '' },
|
||||
# org_name: { value: '' },
|
||||
# email: { value: '' },
|
||||
# fax: { value: '' }
|
||||
# }, attrs: { flag: '1' }
|
||||
# }
|
||||
# }
|
||||
|
||||
# response = epp_plain_request(create_contact_xml(xml), :xml)
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# @contact = Contact.last
|
||||
# @contact.disclosure.name.should == true
|
||||
# @contact.disclosure.org_name.should == true
|
||||
# @contact.disclosure.phone.should == true
|
||||
# @contact.disclosure.fax.should == true
|
||||
# @contact.disclosure.email.should == true
|
||||
# @contact.disclosure.address.should == true
|
||||
# end
|
||||
|
||||
# it 'creates disclosure data merging with defaults' do
|
||||
# xml = {
|
||||
# disclose: { value: {
|
||||
# voice: { value: '' },
|
||||
# addr: { value: '' }
|
||||
# }, attrs: { flag: '1' }
|
||||
# }
|
||||
# }
|
||||
|
||||
# response = epp_plain_request(create_contact_xml(xml), :xml)
|
||||
# response[:result_code].should == '1000'
|
||||
|
||||
# @contact = Contact.last
|
||||
# @contact.disclosure.name.should == nil
|
||||
# @contact.disclosure.org_name.should == nil
|
||||
# @contact.disclosure.phone.should == true
|
||||
# @contact.disclosure.fax.should == nil
|
||||
# @contact.disclosure.email.should == nil
|
||||
# @contact.disclosure.address.should == true
|
||||
# end
|
||||
# end
|
||||
|
||||
# context 'update command' do
|
||||
# before :all do
|
||||
# @contact =
|
||||
# Fabricate(
|
||||
# :contact,
|
||||
# # created_by_id: 1,
|
||||
# registrar: @registrar1,
|
||||
# email: 'not_updated@test.test',
|
||||
# code: 'sh8013',
|
||||
# auth_info: 'password'
|
||||
# )
|
||||
# end
|
||||
|
||||
# it 'fails if request is invalid' do
|
||||
# xml = @epp_xml.update
|
||||
# response = epp_plain_request(xml, :xml) # epp_request('contacts/update_missing_attr.xml')
|
||||
|
||||
# response[:results][0][:result_code].should == '2003'
|
||||
# response[:results][0][:msg].should == 'Required parameter missing: add, rem or chg'
|
||||
# response[:results][1][:result_code].should == '2003'
|
||||
# response[:results][1][:msg].should == 'Required parameter missing: id'
|
||||
# response[:results].count.should == 2
|
||||
# end
|
||||
|
||||
# it 'fails with wrong authentication info' do
|
||||
# login_as :registrar2 do
|
||||
# response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml)
|
||||
# expect(response[:msg]).to eq('Authorization error')
|
||||
# expect(response[:result_code]).to eq('2201')
|
||||
# end
|
||||
# end
|
||||
|
||||
# it 'is succesful' do
|
||||
# response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# @contact.reload
|
||||
# @contact.name.should == 'John Doe Edited'
|
||||
# @contact.email.should == 'edited@example.example'
|
||||
# end
|
||||
|
||||
# it 'returns phone and email error' do
|
||||
# xml = {
|
||||
# id: { value: 'sh8013' },
|
||||
# chg: {
|
||||
# voice: { value: '123213' },
|
||||
# email: { value: 'aaa' }
|
||||
# }
|
||||
# }
|
||||
|
||||
# response = epp_plain_request(update_contact_xml(xml), :xml)
|
||||
|
||||
# response[:results][0][:msg].should == 'Phone nr is invalid'
|
||||
# response[:results][0][:result_code].should == '2005'
|
||||
|
||||
# response[:results][1][:msg].should == 'Email is invalid'
|
||||
# response[:results][1][:result_code].should == '2005'
|
||||
# end
|
||||
|
||||
# it 'updates disclosure items' do
|
||||
# Fabricate(
|
||||
# :contact,
|
||||
# code: 'sh8013disclosure',
|
||||
# auth_info: '2fooBAR',
|
||||
# registrar: @registrar1,
|
||||
# # created_by_id: ApiUser.first.id,
|
||||
# disclosure: Fabricate(:contact_disclosure, phone: true, email: true))
|
||||
|
||||
# xml = {
|
||||
# id: { value: 'sh8013disclosure' },
|
||||
# authInfo: { pw: { value: '2fooBAR' } }
|
||||
# }
|
||||
# @response = epp_plain_request(update_contact_xml(xml), :xml)
|
||||
|
||||
# @response[:results][0][:msg].should == 'Command completed successfully'
|
||||
# @response[:results][0][:result_code].should == '1000'
|
||||
|
||||
# Contact.last.disclosure.phone.should == false
|
||||
# Contact.last.disclosure.email.should == false
|
||||
# end
|
||||
# end
|
||||
|
||||
# context 'delete command' do
|
||||
# it 'fails if request is invalid' do
|
||||
# xml = @epp_xml.delete({ uid: { value: '23123' } })
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
|
||||
# response[:results][0][:msg].should == 'Required parameter missing: id'
|
||||
# response[:results][0][:result_code].should == '2003'
|
||||
# response[:results].count.should == 1
|
||||
# end
|
||||
|
||||
# it 'deletes contact' do
|
||||
# @contact_deleted =
|
||||
# # Fabricate(:contact, code: 'dwa1234', created_by_id: ApiUser.first.id, registrar: registrar1)
|
||||
# Fabricate(:contact, code: 'dwa1234', registrar: @registrar1)
|
||||
|
||||
# response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
# response[:clTRID].should == 'ABC-12345'
|
||||
|
||||
# Contact.find_by_id(@contact_deleted.id).should == nil
|
||||
# end
|
||||
|
||||
# it 'returns error if obj doesnt exist' do
|
||||
# response = epp_plain_request(delete_contact_xml, :xml)
|
||||
# response[:msg].should == 'Object does not exist'
|
||||
# response[:result_code].should == '2303'
|
||||
# end
|
||||
|
||||
# it 'fails if contact has associated domain' do
|
||||
# Fabricate(
|
||||
# :domain,
|
||||
# registrar: @registrar1,
|
||||
# owner_contact: Fabricate(
|
||||
# :contact,
|
||||
# code: 'dwa1234',
|
||||
# # created_by_id: registrar1.id,
|
||||
# registrar: @registrar1)
|
||||
# )
|
||||
# Domain.last.owner_contact.address.present?.should == true
|
||||
# response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
|
||||
|
||||
# response[:msg].should == 'Object association prohibits operation'
|
||||
# response[:result_code].should == '2305'
|
||||
|
||||
# Domain.last.owner_contact.present?.should == true
|
||||
# end
|
||||
# end
|
||||
|
||||
# context 'check command' do
|
||||
# it 'fails if request is invalid' do
|
||||
# xml = @epp_xml.check({ uid: { value: '123asde' } })
|
||||
# response = epp_plain_request(xml, :xml)
|
||||
|
||||
# response[:results][0][:msg].should == 'Required parameter missing: id'
|
||||
# response[:results][0][:result_code].should == '2003'
|
||||
# response[:results].count.should == 1
|
||||
# end
|
||||
|
||||
# it 'returns info about contact availability' do
|
||||
# Fabricate(:contact, code: 'check-1234')
|
||||
|
||||
# response = epp_plain_request(check_multiple_contacts_xml, :xml)
|
||||
|
||||
# response[:msg].should == 'Command completed successfully'
|
||||
# response[:result_code].should == '1000'
|
||||
# ids = response[:parsed].css('resData chkData id')
|
||||
|
||||
# ids[0].attributes['avail'].text.should == '0'
|
||||
# ids[1].attributes['avail'].text.should == '1'
|
||||
|
||||
# ids[0].text.should == 'check-1234'
|
||||
# ids[1].text.should == 'check-4321'
|
||||
# end
|
||||
# end
|
||||
|
||||
# # context 'info command' do
|
||||
# # before :all do
|
||||
# # @registrar1_contact = Fabricate(:contact, code: 'info-4444', registrar: @registrar1,
|
||||
# # name: 'Johnny Awesome', address: Fabricate(:address))
|
||||
# # end
|
||||
|
||||
# # fit 'return info about contact' do
|
||||
# # login_as :registrar2 do
|
||||
# # xml = @epp_xml.info(id: { value: @registrar1_contact.code })
|
||||
# # response = epp_plain_request(xml, :xml)
|
||||
# # response[:msg].should == 'Command completed successfully'
|
||||
# # response[:result_code].should == '1000'
|
||||
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
# # contact.css('name').first.text.should == 'Johnny Awesome'
|
||||
# # end
|
||||
# # end
|
||||
|
||||
# # it 'fails if request invalid' do
|
||||
# # response = epp_plain_request(@epp_xml.info({ wrongid: { value: '123123' } }), :xml)
|
||||
# # response[:results][0][:msg].should == 'Required parameter missing: id'
|
||||
# # response[:results][0][:result_code].should == '2003'
|
||||
# # response[:results].count.should == 1
|
||||
# # end
|
||||
|
||||
# # it 'returns error when object does not exist' do
|
||||
# # response = epp_plain_request(info_contact_xml({ id: { value: 'no-contact' } }), :xml)
|
||||
# # response[:msg].should == 'Object does not exist'
|
||||
# # response[:result_code].should == '2303'
|
||||
# # response[:results][0][:value].should == 'no-contact'
|
||||
# # end
|
||||
|
||||
# # # it 'returns auth error for non-owner with wrong password' do
|
||||
# # # @contact = Fabricate(:contact,
|
||||
# # # registrar: registrar2, code: 'info-4444', name: 'Johnny Awesome', auth_info: 'asde',
|
||||
# # # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# # # xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'asdesde' } } })
|
||||
# # # response = epp_plain_request(xml, :xml, :registrar1)
|
||||
|
||||
# # # expect(response[:result_code]).to eq('2200')
|
||||
# # # expect(response[:msg]).to eq('Authentication error')
|
||||
# # # end
|
||||
|
||||
# # context 'about disclose' do
|
||||
# # it 'discloses items with wrong password when queried by owner' do
|
||||
# # @contact = Fabricate(:contact,
|
||||
# # registrar: registrar1, code: 'info-4444',
|
||||
# # name: 'Johnny Awesome', auth_info: 'asde',
|
||||
# # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# # xml = @epp_xml.info({ id: { value: @contact.code } })
|
||||
# # login_as :registrar1 do
|
||||
# # response = epp_plain_request(xml, :xml)
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# # expect(response[:result_code]).to eq('1000')
|
||||
# # expect(response[:msg]).to eq('Command completed successfully')
|
||||
# # expect(contact.css('name').first.text).to eq('Johnny Awesome')
|
||||
# # end
|
||||
# # end
|
||||
|
||||
# # it 'doesn\'t disclose items to non-owner with right password' do
|
||||
# # @contact = Fabricate(:contact, registrar: registrar2, code: 'info-4444',
|
||||
# # name: 'Johnny Awesome', auth_info: 'password',
|
||||
# # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# # xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'password' } } })
|
||||
# # response = epp_plain_request(xml, :xml, :registrar1)
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# # expect(response[:result_code]).to eq('1000')
|
||||
# # expect(response[:msg]).to eq('Command completed successfully')
|
||||
# # expect(contact.css('chkData postalInfo name').first).to eq(nil)
|
||||
# # end
|
||||
|
||||
# # it 'discloses items to owner' do
|
||||
# # @contact = Fabricate(:contact, registrar: registrar1, code: 'info-4444', name: 'Johnny Awesome',
|
||||
# # auth_info: 'password',
|
||||
# # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
|
||||
|
||||
# # xml = @epp_xml.info({ id: { value: @contact.code } })
|
||||
# # response = epp_plain_request(xml, :xml, :registrar1)
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# # expect(response[:result_code]).to eq('1000')
|
||||
# # expect(response[:msg]).to eq('Command completed successfully')
|
||||
# # expect(contact.css('name').first.text).to eq('Johnny Awesome')
|
||||
# # end
|
||||
|
||||
# # it 'doesn\'t disclose private elements' do
|
||||
# # Fabricate(:contact, code: 'info-4444', auth_info: '2fooBAR', registrar: registrar2,
|
||||
# # disclosure: Fabricate(:contact_disclosure, name: true, email: false, phone: false))
|
||||
|
||||
# # xml = @epp_xml.info({ id: { value: 'info-4444' }, authInfo: { pw: { value: '2fooBAR' } } })
|
||||
|
||||
# # response = epp_plain_request(xml, :xml, :registrar1)
|
||||
# # contact = response[:parsed].css('resData chkData')
|
||||
|
||||
# # expect(response[:result_code]).to eq('1000')
|
||||
|
||||
# # expect(contact.css('chkData phone')).to eq(contact.css('chkData disclose phone'))
|
||||
# # expect(contact.css('chkData phone').count).to eq(1)
|
||||
# # expect(contact.css('chkData email')).to eq(contact.css('chkData disclose email'))
|
||||
# # expect(contact.css('chkData email').count).to eq(1)
|
||||
# # expect(contact.css('postalInfo name').present?).to be(true)
|
||||
# # end
|
||||
# # end
|
||||
|
||||
# # it 'does not display unassociated object without password' do
|
||||
# # xml = @epp_xml.info(id: { value: @registrar1_contact.code })
|
||||
# # response = epp_plain_request(xml, :xml, :registrar2)
|
||||
# # expect(response[:result_code]).to eq('2003')
|
||||
# # expect(response[:msg]).to eq('Required parameter missing: pw')
|
||||
# # end
|
||||
|
||||
# # it 'does not display unassociated object with wrong password' do
|
||||
# # login_as :registrar2
|
||||
# # xml = @epp_xml.info(id: { value: @registrar1_contact.code },
|
||||
# # authInfo: { pw: { value: 'wrong-pw' } })
|
||||
# # response = epp_plain_request(xml, :xml)
|
||||
|
||||
# # response[:msg].should == 'Authentication error'
|
||||
# # response[:result_code].should == '2200'
|
||||
# # end
|
||||
# # end
|
||||
|
||||
# context 'renew command' do
|
||||
# it 'returns 2101-unimplemented command' do
|
||||
# response = epp_plain_request('contacts/renew.xml')
|
||||
|
||||
# response[:msg].should == 'Unimplemented command'
|
||||
# response[:result_code].should == '2101'
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# currently identity code generation not implemented,
|
||||
# currently identity code generation not implemented,
|
||||
# thus default user is FI for a while
|
||||
Fabricator(:user) do
|
||||
Fabricator(:admin_user) do
|
||||
username 'gitlab'
|
||||
password 'ghyt9e4fu'
|
||||
email 'info@gitlab.eu'
|
||||
|
@ -8,7 +8,7 @@ Fabricator(:user) do
|
|||
roles ['admin']
|
||||
end
|
||||
|
||||
Fabricator(:ee_user, from: :user) do
|
||||
Fabricator(:ee_user, from: :admin_user) do
|
||||
identity_code "45002036517"
|
||||
country_code 'EE'
|
||||
roles ['admin']
|
|
@ -1,7 +1,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
feature 'Setting management', type: :feature do
|
||||
let(:user) { Fabricate(:user, username: 'user1', identity_code: '37810013087') }
|
||||
let(:user) { Fabricate(:admin_user, username: 'user1', identity_code: '37810013087') }
|
||||
|
||||
background { create_settings }
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'rails_helper'
|
||||
require 'cancan/matchers'
|
||||
|
||||
describe User do
|
||||
describe AdminUser do
|
||||
context 'with invalid attribute' do
|
||||
before :all do
|
||||
@user = User.new
|
||||
@user = AdminUser.new
|
||||
end
|
||||
|
||||
it 'should not be valid' do
|
||||
|
@ -24,7 +24,7 @@ describe User do
|
|||
|
||||
context 'with valid attributes' do
|
||||
before :all do
|
||||
@user = Fabricate(:user)
|
||||
@user = Fabricate(:admin_user)
|
||||
end
|
||||
|
||||
it 'should be valid' do
|
||||
|
@ -33,7 +33,7 @@ describe User do
|
|||
end
|
||||
|
||||
# it 'should be valid twice' do
|
||||
# @user = Fabricate(:user)
|
||||
# @user = Fabricate(:admin_user)
|
||||
# @user.valid?
|
||||
# @user.errors.full_messages.should match_array([])
|
||||
# end
|
||||
|
@ -54,7 +54,7 @@ describe User do
|
|||
# let(:user) { nil }
|
||||
|
||||
# context 'when user is admin' do
|
||||
# let(:user) { Fabricate(:user) }
|
||||
# let(:user) { Fabricate(:admin_user) }
|
||||
|
||||
# it { should be_able_to(:manage, Domain.new) }
|
||||
# it { should be_able_to(:manage, Contact.new) }
|
|
@ -73,14 +73,14 @@ describe Domain do
|
|||
|
||||
it 'should return api_creator when created by api user' do
|
||||
with_versioning do
|
||||
@user = Fabricate(:user)
|
||||
@user = Fabricate(:admin_user)
|
||||
@api_user = Fabricate(:api_user)
|
||||
@user.id.should == 1
|
||||
@api_user.id.should == 1
|
||||
::PaperTrail.whodunnit = '1-api-testuser'
|
||||
@api_user.id.should == 2
|
||||
::PaperTrail.whodunnit = '2-api-testuser'
|
||||
|
||||
@domain = Fabricate(:domain)
|
||||
@domain.creator_str.should == '1-api-testuser'
|
||||
@domain.creator_str.should == '2-api-testuser'
|
||||
|
||||
@domain.creator.should == @api_user
|
||||
@domain.creator.should_not == @user
|
||||
|
@ -89,14 +89,14 @@ describe Domain do
|
|||
|
||||
it 'should return api_creator when created by api user' do
|
||||
with_versioning do
|
||||
@user = Fabricate(:user)
|
||||
@user = Fabricate(:admin_user)
|
||||
@api_user = Fabricate(:api_user)
|
||||
@user.id.should == 2
|
||||
@api_user.id.should == 2
|
||||
::PaperTrail.whodunnit = '2-testuser'
|
||||
@user.id.should == 3
|
||||
@api_user.id.should == 4
|
||||
::PaperTrail.whodunnit = '3-testuser'
|
||||
|
||||
@domain = Fabricate(:domain)
|
||||
@domain.creator_str.should == '2-testuser'
|
||||
@domain.creator_str.should == '3-testuser'
|
||||
|
||||
@domain.creator.should == @user
|
||||
@domain.creator.should_not == @api_user
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue