summaryrefslogtreecommitdiff
path: root/tests/integration_tests/bugs/test_gh671.py
blob: 15f204ee1a6a7c27912bb4fd92fda70e6b139c52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Integration test for gh-671.

Verify that on Azure that if a default user and password are specified
through the Azure API that a change in the default password overwrites
the old password
"""

import crypt

import pytest

from tests.integration_tests.clouds import IntegrationCloud

OLD_PASSWORD = "DoIM33tTheComplexityRequirements!??"
NEW_PASSWORD = "DoIM33tTheComplexityRequirementsNow!??"


def _check_password(instance, unhashed_password):
    shadow_password = instance.execute("getent shadow ubuntu").split(":")[1]
    salt = shadow_password.rsplit("$", 1)[0]
    hashed_password = crypt.crypt(unhashed_password, salt)
    assert shadow_password == hashed_password


@pytest.mark.azure
@pytest.mark.sru_2020_11
def test_update_default_password(setup_image, session_cloud: IntegrationCloud):
    os_profile = {
        "os_profile": {
            "admin_password": "",
            "linux_configuration": {"disable_password_authentication": False},
        }
    }
    os_profile["os_profile"]["admin_password"] = OLD_PASSWORD
    instance1 = session_cloud.launch(launch_kwargs={"vm_params": os_profile})

    _check_password(instance1, OLD_PASSWORD)

    snapshot_id = instance1.cloud.cloud_instance.snapshot(
        instance1.instance, delete_provisioned_user=False
    )

    os_profile["os_profile"]["admin_password"] = NEW_PASSWORD
    try:
        with session_cloud.launch(
            launch_kwargs={
                "image_id": snapshot_id,
                "vm_params": os_profile,
            }
        ) as instance2:
            _check_password(instance2, NEW_PASSWORD)
    finally:
        session_cloud.cloud_instance.delete_image(snapshot_id)
        instance1.destroy()