Skip to content

Commit

Permalink
added test for register with authentication keys and environment
Browse files Browse the repository at this point in the history
  • Loading branch information
jstavel committed Dec 6, 2024
1 parent 17e9f4a commit 28c6917
Showing 1 changed file with 58 additions and 6 deletions.
64 changes: 58 additions & 6 deletions integration-tests/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from conftest import RHSMPrivateBus
from constants import RHSM, RHSM_REGISTER_SERVER, RHSM_REGISTER
from dasbus.error import DBusError
from dasbus.typing import get_variant, Str, get_native
from dasbus.typing import get_variant, Str, get_native, List

import sh
import subprocess
Expand All @@ -16,7 +16,7 @@
from dataclasses import dataclass
from functools import reduce
import json
from funcy import first
from funcy import first, partial

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_register_with_wrong_values(external_candlepin, subman, test_config, sub
{},
locale)
logger.debug(f"raised exception: {excinfo}")
assert "Invalid username or password." in str(excinfo.value)
assert "Invalid Credentials" in str(excinfo.value)
assert not subman.is_registered

with subtests.test(msg="Register with wrong password"):
Expand All @@ -117,7 +117,7 @@ def test_register_with_wrong_values(external_candlepin, subman, test_config, sub
{},
locale)
logger.debug(f"raised exception: {excinfo}")
assert "Invalid username or password." in str(excinfo.value)
assert "Invalid Credentials" in str(excinfo.value)
assert not subman.is_registered

with subtests.test(msg="Register with wrong organization"):
Expand Down Expand Up @@ -243,10 +243,62 @@ def test_register_with_activation_keys(external_candlepin, subman, test_config):
{},
{},
locale))

assert 'activationKeys' in response,\
"DBus method returns what activation keys were used to register a system"


logger.debug(response['activationKeys'])
assert sorted([ii['activationKeyName'] for ii in response['activationKeys']]) == sorted(act_keynames)

assert subman.is_registered

def test_register_with_activation_keys_and_environments(external_candlepin, subman, test_config):
"""
https://www.candlepinproject.org/docs/subscription-manager/dbus_objects.html#methods-6
"""
candlepin_config = partial(test_config.get,"candlepin")

assert not subman.is_registered
proxy = RHSM.get_proxy(RHSM_REGISTER_SERVER)
act_keynames = candlepin_config("activation_keys")
with RHSMPrivateBus(proxy) as private_bus:
private_proxy = private_bus.get_proxy(RHSM.service_name,
RHSM_REGISTER.object_path)
locale = os.environ.get("LANG", "")
response = json.loads(private_proxy.RegisterWithActivationKeys(candlepin_config("org"),
act_keynames,
{"environments":get_variant(Str, first(candlepin_config("environment","ids")))},
{},
locale))

assert 'activationKeys' in response,\
"DBus method returns what activation keys were used to register a system"

logger.debug(response['activationKeys'])
assert sorted([ii['activationKeyName'] for ii in response['activationKeys']]) == sorted(act_keynames)

subman_response = subman.run("identity")
"""
(env) [root@kvm-08-guest21 integration-tests]# subscription-manager identity
system identity: 5c00d2c6-5bea-4b6d-8662-8680e38f0dab
name: kvm-08-guest21.lab.eng.rdu2.dc.redhat.com
org name: Donald Duck
org ID: donaldduck
environment name: env-name-01
"""
def read_pair(line):
result = re.search(r"^([^:]+):(.*)",line.strip())
if result:
pair = [g.strip() for g in result.groups()]
return pair
return []

pairs = dict([read_pair(line) for line in subman_response.stdout.splitlines()])
logger.debug(pairs)

assert "environment name" in pairs
assert pairs["environment name"] == first(candlepin_config("environment","names"))


assert subman.is_registered

0 comments on commit 28c6917

Please sign in to comment.