Ejemplo n.º 1
0
    def test_positive_ssh_key_in_host_enc(self, default_sat):
        """SSH key appears in host ENC output

        :id: 4b70a950-e777-4b2d-a83d-29279715fe6d

        :steps:

            1. Create user with all the details
            2. Add ssh key in above user
            3. Provision a new host from the above user
            4. Check new hosts ENC output

        :expectedresults: SSH key should be added to host ENC output

        :CaseLevel: Integration
        """
        org = entities.Organization().create()
        loc = entities.Location(organization=[org]).create()
        user = entities.User(organization=[org], location=[loc]).create()
        ssh_key = gen_ssh_keypairs()[1]
        entities.SSHKey(user=user, name=gen_string('alpha'),
                        key=ssh_key).create()
        host = entities.Host(owner=user,
                             owner_type='User',
                             organization=org,
                             location=loc).create()
        sshkey_updated_for_host = f'{ssh_key} {user.login}@{default_sat.hostname}'
        host_enc_key = host.enc()['data']['parameters']['ssh_authorized_keys']
        assert sshkey_updated_for_host == host_enc_key[0]
Ejemplo n.º 2
0
    def test_positive_CRD_ssh_key(self):
        """SSH Key can be added to User

        :id: d00905f6-3a70-4e2f-a5ae-fcac18274bb7

        :steps:

            1. Create new user with all the details
            2. Add SSH key to the above user
            3. Info the above ssh key in user
            4. Delete ssh key in user

        :expectedresults: SSH key should be added to user

        :CaseImportance: Critical
        """
        user = entities.User().create()
        ssh_name = gen_string('alpha')
        ssh_key = gen_ssh_keypairs()[1]
        user_sshkey = entities.SSHKey(user=user, name=ssh_name,
                                      key=ssh_key).create()
        assert ssh_name == user_sshkey.name
        assert ssh_key == user_sshkey.key
        user_sshkey.delete()
        result = entities.SSHKey(user=user).search()
        assert len(result) == 0
Ejemplo n.º 3
0
class TestSshKeyInUser:
    """Implements the SSH Key in User Tests"""

    ssh_key = gen_ssh_keypairs()[1]

    @pytest.fixture(scope='module')
    def module_user(self):
        """Create an user"""
        return entities.User().create()

    @pytest.mark.tier1
    def test_positive_CRD_ssh_key(self, module_user):
        """SSH Key can be added to a User, listed and deletd

        :id: 57304fca-8e0d-454a-be31-34423345c8b2

        :expectedresults: SSH key should be added to new user,
                          listed and deleted

        :CaseImportance: Critical
        """
        ssh_name = gen_string('alpha')
        User.ssh_keys_add({'user': module_user.login, 'key': self.ssh_key, 'name': ssh_name})
        result = User.ssh_keys_list({'user-id': module_user.id})
        assert ssh_name in [i['name'] for i in result]
        result = User.ssh_keys_info({'user-id': module_user.id, 'name': ssh_name})
        assert self.ssh_key in result[0]['public-key']
        result = User.ssh_keys_delete({'user-id': module_user.id, 'name': ssh_name})
        result = User.ssh_keys_list({'user-id': module_user.id})
        assert ssh_name not in [i['name'] for i in result]

    @pytest.mark.tier1
    def test_positive_create_ssh_key_super_admin_from_file(self, default_sat):
        """SSH Key can be added to Super Admin user from file

        :id: b865d0ae-6317-475c-a6da-600615b71eeb

        :expectedresults: SSH Key should be added to Super Admin user
                          from ssh pub file

        :CaseImportance: Critical
        """
        ssh_name = gen_string('alpha')
        result = default_sat.execute(f"echo '{self.ssh_key}' > test_key.pub")
        assert result.status == 0, 'key file not created'
        User.ssh_keys_add({'user': '******', 'key-file': 'test_key.pub', 'name': ssh_name})
        result = User.ssh_keys_list({'user': '******'})
        assert ssh_name in [i['name'] for i in result]
        result = User.ssh_keys_info({'user': '******', 'name': ssh_name})
        assert self.ssh_key == result[0]['public-key']
Ejemplo n.º 4
0
    def test_negative_create_ssh_key_with_invalid_name(self, create_user):
        """Attempt to add SSH key that has invalid name length

        :id: e1e17839-a392-45bb-bb1e-28d3cd9dba1c

        :steps:

            1. Create new user with all the details
            2. Attempt to add invalid ssh Key name to above user

        :expectedresults: Satellite should raise Name is too long assertion

        :CaseImportance: Critical
        """
        invalid_ssh_key_name = gen_string('alpha', length=300)
        with pytest.raises(HTTPError) as context:
            entities.SSHKey(user=create_user['user'],
                            name=invalid_ssh_key_name,
                            key=gen_ssh_keypairs()[1]).create()
        assert re.search("Name is too long", context.value.response.text)
Ejemplo n.º 5
0
    def test_positive_create_multiple_ssh_key_types(self, create_user):
        """Multiple types of ssh keys can be added to user

        :id: d1ffa908-dc86-40c8-b6f0-20650cc67046

        :steps:
            1. Create user with all the details
            2. Add multiple types of supported ssh keys, type includes
                rsa, dsa, ed25519, ecdsa

        :expectedresults: Multiple types of supported ssh keys can be added to
            user
        """
        rsa = gen_ssh_keypairs()[1]
        dsa = create_user['data_keys']['ssh_keys']['dsa']
        ecdsa = create_user['data_keys']['ssh_keys']['ecdsa']
        ed = create_user['data_keys']['ssh_keys']['ed']
        user = entities.User().create()
        for key in [rsa, dsa, ecdsa, ed]:
            entities.SSHKey(user=user, name=gen_string('alpha'),
                            key=key).create()
        user_sshkeys = entities.SSHKey(user=user).search()
        assert len(user_sshkeys) == 4