internetee-registry/test/integration/epp/login/credentials_test.rb
Maciej Szlosarczyk 526a9ccd58
Change test structure to follow closer newer Rails 5 rules
* Create new class called ApplicationIntegrationTest, so we don't have
  to override ActionDispatch::IntegrationTest
* Move UI tests to inherit from ApplicationSystemTestCase
* Existing REST API or EPP tests inherit from
  ApplicationIntegrationTest.
* Move `require 'application_system_test_case'` at the end of
  `test_helper`

I don't particularly agree with the Rails' convention of treating UI
tests as system tests and API tests as integration tests, but I see no
benefit in actively fighting against it.
2018-07-27 09:36:27 +03:00

64 lines
2.2 KiB
Ruby

require 'test_helper'
class EppLoginCredentialsTest < ApplicationIntegrationTest
def test_correct_credentials
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<login>
<clID>test_bestnames</clID>
<pw>testtest</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:keyrelay-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' }
assert EppSession.find_by(session_id: 'new_session_id')
assert_equal users(:api_bestnames), EppSession.find_by(session_id: 'new_session_id').user
assert Nokogiri::XML(response.body).at_css('result[code="1000"]')
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end
def test_already_logged_in
assert true # Handled by mod_epp
end
def test_wrong_credentials
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<login>
<clID>non-existent</clID>
<pw>valid-but-wrong</pw>
<options>
<version>1.0</version>
<lang>en</lang>
</options>
<svcs>
<objURI>https://epp.tld.ee/schema/domain-eis-1.0.xsd</objURI>
<objURI>https://epp.tld.ee/schema/contact-ee-1.1.xsd</objURI>
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
<objURI>urn:ietf:params:xml:ns:keyrelay-1.0</objURI>
</svcs>
</login>
</command>
</epp>
XML
post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=any_random_string' }
assert Nokogiri::XML(response.body).at_css('result[code="2501"]')
end
end