Changeset - 38dda6c8a969
[Not reviewed]
0 2 0
Branko Majic (branko) - 6 years ago 2017-11-25 20:40:40
branko@majic.rs
MAR-128: Fixed test for login mechanisms on backup_server role:

- Moved test back into test_default.py to be run against all servers.
- Switch to using local ssh command that would reveal available
mechanisms instead of using paramiko from the test host.
2 files changed with 12 insertions and 23 deletions:
0 comments (0 inline, 0 general)
roles/backup_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -159,3 +159,15 @@ def test_backup_ssh_server_service(host):
 
        assert service.is_running
 
        assert service.is_enabled
 
        assert host.socket('tcp://0.0.0.0:2222').is_listening
 

	
 

	
 
def test_backup_ssh_server_login_mechanisms(host):
 
    """
 
    Tests available SSH login mechanisms (should be just public key).
 
    """
 

	
 
    # Try to login with no preferred authentication types to the server.
 
    login_attempt = host.run("ssh -v -o PreferredAuthentications=none -o NoHostAuthenticationForLocalhost=yes localhost")
 

	
 
    assert login_attempt.rc == 255
 
    assert "debug1: Authentications that can continue: publickey" in login_attempt.stderr.split("\r\n")
roles/backup_server/molecule/default/tests/test_parameters_optional.py
Show inline comments
 
import os
 
import socket
 

	
 
import paramiko
 

	
 
import testinfra.utils.ansible_runner
 

	
 
@@ -226,23 +223,3 @@ def test_backup_ssh_service_key_fingerprints(host):
 
                                  "bak-client1_backup@%s /bin/echo sshtest" % (key_type, remote_ip))
 
        assert login_attempt.rc == 1
 
        assert "This service allows sftp connections only." in login_attempt.stdout
 

	
 

	
 
def test_backup_ssh_server_login_mechanisms(host):
 
    """
 
    Tests available SSH login mechanisms (should be just public key).
 
    """
 

	
 
    # Extract first non-IPv6 IP. Crude test, but it should work.
 
    remote_ip = next(a for a in host.interface("eth1").addresses if ":" not in a)
 

	
 
    sock = socket.socket()
 
    sock.connect((remote_ip, 2222))
 

	
 
    transport = paramiko.transport.Transport(sock)
 
    transport.connect()
 

	
 
    try:
 
        transport.auth_none('')
 
    except paramiko.transport.BadAuthenticationType, err:
 
        assert err.allowed_types == ['publickey']
0 comments (0 inline, 0 general)