Changeset - b35918db4b2d
[Not reviewed]
0 11 0
Branko Majic (branko) - 4 years ago 2020-01-06 18:10:31
branko@majic.rs
MAR-148: Fixed tests for the backup_server role:

- Fix some handling of newlines by updating test data keys to include
newline at the end of file.
- Ensure we do not produce exit code 255 when testing the available
authentication mechanisms for the backup SSH server
instance (otherwise we get runtime exception from Testinfra itself).
- Fix some handling of newlines by not doing stripping and including
newline in expected output.
11 files changed with 23 insertions and 15 deletions:
0 comments (0 inline, 0 general)
roles/backup_server/molecule/default/tests/data/ssh/client1
Show inline comments
 
@@ -2,4 +2,4 @@
 
MHcCAQEEINHLWDWSpuuGgHT5cGpzkPMdnmT493/zqrBSyMOGPPrqoAoGCCqGSM49
 
AwEHoUQDQgAE1gEshzmIJDC93lAg7kdjUWeFrI8I26Mvi7IAM37SBfU2a08KMDWR
 
QvLygMvp6rixo4QRpkUp5lDcl24fybh6xQ==
 
-----END EC PRIVATE KEY-----
 
\ No newline at end of file
 
-----END EC PRIVATE KEY-----
roles/backup_server/molecule/default/tests/data/ssh/client1.pub
Show inline comments
 
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNYBLIc5iCQwvd5QIO5HY1FnhayPCNujL4uyADN+0gX1NmtPCjA1kULy8oDL6eq4saOEEaZFKeZQ3JduH8m4esU= user@client1
 
\ No newline at end of file
 
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNYBLIc5iCQwvd5QIO5HY1FnhayPCNujL4uyADN+0gX1NmtPCjA1kULy8oDL6eq4saOEEaZFKeZQ3JduH8m4esU= user@client1
roles/backup_server/molecule/default/tests/data/ssh/client2
Show inline comments
 
@@ -2,4 +2,4 @@
 
MHcCAQEEICwzh3hupZa3aKFWFwdRosm8kXS6czUWw/sHIvgKWNEcoAoGCCqGSM49
 
AwEHoUQDQgAEPh00CkvI6wEACjGfETwsP1RwyekgFsiQl7IvuJ4Nc20GgdvzRw6n
 
gFDn1F4NkfdJl1Fg2UNLMeXWG4murieuBA==
 
-----END EC PRIVATE KEY-----
 
\ No newline at end of file
 
-----END EC PRIVATE KEY-----
roles/backup_server/molecule/default/tests/data/ssh/client2.pub
Show inline comments
 
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBD4dNApLyOsBAAoxnxE8LD9UcMnpIBbIkJeyL7ieDXNtBoHb80cOp4BQ59ReDZH3SZdRYNlDSzHl1huJrq4nrgQ= user@client2
 
\ No newline at end of file
 
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBD4dNApLyOsBAAoxnxE8LD9UcMnpIBbIkJeyL7ieDXNtBoHb80cOp4BQ59ReDZH3SZdRYNlDSzHl1huJrq4nrgQ= user@client2
roles/backup_server/molecule/default/tests/data/ssh/server_dsa
Show inline comments
 
@@ -9,4 +9,4 @@ gaRvcyUCgYAYAG/Udg4i/2q8Iemqs5TuP48ge1CxQcyFw4vVl2zr85MPZ24rBf+Z
 
PGy1CsEBpJqHQ5agftMYR9CRcxlqAP44JpIPcSq1NsL59HnXDsdCe/IJjO4JmL1H
 
L+VIcWkXgj0MxGds8hck+HC5lX7jGAKjZBea8ksBZD/Ma2WvYKXpggIVANDGn68D
 
y8jb/9mLaOM8bd9VFfdC
 
-----END DSA PRIVATE KEY-----
 
\ No newline at end of file
 
-----END DSA PRIVATE KEY-----
roles/backup_server/molecule/default/tests/data/ssh/server_ecdsa
Show inline comments
 
@@ -2,4 +2,4 @@
 
MHcCAQEEICsNfHic+b1E8HsU2kXcQNXozt4SHCb9VQC06GvbTkZuoAoGCCqGSM49
 
AwEHoUQDQgAEtplvzFzDk9vNDwmjzHKBxRojrOIYuz5mqwColI4ii72I3TNIo71r
 
i6Nt4yAht9lk8HlRZy/ULE16RNni2SsBow==
 
-----END EC PRIVATE KEY-----
 
\ No newline at end of file
 
-----END EC PRIVATE KEY-----
roles/backup_server/molecule/default/tests/data/ssh/server_ed25519
Show inline comments
 
@@ -4,4 +4,4 @@ QyNTUxOQAAACDkMzY9epWd7nCCb8JxWM0f72U90rloiFTzToSuSRpaugAAAJDQ62Z20Otm
 
dgAAAAtzc2gtZWQyNTUxOQAAACDkMzY9epWd7nCCb8JxWM0f72U90rloiFTzToSuSRpaug
 
AAAEDvdmF74GsQAOmsWcFWmXsbzdcSoHNbLiTkSWaVp0CtV+QzNj16lZ3ucIJvwnFYzR/v
 
ZT3SuWiIVPNOhK5JGlq6AAAADGJyYW5rb0BtYXJrcwE=
 
-----END OPENSSH PRIVATE KEY-----
 
\ No newline at end of file
 
-----END OPENSSH PRIVATE KEY-----
roles/backup_server/molecule/default/tests/data/ssh/server_rsa
Show inline comments
 
@@ -24,4 +24,4 @@ dvDt0R1O9ch2UjnmAx/8rk5yKNLfRIzo4q2zXx0snIYCMbn9LsYZoMoA8r+Oipv0
 
iR+wTQKBgQCpVCOigFz1pxUxWdbjQicEwug8k7dOtXkWepNqmXXFQTXUQnhsJ4iP
 
DlDGllPBJasoReRLAnI4OTkbuU1qECnUilVvFnqnuuox3vJ4IWeTdAxcmUAK7+WD
 
7EYQgHFDybzjEhxXtXGaMSfndAEVwPMRitZMUXaBjnufFW/j/8mrYg==
 
-----END RSA PRIVATE KEY-----
 
\ No newline at end of file
 
-----END RSA PRIVATE KEY-----
roles/backup_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -172,8 +172,16 @@ 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
 
    # Try to login with no preferred authentication types to the
 
    # server.
 
    # @TODO: The /bin/false is used because the ssh command listed
 
    #        below will return error code 255. On the other hand,
 
    #        Testinfra itself treats exit code 255 as special case for
 
    #        detecting when the ssh connection to managed machine
 
    #        fails. It might be a good idea to try to reach out to
 
    #        Testinfra maintainer about this or update this test to
 
    #        use Paramiko in some way.
 
    login_attempt = host.run("ssh -v -o PreferredAuthentications=none -o NoHostAuthenticationForLocalhost=yes localhost || /bin/false")
 

	
 
    assert login_attempt.rc == 1
 
    assert "debug1: Authentications that can continue: publickey" in login_attempt.stderr.split("\r\n")
roles/backup_server/molecule/default/tests/test_parameters_mandatory.py
Show inline comments
 
@@ -20,4 +20,4 @@ def test_firewall_configuration(host):
 
        assert firewall_config.user == 'root'
 
        assert firewall_config.group == 'root'
 
        assert firewall_config.mode == 0o640
 
        assert firewall_config.content == ""
 
        assert firewall_config.content == "\n"
roles/backup_server/molecule/default/tests/test_parameters_optional.py
Show inline comments
 
@@ -110,7 +110,7 @@ def test_backup_client_authorized_keys(host):
 
        assert client1_user_authorized_keys.user == 'root'
 
        assert client1_user_authorized_keys.group == 'bak-client1_backup'
 
        assert client1_user_authorized_keys.mode == 0o640
 
        assert client1_user_authorized_keys.content == open('tests/data/ssh/client1.pub', 'r').read().strip()
 
        assert client1_user_authorized_keys.content == open('tests/data/ssh/client1.pub', 'r').read()
 

	
 
        client2_user = host.user('bak-client2-backup')
 

	
 
@@ -119,7 +119,7 @@ def test_backup_client_authorized_keys(host):
 
        assert client2_user_authorized_keys.user == 'root'
 
        assert client2_user_authorized_keys.group == 'bak-client2-backup'
 
        assert client2_user_authorized_keys.mode == 0o640
 
        assert client2_user_authorized_keys.content == open('tests/data/ssh/client2.pub', 'r').read().strip()
 
        assert client2_user_authorized_keys.content == open('tests/data/ssh/client2.pub', 'r').read()
 

	
 

	
 
def test_firewall_configuration(host):
0 comments (0 inline, 0 general)