Skip to content

Commit

Permalink
Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Beljajev authored and yulgolem committed Sep 3, 2020
1 parent 18ff9c4 commit bace52f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/models/epp_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class EppSession < ApplicationRecord
class_attribute :timeout
self.timeout = (ENV['epp_session_timeout_seconds'] || 300).to_i.seconds

class_attribute :limit_per_registrar
self.limit_per_registrar = (ENV['epp_session_limit_per_registrar'] || 4).to_i
class_attribute :sessions_per_registrar
self.sessions_per_registrar = (ENV['epp_session_limit_per_registrar'] || 4).to_i

alias_attribute :last_access, :updated_at

def self.limit_reached?(registrar)
count = where(user_id: registrar.api_users.ids).count
count >= limit_per_registrar
count >= sessions_per_registrar
end

def self.expired
Expand Down
2 changes: 1 addition & 1 deletion config/application.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ lhv_dev_mode: 'false'

epp_session_timeout_seconds: '300'

epp_session_limit_per_registrar: '4'
epp_sessions_per_registrar: '4'

# Since the keys for staging are absent from the repo, we need to supply them separate for testing.
test:
Expand Down
8 changes: 4 additions & 4 deletions test/integration/epp/login_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

class EppLoginTest < EppTestCase
setup do
@original_session_limit_per_registrar = EppSession.limit_per_registrar
@original_sessions_per_registrar_setting = EppSession.sessions_per_registrar
end

teardown do
EppSession.limit_per_registrar = @original_session_limit_per_registrar
EppSession.sessions_per_registrar = @original_sessions_per_registrar_setting
end

def test_logging_in_with_correct_credentials_creates_new_session
Expand Down Expand Up @@ -142,10 +142,10 @@ def test_password_change
assert_equal new_password, user.plain_text_password
end

def test_user_cannot_login_when_session_limit_is_exceeded
def test_user_cannot_login_when_max_allowed_sessions_per_registrar_is_exceeded
user = users(:api_bestnames)
eliminate_effect_of_existing_epp_sessions
EppSession.limit_per_registrar = 1
EppSession.sessions_per_registrar = 1
EppSession.create!(session_id: 'any', user: user)

request_xml = <<-XML
Expand Down

0 comments on commit bace52f

Please sign in to comment.