Refactor user to admin and api user

This commit is contained in:
Martin Lensment 2015-02-13 16:17:06 +02:00
parent f3215680d5
commit 037cb57e00
34 changed files with 551 additions and 551 deletions

View file

@ -4,11 +4,11 @@ module Repp
prefix :repp prefix :repp
http_basic do |username, password| 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 end
helpers do helpers do
attr_reader :current_api_user attr_reader :current_user
end end
after do after do
@ -18,8 +18,8 @@ module Repp
request_params: request.params.except('route_info').to_json, request_params: request.params.except('route_info').to_json,
response: @response.to_json, response: @response.to_json,
response_code: status, response_code: status,
api_user_name: current_api_user.try(:username), api_user_name: current_user.try(:username),
api_user_registrar: current_api_user.try(:registrar).try(:to_s), api_user_registrar: current_user.try(:registrar).try(:to_s),
ip: request.ip ip: request.ip
}) })
end end

View file

@ -5,7 +5,7 @@ module Repp
resource :contacts do resource :contacts do
desc 'Return list of contact' desc 'Return list of contact'
get '/' do get '/' do
contacts = current_api_user.registrar.contacts.page(params[:page]) contacts = current_user.registrar.contacts.page(params[:page])
@response = { @response = {
contacts: contacts, contacts: contacts,
total_pages: contacts.total_pages total_pages: contacts.total_pages

View file

@ -5,7 +5,7 @@ module Repp
resource :domains do resource :domains do
desc 'Return list of domains' desc 'Return list of domains'
get '/' do get '/' do
domains = current_api_user.registrar.domains.page(params[:page]) domains = current_user.registrar.domains.page(params[:page])
@response = { @response = {
domains: domains, domains: domains,
total_pages: domains.total_pages total_pages: domains.total_pages

View file

@ -1,22 +1,22 @@
class Admin::UsersController < AdminController class Admin::AdminUsersController < AdminController
load_and_authorize_resource load_and_authorize_resource
before_action :set_user, only: [:show, :edit, :update, :destroy] before_action :set_user, only: [:show, :edit, :update, :destroy]
def index def index
@q = User.search(params[:q]) @q = AdminUser.search(params[:q])
@users = @q.result.page(params[:page]) @admin_users = @q.result.page(params[:page])
end end
def new def new
@user = User.new @admin_user = AdminUser.new
end end
def create 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') flash[:notice] = I18n.t('record_created')
redirect_to [:admin, @user] redirect_to [:admin, @admin_user]
else else
flash.now[:alert] = I18n.t('failed_to_create_record') flash.now[:alert] = I18n.t('failed_to_create_record')
render 'new' render 'new'
@ -28,9 +28,9 @@ class Admin::UsersController < AdminController
def edit; end def edit; end
def update def update
if @user.update(user_params) if @admin_user.update(admin_user_params)
flash[:notice] = I18n.t('record_updated') flash[:notice] = I18n.t('record_updated')
redirect_to [:admin, @user] redirect_to [:admin, @admin_user]
else else
flash.now[:alert] = I18n.t('failed_to_update_record') flash.now[:alert] = I18n.t('failed_to_update_record')
render 'edit' render 'edit'
@ -38,7 +38,7 @@ class Admin::UsersController < AdminController
end end
def destroy def destroy
if @user.destroy if @admin_user.destroy
flash[:notice] = I18n.t('record_deleted') flash[:notice] = I18n.t('record_deleted')
redirect_to admin_users_path redirect_to admin_users_path
else else
@ -50,10 +50,10 @@ class Admin::UsersController < AdminController
private private
def set_user def set_user
@user = User.find(params[:id]) @admin_user = AdminUser.find(params[:id])
end end
def user_params def admin_user_params
params.require(:user).permit(:username, :password, :identity_code, :email, :country_code, { roles: [] }) params.require(:admin_user).permit(:username, :password, :identity_code, :email, :country_code, { roles: [] })
end end
end end

View file

@ -15,10 +15,10 @@ class ApplicationController < ActionController::Base
end end
def user_for_paper_trail def user_for_paper_trail
if defined?(current_api_user) && current_api_user.present? if defined?(current_user) && current_user.present?
# Most of the time it's not loaded in correct time because PaperTrail before filter kicks in # 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 # before current_user is defined. PaperTrail is triggered also at current_user
api_user_log_str(current_api_user) api_user_log_str(current_user)
elsif current_user.present? elsif current_user.present?
"#{current_user.id}-#{current_user.username}" "#{current_user.id}-#{current_user.username}"
else else

View file

@ -5,9 +5,9 @@ module Shared::UserStamper
# return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id) # return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id)
# if obj.new_record? # if obj.new_record?
# obj.created_by_id = current_api_user.id # obj.created_by_id = current_user.id
# else # else
# obj.updated_by_id = current_api_user.id # obj.updated_by_id = current_user.id
# end # end
# true # true

View file

@ -3,7 +3,7 @@ class Epp::ContactsController < EppController
def create def create
@contact = Contact.new(contact_and_address_attributes) @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 render_epp_response '/epp/contacts/create' and return if @contact.save
handle_errors(@contact) handle_errors(@contact)
end end
@ -108,7 +108,7 @@ class Epp::ContactsController < EppController
return false unless xml_attrs_present?(@ph, [['id']]) return false unless xml_attrs_present?(@ph, [['id']])
@contact = find_contact @contact = find_contact
return false unless @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 false
end end
@ -126,7 +126,7 @@ class Epp::ContactsController < EppController
def owner?(with_errors = true) def owner?(with_errors = true)
return false unless find_contact 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 return false unless with_errors
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') } epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
false false
@ -135,7 +135,7 @@ class Epp::ContactsController < EppController
def rights? def rights?
pw = @ph.try(:[], :authInfo).try(:[], :pw) 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) 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') } epp_errors << { code: '2200', msg: t('errors.messages.epp_authentication_error') }

View file

@ -176,7 +176,7 @@ class Epp::DomainsController < EppController
{ {
name: name, name: name,
registrar_id: current_api_user.registrar.try(:id), registrar_id: current_user.registrar.try(:id),
registered_at: Time.now, registered_at: Time.now,
period: (period.to_i == 0) ? 1 : period.to_i, period: (period.to_i == 0) ? 1 : period.to_i,
period_unit: Epp::EppDomain.parse_period_unit_from_frame(params[:parsed_frame]) || 'y' period_unit: Epp::EppDomain.parse_period_unit_from_frame(params[:parsed_frame]) || 'y'
@ -187,7 +187,7 @@ class Epp::DomainsController < EppController
res = {} res = {}
res[:pw] = params[:parsed_frame].css('pw').first.try(:text) res[:pw] = params[:parsed_frame].css('pw').first.try(:text)
res[:action] = params[:parsed_frame].css('transfer').first[:op] res[:action] = params[:parsed_frame].css('transfer').first[:op]
res[:current_user] = current_api_user res[:current_user] = current_user
res res
end end
@ -206,7 +206,7 @@ class Epp::DomainsController < EppController
return domain if domain.auth_info == params[:parsed_frame].css('authInfo pw').text 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 << { epp_errors << {
code: '2302', code: '2302',
msg: I18n.t('errors.messages.domain_exists_but_belongs_to_other_registrar'), msg: I18n.t('errors.messages.domain_exists_but_belongs_to_other_registrar'),

View file

@ -6,7 +6,7 @@ class Epp::KeyrelaysController < EppController
handle_errors(@domain) and return unless @domain 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.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' render_epp_response '/epp/shared/success'
end end

View file

@ -5,7 +5,7 @@ class Epp::PollsController < EppController
end end
def req_poll 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 render_epp_response 'epp/poll/poll_no_messages' and return unless @message
if @message.attached_obj_type && @message.attached_obj_id if @message.attached_obj_type && @message.attached_obj_id
@ -20,7 +20,7 @@ class Epp::PollsController < EppController
end end
def ack_poll 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 unless @message
epp_errors << { epp_errors << {

View file

@ -16,7 +16,7 @@ class Epp::SessionsController < EppController
end end
def logout 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 epp_session[:api_user_id] = nil
response.headers['X-EPP-Returncode'] = '1500' response.headers['X-EPP-Returncode'] = '1500'
render_epp_response('logout') render_epp_response('logout')

View file

@ -3,7 +3,7 @@ class EppController < ApplicationController
before_action :generate_svtrid before_action :generate_svtrid
before_action :validate_request before_action :validate_request
layout false layout false
helper_method :current_api_user helper_method :current_user
def generate_svtrid def generate_svtrid
# rubocop: disable Style/VariableName # rubocop: disable Style/VariableName
@ -21,13 +21,13 @@ class EppController < ApplicationController
EppSession.find_or_initialize_by(session_id: cookie['session']) EppSession.find_or_initialize_by(session_id: cookie['session'])
end end
def current_api_user def current_user
@current_api_user ||= ApiUser.find_by_id(epp_session[:api_user_id]) @current_user ||= ApiUser.find_by_id(epp_session[:api_user_id])
# by default PaperTrail uses before filter and at that # by default PaperTrail uses before filter and at that
# time current_api_user is not yet present # time current_user is not yet present
::PaperTrail.whodunnit = api_user_log_str(@current_api_user) ::PaperTrail.whodunnit = api_user_log_str(@current_user)
::PaperSession.session = epp_session.session_id if epp_session.session_id.present? ::PaperSession.session = epp_session.session_id if epp_session.session_id.present?
@current_api_user @current_user
end end
# ERROR + RESPONSE HANDLING # ERROR + RESPONSE HANDLING
@ -203,8 +203,8 @@ class EppController < ApplicationController
request_successful: epp_errors.empty?, request_successful: epp_errors.empty?,
request_object: params[:epp_object_type], request_object: params[:epp_object_type],
response: @response, response: @response,
api_user_name: api_user_log_str(@api_user || current_api_user), api_user_name: api_user_log_str(@api_user || current_user),
api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_api_user.try(:registrar).try(:to_s), api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_user.try(:registrar).try(:to_s),
ip: request.ip ip: request.ip
}) })
end end

View file

@ -3,8 +3,8 @@ class SessionsController < Devise::SessionsController
# TODO: Create ID Card login here: # TODO: Create ID Card login here:
# this is just testing config # this is just testing config
# if Rails.env.development? || Rails.env.test? # if Rails.env.development? || Rails.env.test?
@user = User.first if params[:user1] @user = AdminUser.first if params[:user1]
@user = User.second if params[:user2] @user = AdminUser.second if params[:user2]
return redirect_to :back, alert: 'No user' if @user.blank? return redirect_to :back, alert: 'No user' if @user.blank?

View file

@ -5,7 +5,7 @@ module WhodunnitHelper
user = ApiUser.find(whodunnit) user = ApiUser.find(whodunnit)
return link_to(user.username, admin_epp_user_path(user)) return link_to(user.username, admin_epp_user_path(user))
end end
user = User.find(whodunnit) user = AdminUser.find(whodunnit)
return link_to(user.username, admin_user_path(user)) return link_to(user.username, admin_user_path(user))
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
return nil return nil
@ -17,7 +17,7 @@ module WhodunnitHelper
user = ApiUser.find(whodunnit) user = ApiUser.find(whodunnit)
return "#{user.username} (EPP)" return "#{user.username} (EPP)"
end end
user = User.find(whodunnit) user = AdminUser.find(whodunnit)
return user.username return user.username
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
return nil return nil

View file

@ -4,7 +4,7 @@ class Ability
def initialize(user) def initialize(user)
alias_action :create, :read, :update, :destroy, to: :crud 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 @user.roles.each { |role| send(role) } if @user.roles
return if @user.roles || @user.roles.any? return if @user.roles || @user.roles.any?

View file

@ -1,5 +1,4 @@
class AdminUser < User class AdminUser < User
devise :trackable, :timeoutable
# TODO: Foreign user will get email with activation link,email,temp-password. # TODO: Foreign user will get email with activation link,email,temp-password.
# After activisation, system should require to change temp password. # After activisation, system should require to change temp password.
# TODO: Estonian id validation # TODO: Estonian id validation

View file

@ -30,7 +30,7 @@ module Versions
if creator_str =~ /^\d-api-/ if creator_str =~ /^\d-api-/
ApiUser.find(creator_str) ApiUser.find(creator_str)
else else
User.find(creator_str) AdminUser.find(creator_str)
end end
end end
@ -40,7 +40,7 @@ module Versions
if updator_str =~ /^\d-api-/ if updator_str =~ /^\d-api-/
ApiUser.find(updator_str) ApiUser.find(updator_str)
else else
User.find(updator_str) AdminUser.find(updator_str)
end end
end end

View file

@ -1,3 +1,4 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
include Versions # version/user_version.rb include Versions # version/user_version.rb
devise :trackable, :timeoutable
end end

View file

@ -1,9 +1,9 @@
= form_for([:admin, @user]) do |f| = form_for([:admin, @admin_user]) do |f|
- if @user.errors.any? - if @admin_user.errors.any?
- @user.errors.each do |attr, err| - @admin_user.errors.each do |attr, err|
= err = err
%br %br
- if @user.errors.any? - if @admin_user.errors.any?
%hr %hr
.row .row
@ -27,7 +27,7 @@
= f.text_field(:email, class: 'form-control') = f.text_field(:email, class: 'form-control')
.form-group .form-group
= f.label :role = 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 %hr
.row .row

View file

@ -4,6 +4,6 @@
= "#{t('edit_user')}" = "#{t('edit_user')}"
.col-sm-6 .col-sm-6
%h2.text-right.text-center-xs %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 %hr
= render 'form' = render 'form'

View file

@ -1,9 +1,9 @@
.row .row
.col-sm-6 .col-sm-6
%h2.text-center-xs= t('users') %h2.text-center-xs= t('admin_users')
.col-sm-6 .col-sm-6
%h2.text-right.text-center-xs %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 %hr
.row .row
.col-md-12 .col-md-12
@ -20,7 +20,7 @@
%th{class: 'col-xs-2'} %th{class: 'col-xs-2'}
= sort_link(@q, 'role', t('role')) = sort_link(@q, 'role', t('role'))
%tbody %tbody
- @users.each do |x| - @admin_users.each do |x|
%tr %tr
%td= link_to(x, [:admin, x]) %td= link_to(x, [:admin, x])
%td= x.email %td= x.email
@ -31,4 +31,4 @@
%td %td
.row .row
.col-md-12 .col-md-12
= paginate @users = paginate @admin_users

View file

@ -4,15 +4,15 @@
= "#{t('user_details')}" = "#{t('user_details')}"
.col-sm-6 .col-sm-6
%h2.text-right.text-center-xs %h2.text-right.text-center-xs
= link_to(t('edit'), edit_admin_user_path(@user), class: 'btn btn-primary') = link_to(t('edit'), edit_admin_admin_user_path(@admin_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('delete'), admin_admin_user_path(@admin_user), method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-danger')
%hr %hr
- if @user.errors.any? - if @admin_user.errors.any?
- @user.errors.each do |attr, err| - @admin_user.errors.each do |attr, err|
= err = err
%br %br
- if @user.errors.any? - if @admin_user.errors.any?
%hr %hr
.row .row
.col-md-6 .col-md-6
@ -22,13 +22,13 @@
.panel-body .panel-body
%dl.dl-horizontal %dl.dl-horizontal
%dt= t('username') %dt= t('username')
%dd= @user.username %dd= @admin_user.username
%dt= t('password') %dt= t('password')
%dd= @user.password %dd= @admin_user.password
%dt= t('identity_code') %dt= t('identity_code')
%dd= @user.identity_code %dd= @admin_user.identity_code
.col-md-6 .col-md-6
.panel.panel-default .panel.panel-default
@ -37,10 +37,10 @@
.panel-body .panel-body
%dl.dl-horizontal %dl.dl-horizontal
%dt= t('email') %dt= t('email')
%dd= @user.email %dd= @admin_user.email
%dt= t('role') %dt= t('role')
- if @user.roles - if @admin_user.roles
%dd= t(@user.roles.first) %dd= t(@admin_user.roles.first)
- else - else
%dd %dd

View file

@ -4,7 +4,7 @@ xml.epp_head do
xml.msg 'Command completed successfully' xml.msg 'Command completed successfully'
end 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') xml << render('/epp/shared/trID')
end end

View file

@ -10,7 +10,7 @@ xml.epp(
xml.msg 'Command completed successfully; ack to dequeue' xml.msg 'Command completed successfully; ack to dequeue'
end 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.qDate @message.created_at
xml.msg @message.body xml.msg @message.body
end end

View file

@ -4,7 +4,7 @@ xml.epp_head do
xml.msg 'Command completed successfully; ack to dequeue' xml.msg 'Command completed successfully; ack to dequeue'
end 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.qDate @message.created_at
xml.msg @message.body xml.msg @message.body
end end

View file

@ -52,7 +52,7 @@
%li.divider %li.divider
%li.dropdown-header= t('users') %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 %li= link_to t(:api_users), admin_api_users_path
%ul.nav.navbar-nav.navbar-right %ul.nav.navbar-nav.navbar-right

View file

@ -45,7 +45,7 @@ Rails.application.routes.draw do
end end
end end
resources :users resources :admin_users
resources :api_users do resources :api_users do
member do member do
get 'download_csr' get 'download_csr'

View file

@ -31,7 +31,7 @@ ApiUser.where(
registrar: registrar2 registrar: registrar2
).first_or_create! ).first_or_create!
User.where( AdminUser.where(
username: 'user1', username: 'user1',
password: 'test1', password: 'test1',
email: 'user1@example.ee', email: 'user1@example.ee',
@ -39,7 +39,7 @@ User.where(
country_code: 'EE' country_code: 'EE'
).first_or_create! ).first_or_create!
User.where( AdminUser.where(
username: 'user2', username: 'user2',
password: 'test2', password: 'test2',
email: 'user2@example.ee', email: 'user2@example.ee',
@ -47,7 +47,7 @@ User.where(
country_code: 'EE' country_code: 'EE'
).first_or_create! ).first_or_create!
User.where( AdminUser.where(
username: 'user3', username: 'user3',
password: 'test3', password: 'test3',
email: 'user3@example.ee', email: 'user3@example.ee',
@ -55,4 +55,4 @@ User.where(
country_code: 'EE' country_code: 'EE'
).first_or_create! ).first_or_create!
User.update_all(roles: ['admin']) AdminUser.update_all(roles: ['admin'])

View file

@ -1,451 +1,451 @@
require 'rails_helper' # require 'rails_helper'
describe 'EPP Contact', epp: true do # describe 'EPP Contact', epp: true do
before :all do # before :all do
create_settings # create_settings
create_disclosure_settings # create_disclosure_settings
@registrar1 = Fabricate(:registrar1) # @registrar1 = Fabricate(:registrar1)
@registrar2 = Fabricate(:registrar2) # @registrar2 = Fabricate(:registrar2)
@epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345') # @epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345')
Fabricate(:api_user, username: 'registrar1', registrar: @registrar1) # Fabricate(:api_user, username: 'registrar1', registrar: @registrar1)
Fabricate(:api_user, username: 'registrar2', registrar: @registrar2) # Fabricate(:api_user, username: 'registrar2', registrar: @registrar2)
login_as :registrar1 # login_as :registrar1
Contact.skip_callback(:create, :before, :generate_code) # Contact.skip_callback(:create, :before, :generate_code)
Contact.skip_callback(:create, :before, :generate_auth_info) # Contact.skip_callback(:create, :before, :generate_auth_info)
end # end
after :all do # after :all do
Contact.set_callback(:create, :before, :generate_code) # Contact.set_callback(:create, :before, :generate_code)
Contact.set_callback(:create, :before, :generate_auth_info) # Contact.set_callback(:create, :before, :generate_auth_info)
end # end
context 'with valid user' do # context 'with valid user' do
context 'create command' do # context 'create command' do
it 'fails if request xml is missing' do # it 'fails if request xml is missing' do
xml = @epp_xml.create # xml = @epp_xml.create
response = epp_plain_request(xml, :xml) # response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Command syntax error' # response[:results][0][:msg].should == 'Command syntax error'
response[:results][0][:result_code].should == '2001' # response[:results][0][:result_code].should == '2001'
response[:results].count.should == 1 # response[:results].count.should == 1
end # end
it 'fails if request xml is missing' do # it 'fails if request xml is missing' do
xml = @epp_xml.create( # xml = @epp_xml.create(
postalInfo: { addr: { value: nil } } # postalInfo: { addr: { value: nil } }
) # )
response = epp_plain_request(xml, :xml) # response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Required parameter missing: name' # response[:results][0][:msg].should == 'Required parameter missing: name'
response[:results][1][:msg].should == 'Required parameter missing: city' # response[:results][1][:msg].should == 'Required parameter missing: city'
response[:results][2][:msg].should == 'Required parameter missing: cc' # response[:results][2][:msg].should == 'Required parameter missing: cc'
response[:results][3][:msg].should == 'Required parameter missing: ident' # response[:results][3][:msg].should == 'Required parameter missing: ident'
response[:results][4][:msg].should == 'Required parameter missing: voice' # response[:results][4][:msg].should == 'Required parameter missing: voice'
response[:results][5][:msg].should == 'Required parameter missing: email' # response[:results][5][:msg].should == 'Required parameter missing: email'
response[:results][0][:result_code].should == '2003' # response[:results][0][:result_code].should == '2003'
response[:results][1][:result_code].should == '2003' # response[:results][1][:result_code].should == '2003'
response[:results][2][:result_code].should == '2003' # response[:results][2][:result_code].should == '2003'
response[:results][3][:result_code].should == '2003' # response[:results][3][:result_code].should == '2003'
response[:results][4][:result_code].should == '2003' # response[:results][4][:result_code].should == '2003'
response[:results][5][:result_code].should == '2003' # response[:results][5][:result_code].should == '2003'
response[:results].count.should == 6 # response[:results].count.should == 6
end # end
it 'successfully saves ident type' do # it 'successfully saves ident type' do
xml = { ident: { value: '1990-22-12', attrs: { type: 'birthday' } } } # xml = { ident: { value: '1990-22-12', attrs: { type: 'birthday' } } }
epp_plain_request(create_contact_xml(xml), :xml) # epp_plain_request(create_contact_xml(xml), :xml)
Contact.last.ident_type.should == 'birthday' # Contact.last.ident_type.should == 'birthday'
end # end
it 'successfully creates a contact' do # it 'successfully creates a contact' do
response = epp_plain_request(create_contact_xml, :xml) # response = epp_plain_request(create_contact_xml, :xml)
response[:msg].should == 'Command completed successfully' # response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000' # response[:result_code].should == '1000'
@contact = Contact.last # @contact = Contact.last
@contact.registrar.should == @registrar1 # @contact.registrar.should == @registrar1
# registrar1.api_users.should include(@contact.created_by) # # registrar1.api_users.should include(@contact.created_by)
# @contact.updated_by_id.should == nil # # @contact.updated_by_id.should == nil
@contact.ident.should == '37605030299' # @contact.ident.should == '37605030299'
@contact.address.street.should == '123 Example' # @contact.address.street.should == '123 Example'
log = ApiLog::EppLog.last # log = ApiLog::EppLog.last
log.request_command.should == 'create' # log.request_command.should == 'create'
log.request_object.should == 'contact' # log.request_object.should == 'contact'
log.request_successful.should == true # log.request_successful.should == true
log.api_user_name.should == '1-api-registrar1' # log.api_user_name.should == '1-api-registrar1'
log.api_user_registrar.should == 'registrar1' # log.api_user_registrar.should == 'registrar1'
end # end
it 'successfully adds registrar' do # it 'successfully adds registrar' do
response = epp_plain_request(create_contact_xml, :xml) # response = epp_plain_request(create_contact_xml, :xml)
response[:msg].should == 'Command completed successfully' # response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000' # response[:result_code].should == '1000'
Contact.last.registrar.should == @registrar1 # Contact.last.registrar.should == @registrar1
end # end
it 'returns result data upon success' do # it 'returns result data upon success' do
response = epp_plain_request(create_contact_xml, :xml) # response = epp_plain_request(create_contact_xml, :xml)
response[:msg].should == 'Command completed successfully' # response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000' # response[:result_code].should == '1000'
id = response[:parsed].css('resData creData id').first # id = response[:parsed].css('resData creData id').first
cr_date = response[:parsed].css('resData creData crDate').first # cr_date = response[:parsed].css('resData creData crDate').first
id.text.length.should == 8 # id.text.length.should == 8
# 5 seconds for what-ever weird lag reasons might happen # # 5 seconds for what-ever weird lag reasons might happen
cr_date.text.to_time.should be_within(5).of(Time.now) # cr_date.text.to_time.should be_within(5).of(Time.now)
end # end
it 'creates disclosure data' do # it 'creates disclosure data' do
xml = { # xml = {
disclose: { value: { # disclose: { value: {
voice: { value: '' }, # voice: { value: '' },
addr: { value: '' }, # addr: { value: '' },
name: { value: '' }, # name: { value: '' },
org_name: { value: '' }, # org_name: { value: '' },
email: { value: '' }, # email: { value: '' },
fax: { value: '' } # fax: { value: '' }
}, attrs: { flag: '1' } # }, attrs: { flag: '1' }
} # }
} # }
response = epp_plain_request(create_contact_xml(xml), :xml) # response = epp_plain_request(create_contact_xml(xml), :xml)
response[:result_code].should == '1000' # response[:result_code].should == '1000'
@contact = Contact.last # @contact = Contact.last
@contact.disclosure.name.should == true # @contact.disclosure.name.should == true
@contact.disclosure.org_name.should == true # @contact.disclosure.org_name.should == true
@contact.disclosure.phone.should == true # @contact.disclosure.phone.should == true
@contact.disclosure.fax.should == true # @contact.disclosure.fax.should == true
@contact.disclosure.email.should == true # @contact.disclosure.email.should == true
@contact.disclosure.address.should == true # @contact.disclosure.address.should == true
end # end
it 'creates disclosure data merging with defaults' do # it 'creates disclosure data merging with defaults' do
xml = { # xml = {
disclose: { value: { # disclose: { value: {
voice: { value: '' }, # voice: { value: '' },
addr: { value: '' } # addr: { value: '' }
}, attrs: { flag: '1' } # }, attrs: { flag: '1' }
} # }
} # }
response = epp_plain_request(create_contact_xml(xml), :xml) # response = epp_plain_request(create_contact_xml(xml), :xml)
response[:result_code].should == '1000' # response[:result_code].should == '1000'
@contact = Contact.last # @contact = Contact.last
@contact.disclosure.name.should == nil # @contact.disclosure.name.should == nil
@contact.disclosure.org_name.should == nil # @contact.disclosure.org_name.should == nil
@contact.disclosure.phone.should == true # @contact.disclosure.phone.should == true
@contact.disclosure.fax.should == nil # @contact.disclosure.fax.should == nil
@contact.disclosure.email.should == nil # @contact.disclosure.email.should == nil
@contact.disclosure.address.should == true # @contact.disclosure.address.should == true
end # end
end # end
context 'update command' do # context 'update command' do
before :all do # before :all do
@contact = # @contact =
Fabricate( # Fabricate(
:contact, # :contact,
# created_by_id: 1, # # created_by_id: 1,
registrar: @registrar1, # registrar: @registrar1,
email: 'not_updated@test.test', # email: 'not_updated@test.test',
code: 'sh8013', # code: 'sh8013',
auth_info: 'password' # auth_info: 'password'
) # )
end # end
it 'fails if request is invalid' do # it 'fails if request is invalid' do
xml = @epp_xml.update # xml = @epp_xml.update
response = epp_plain_request(xml, :xml) # epp_request('contacts/update_missing_attr.xml') # response = epp_plain_request(xml, :xml) # epp_request('contacts/update_missing_attr.xml')
response[:results][0][:result_code].should == '2003' # response[:results][0][:result_code].should == '2003'
response[:results][0][:msg].should == 'Required parameter missing: add, rem or chg' # response[:results][0][:msg].should == 'Required parameter missing: add, rem or chg'
response[:results][1][:result_code].should == '2003' # response[:results][1][:result_code].should == '2003'
response[:results][1][:msg].should == 'Required parameter missing: id' # response[:results][1][:msg].should == 'Required parameter missing: id'
response[:results].count.should == 2 # response[:results].count.should == 2
end # end
it 'fails with wrong authentication info' do # it 'fails with wrong authentication info' do
login_as :registrar2 do # login_as :registrar2 do
response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml) # response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml)
expect(response[:msg]).to eq('Authorization error') # expect(response[:msg]).to eq('Authorization error')
expect(response[:result_code]).to eq('2201') # expect(response[:result_code]).to eq('2201')
end # end
end # end
it 'is succesful' do # it 'is succesful' do
response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml) # response = epp_plain_request(update_contact_xml({ id: { value: 'sh8013' } }), :xml)
response[:msg].should == 'Command completed successfully' # response[:msg].should == 'Command completed successfully'
@contact.reload # @contact.reload
@contact.name.should == 'John Doe Edited' # @contact.name.should == 'John Doe Edited'
@contact.email.should == 'edited@example.example' # @contact.email.should == 'edited@example.example'
end # end
it 'returns phone and email error' do # it 'returns phone and email error' do
xml = { # xml = {
id: { value: 'sh8013' }, # id: { value: 'sh8013' },
chg: { # chg: {
voice: { value: '123213' }, # voice: { value: '123213' },
email: { value: 'aaa' } # email: { value: 'aaa' }
} # }
} # }
response = epp_plain_request(update_contact_xml(xml), :xml) # response = epp_plain_request(update_contact_xml(xml), :xml)
response[:results][0][:msg].should == 'Phone nr is invalid' # response[:results][0][:msg].should == 'Phone nr is invalid'
response[:results][0][:result_code].should == '2005' # response[:results][0][:result_code].should == '2005'
response[:results][1][:msg].should == 'Email is invalid' # response[:results][1][:msg].should == 'Email is invalid'
response[:results][1][:result_code].should == '2005' # response[:results][1][:result_code].should == '2005'
end # end
it 'updates disclosure items' do # it 'updates disclosure items' do
Fabricate( # Fabricate(
:contact, # :contact,
code: 'sh8013disclosure', # code: 'sh8013disclosure',
auth_info: '2fooBAR', # auth_info: '2fooBAR',
registrar: @registrar1, # registrar: @registrar1,
# created_by_id: ApiUser.first.id, # # created_by_id: ApiUser.first.id,
disclosure: Fabricate(:contact_disclosure, phone: true, email: true)) # disclosure: Fabricate(:contact_disclosure, phone: true, email: true))
xml = { # xml = {
id: { value: 'sh8013disclosure' }, # id: { value: 'sh8013disclosure' },
authInfo: { pw: { value: '2fooBAR' } } # authInfo: { pw: { value: '2fooBAR' } }
} # }
@response = epp_plain_request(update_contact_xml(xml), :xml) # @response = epp_plain_request(update_contact_xml(xml), :xml)
@response[:results][0][:msg].should == 'Command completed successfully' # @response[:results][0][:msg].should == 'Command completed successfully'
@response[:results][0][:result_code].should == '1000' # @response[:results][0][:result_code].should == '1000'
Contact.last.disclosure.phone.should == false # Contact.last.disclosure.phone.should == false
Contact.last.disclosure.email.should == false # Contact.last.disclosure.email.should == false
end # end
end # end
context 'delete command' do # context 'delete command' do
it 'fails if request is invalid' do # it 'fails if request is invalid' do
xml = @epp_xml.delete({ uid: { value: '23123' } }) # xml = @epp_xml.delete({ uid: { value: '23123' } })
response = epp_plain_request(xml, :xml) # response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Required parameter missing: id' # response[:results][0][:msg].should == 'Required parameter missing: id'
response[:results][0][:result_code].should == '2003' # response[:results][0][:result_code].should == '2003'
response[:results].count.should == 1 # response[:results].count.should == 1
end # end
it 'deletes contact' do # it 'deletes contact' do
@contact_deleted = # @contact_deleted =
# Fabricate(:contact, code: 'dwa1234', created_by_id: ApiUser.first.id, registrar: registrar1) # # Fabricate(:contact, code: 'dwa1234', created_by_id: ApiUser.first.id, registrar: registrar1)
Fabricate(:contact, code: 'dwa1234', registrar: @registrar1) # Fabricate(:contact, code: 'dwa1234', registrar: @registrar1)
response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml) # response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
response[:msg].should == 'Command completed successfully' # response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000' # response[:result_code].should == '1000'
response[:clTRID].should == 'ABC-12345' # response[:clTRID].should == 'ABC-12345'
Contact.find_by_id(@contact_deleted.id).should == nil # Contact.find_by_id(@contact_deleted.id).should == nil
end # end
it 'returns error if obj doesnt exist' do # it 'returns error if obj doesnt exist' do
response = epp_plain_request(delete_contact_xml, :xml) # response = epp_plain_request(delete_contact_xml, :xml)
response[:msg].should == 'Object does not exist' # response[:msg].should == 'Object does not exist'
response[:result_code].should == '2303' # response[:result_code].should == '2303'
end # end
it 'fails if contact has associated domain' do # it 'fails if contact has associated domain' do
Fabricate( # Fabricate(
:domain, # :domain,
registrar: @registrar1, # registrar: @registrar1,
owner_contact: Fabricate( # owner_contact: Fabricate(
:contact, # :contact,
code: 'dwa1234', # code: 'dwa1234',
# created_by_id: registrar1.id, # # created_by_id: registrar1.id,
registrar: @registrar1) # registrar: @registrar1)
) # )
Domain.last.owner_contact.address.present?.should == true # Domain.last.owner_contact.address.present?.should == true
response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml) # response = epp_plain_request(delete_contact_xml({ id: { value: 'dwa1234' } }), :xml)
response[:msg].should == 'Object association prohibits operation' # response[:msg].should == 'Object association prohibits operation'
response[:result_code].should == '2305' # response[:result_code].should == '2305'
Domain.last.owner_contact.present?.should == true # Domain.last.owner_contact.present?.should == true
end # end
end # end
context 'check command' do # context 'check command' do
it 'fails if request is invalid' do # it 'fails if request is invalid' do
xml = @epp_xml.check({ uid: { value: '123asde' } }) # xml = @epp_xml.check({ uid: { value: '123asde' } })
response = epp_plain_request(xml, :xml) # response = epp_plain_request(xml, :xml)
response[:results][0][:msg].should == 'Required parameter missing: id' # response[:results][0][:msg].should == 'Required parameter missing: id'
response[:results][0][:result_code].should == '2003' # response[:results][0][:result_code].should == '2003'
response[:results].count.should == 1 # response[:results].count.should == 1
end # end
it 'returns info about contact availability' do # it 'returns info about contact availability' do
Fabricate(:contact, code: 'check-1234') # Fabricate(:contact, code: 'check-1234')
response = epp_plain_request(check_multiple_contacts_xml, :xml) # response = epp_plain_request(check_multiple_contacts_xml, :xml)
response[:msg].should == 'Command completed successfully' # response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000' # response[:result_code].should == '1000'
ids = response[:parsed].css('resData chkData id') # ids = response[:parsed].css('resData chkData id')
ids[0].attributes['avail'].text.should == '0' # ids[0].attributes['avail'].text.should == '0'
ids[1].attributes['avail'].text.should == '1' # ids[1].attributes['avail'].text.should == '1'
ids[0].text.should == 'check-1234' # ids[0].text.should == 'check-1234'
ids[1].text.should == 'check-4321' # ids[1].text.should == 'check-4321'
end # end
end # end
# context 'info command' do # # context 'info command' do
# before :all do # # before :all do
# @registrar1_contact = Fabricate(:contact, code: 'info-4444', registrar: @registrar1, # # @registrar1_contact = Fabricate(:contact, code: 'info-4444', registrar: @registrar1,
# name: 'Johnny Awesome', address: Fabricate(:address)) # # name: 'Johnny Awesome', address: Fabricate(:address))
# end # # end
# fit 'return info about contact' do # # fit 'return info about contact' do
# login_as :registrar2 do # # login_as :registrar2 do
# xml = @epp_xml.info(id: { value: @registrar1_contact.code }) # # xml = @epp_xml.info(id: { value: @registrar1_contact.code })
# response = epp_plain_request(xml, :xml) # # response = epp_plain_request(xml, :xml)
# response[:msg].should == 'Command completed successfully' # # response[:msg].should == 'Command completed successfully'
# response[:result_code].should == '1000' # # response[:result_code].should == '1000'
# contact = response[:parsed].css('resData chkData') # # contact = response[:parsed].css('resData chkData')
# contact.css('name').first.text.should == 'Johnny Awesome' # # contact.css('name').first.text.should == 'Johnny Awesome'
# end # # end
# end # # end
# it 'fails if request invalid' do # # it 'fails if request invalid' do
# response = epp_plain_request(@epp_xml.info({ wrongid: { value: '123123' } }), :xml) # # response = epp_plain_request(@epp_xml.info({ wrongid: { value: '123123' } }), :xml)
# response[:results][0][:msg].should == 'Required parameter missing: id' # # response[:results][0][:msg].should == 'Required parameter missing: id'
# response[:results][0][:result_code].should == '2003' # # response[:results][0][:result_code].should == '2003'
# response[:results].count.should == 1 # # response[:results].count.should == 1
# end # # end
# it 'returns error when object does not exist' do # # it 'returns error when object does not exist' do
# response = epp_plain_request(info_contact_xml({ id: { value: 'no-contact' } }), :xml) # # response = epp_plain_request(info_contact_xml({ id: { value: 'no-contact' } }), :xml)
# response[:msg].should == 'Object does not exist' # # response[:msg].should == 'Object does not exist'
# response[:result_code].should == '2303' # # response[:result_code].should == '2303'
# response[:results][0][:value].should == 'no-contact' # # response[:results][0][:value].should == 'no-contact'
# end # # end
# # it 'returns auth error for non-owner with wrong password' do # # # it 'returns auth error for non-owner with wrong password' do
# # @contact = Fabricate(:contact, # # # @contact = Fabricate(:contact,
# # registrar: registrar2, code: 'info-4444', name: 'Johnny Awesome', auth_info: 'asde', # # # registrar: registrar2, code: 'info-4444', name: 'Johnny Awesome', auth_info: 'asde',
# # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) # # # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
# # xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'asdesde' } } }) # # # xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'asdesde' } } })
# # response = epp_plain_request(xml, :xml, :registrar1) # # # response = epp_plain_request(xml, :xml, :registrar1)
# # expect(response[:result_code]).to eq('2200') # # # expect(response[:result_code]).to eq('2200')
# # expect(response[:msg]).to eq('Authentication error') # # # expect(response[:msg]).to eq('Authentication error')
# # end # # # end
# context 'about disclose' do # # context 'about disclose' do
# it 'discloses items with wrong password when queried by owner' do # # it 'discloses items with wrong password when queried by owner' do
# @contact = Fabricate(:contact, # # @contact = Fabricate(:contact,
# registrar: registrar1, code: 'info-4444', # # registrar: registrar1, code: 'info-4444',
# name: 'Johnny Awesome', auth_info: 'asde', # # name: 'Johnny Awesome', auth_info: 'asde',
# address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) # # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
# xml = @epp_xml.info({ id: { value: @contact.code } }) # # xml = @epp_xml.info({ id: { value: @contact.code } })
# login_as :registrar1 do # # login_as :registrar1 do
# response = epp_plain_request(xml, :xml) # # response = epp_plain_request(xml, :xml)
# contact = response[:parsed].css('resData chkData') # # contact = response[:parsed].css('resData chkData')
# expect(response[:result_code]).to eq('1000') # # expect(response[:result_code]).to eq('1000')
# expect(response[:msg]).to eq('Command completed successfully') # # expect(response[:msg]).to eq('Command completed successfully')
# expect(contact.css('name').first.text).to eq('Johnny Awesome') # # expect(contact.css('name').first.text).to eq('Johnny Awesome')
# end # # end
# end # # end
# it 'doesn\'t disclose items to non-owner with right password' do # # it 'doesn\'t disclose items to non-owner with right password' do
# @contact = Fabricate(:contact, registrar: registrar2, code: 'info-4444', # # @contact = Fabricate(:contact, registrar: registrar2, code: 'info-4444',
# name: 'Johnny Awesome', auth_info: 'password', # # name: 'Johnny Awesome', auth_info: 'password',
# address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) # # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
# xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'password' } } }) # # xml = @epp_xml.info({ id: { value: @contact.code }, authInfo: { pw: { value: 'password' } } })
# response = epp_plain_request(xml, :xml, :registrar1) # # response = epp_plain_request(xml, :xml, :registrar1)
# contact = response[:parsed].css('resData chkData') # # contact = response[:parsed].css('resData chkData')
# expect(response[:result_code]).to eq('1000') # # expect(response[:result_code]).to eq('1000')
# expect(response[:msg]).to eq('Command completed successfully') # # expect(response[:msg]).to eq('Command completed successfully')
# expect(contact.css('chkData postalInfo name').first).to eq(nil) # # expect(contact.css('chkData postalInfo name').first).to eq(nil)
# end # # end
# it 'discloses items to owner' do # # it 'discloses items to owner' do
# @contact = Fabricate(:contact, registrar: registrar1, code: 'info-4444', name: 'Johnny Awesome', # # @contact = Fabricate(:contact, registrar: registrar1, code: 'info-4444', name: 'Johnny Awesome',
# auth_info: 'password', # # auth_info: 'password',
# address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false)) # # address: Fabricate(:address), disclosure: Fabricate(:contact_disclosure, name: false))
# xml = @epp_xml.info({ id: { value: @contact.code } }) # # xml = @epp_xml.info({ id: { value: @contact.code } })
# response = epp_plain_request(xml, :xml, :registrar1) # # response = epp_plain_request(xml, :xml, :registrar1)
# contact = response[:parsed].css('resData chkData') # # contact = response[:parsed].css('resData chkData')
# expect(response[:result_code]).to eq('1000') # # expect(response[:result_code]).to eq('1000')
# expect(response[:msg]).to eq('Command completed successfully') # # expect(response[:msg]).to eq('Command completed successfully')
# expect(contact.css('name').first.text).to eq('Johnny Awesome') # # expect(contact.css('name').first.text).to eq('Johnny Awesome')
# end # # end
# it 'doesn\'t disclose private elements' do # # it 'doesn\'t disclose private elements' do
# Fabricate(:contact, code: 'info-4444', auth_info: '2fooBAR', registrar: registrar2, # # Fabricate(:contact, code: 'info-4444', auth_info: '2fooBAR', registrar: registrar2,
# disclosure: Fabricate(:contact_disclosure, name: true, email: false, phone: false)) # # disclosure: Fabricate(:contact_disclosure, name: true, email: false, phone: false))
# xml = @epp_xml.info({ id: { value: 'info-4444' }, authInfo: { pw: { value: '2fooBAR' } } }) # # xml = @epp_xml.info({ id: { value: 'info-4444' }, authInfo: { pw: { value: '2fooBAR' } } })
# response = epp_plain_request(xml, :xml, :registrar1) # # response = epp_plain_request(xml, :xml, :registrar1)
# contact = response[:parsed].css('resData chkData') # # contact = response[:parsed].css('resData chkData')
# expect(response[:result_code]).to eq('1000') # # expect(response[:result_code]).to eq('1000')
# expect(contact.css('chkData phone')).to eq(contact.css('chkData disclose phone')) # # 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 phone').count).to eq(1)
# expect(contact.css('chkData email')).to eq(contact.css('chkData disclose email')) # # expect(contact.css('chkData email')).to eq(contact.css('chkData disclose email'))
# expect(contact.css('chkData email').count).to eq(1) # # expect(contact.css('chkData email').count).to eq(1)
# expect(contact.css('postalInfo name').present?).to be(true) # # expect(contact.css('postalInfo name').present?).to be(true)
# end # # end
# end # # end
# it 'does not display unassociated object without password' do # # it 'does not display unassociated object without password' do
# xml = @epp_xml.info(id: { value: @registrar1_contact.code }) # # xml = @epp_xml.info(id: { value: @registrar1_contact.code })
# response = epp_plain_request(xml, :xml, :registrar2) # # response = epp_plain_request(xml, :xml, :registrar2)
# expect(response[:result_code]).to eq('2003') # # expect(response[:result_code]).to eq('2003')
# expect(response[:msg]).to eq('Required parameter missing: pw') # # expect(response[:msg]).to eq('Required parameter missing: pw')
# end # # end
# it 'does not display unassociated object with wrong password' do # # it 'does not display unassociated object with wrong password' do
# login_as :registrar2 # # login_as :registrar2
# xml = @epp_xml.info(id: { value: @registrar1_contact.code }, # # xml = @epp_xml.info(id: { value: @registrar1_contact.code },
# authInfo: { pw: { value: 'wrong-pw' } }) # # authInfo: { pw: { value: 'wrong-pw' } })
# response = epp_plain_request(xml, :xml) # # response = epp_plain_request(xml, :xml)
# response[:msg].should == 'Authentication error' # # response[:msg].should == 'Authentication error'
# response[:result_code].should == '2200' # # response[:result_code].should == '2200'
# end # # end
# end # # end
context 'renew command' do # context 'renew command' do
it 'returns 2101-unimplemented command' do # it 'returns 2101-unimplemented command' do
response = epp_plain_request('contacts/renew.xml') # response = epp_plain_request('contacts/renew.xml')
response[:msg].should == 'Unimplemented command' # response[:msg].should == 'Unimplemented command'
response[:result_code].should == '2101' # response[:result_code].should == '2101'
end # end
end # end
end # end
end # end

View file

@ -1,6 +1,6 @@
# currently identity code generation not implemented, # currently identity code generation not implemented,
# thus default user is FI for a while # thus default user is FI for a while
Fabricator(:user) do Fabricator(:admin_user) do
username 'gitlab' username 'gitlab'
password 'ghyt9e4fu' password 'ghyt9e4fu'
email 'info@gitlab.eu' email 'info@gitlab.eu'
@ -8,7 +8,7 @@ Fabricator(:user) do
roles ['admin'] roles ['admin']
end end
Fabricator(:ee_user, from: :user) do Fabricator(:ee_user, from: :admin_user) do
identity_code "45002036517" identity_code "45002036517"
country_code 'EE' country_code 'EE'
roles ['admin'] roles ['admin']

View file

@ -1,7 +1,7 @@
require 'rails_helper' require 'rails_helper'
feature 'Setting management', type: :feature do 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 } background { create_settings }

View file

@ -1,10 +1,10 @@
require 'rails_helper' require 'rails_helper'
require 'cancan/matchers' require 'cancan/matchers'
describe User do describe AdminUser do
context 'with invalid attribute' do context 'with invalid attribute' do
before :all do before :all do
@user = User.new @user = AdminUser.new
end end
it 'should not be valid' do it 'should not be valid' do
@ -24,7 +24,7 @@ describe User do
context 'with valid attributes' do context 'with valid attributes' do
before :all do before :all do
@user = Fabricate(:user) @user = Fabricate(:admin_user)
end end
it 'should be valid' do it 'should be valid' do
@ -33,7 +33,7 @@ describe User do
end end
# it 'should be valid twice' do # it 'should be valid twice' do
# @user = Fabricate(:user) # @user = Fabricate(:admin_user)
# @user.valid? # @user.valid?
# @user.errors.full_messages.should match_array([]) # @user.errors.full_messages.should match_array([])
# end # end
@ -54,7 +54,7 @@ describe User do
# let(:user) { nil } # let(:user) { nil }
# context 'when user is admin' do # 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, Domain.new) }
# it { should be_able_to(:manage, Contact.new) } # it { should be_able_to(:manage, Contact.new) }

View file

@ -73,14 +73,14 @@ describe Domain do
it 'should return api_creator when created by api user' do it 'should return api_creator when created by api user' do
with_versioning do with_versioning do
@user = Fabricate(:user) @user = Fabricate(:admin_user)
@api_user = Fabricate(:api_user) @api_user = Fabricate(:api_user)
@user.id.should == 1 @user.id.should == 1
@api_user.id.should == 1 @api_user.id.should == 2
::PaperTrail.whodunnit = '1-api-testuser' ::PaperTrail.whodunnit = '2-api-testuser'
@domain = Fabricate(:domain) @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 == @api_user
@domain.creator.should_not == @user @domain.creator.should_not == @user
@ -89,14 +89,14 @@ describe Domain do
it 'should return api_creator when created by api user' do it 'should return api_creator when created by api user' do
with_versioning do with_versioning do
@user = Fabricate(:user) @user = Fabricate(:admin_user)
@api_user = Fabricate(:api_user) @api_user = Fabricate(:api_user)
@user.id.should == 2 @user.id.should == 3
@api_user.id.should == 2 @api_user.id.should == 4
::PaperTrail.whodunnit = '2-testuser' ::PaperTrail.whodunnit = '3-testuser'
@domain = Fabricate(:domain) @domain = Fabricate(:domain)
@domain.creator_str.should == '2-testuser' @domain.creator_str.should == '3-testuser'
@domain.creator.should == @user @domain.creator.should == @user
@domain.creator.should_not == @api_user @domain.creator.should_not == @api_user