Skip to content

Commit

Permalink
test: Use SCA to register
Browse files Browse the repository at this point in the history
* Card ID: CCT-612
* Card ID: RHEL-41063

List of notable changes:
- Switched the tests to use accounts that are part of SCA organization
- Removed calls to `wait_subscription`.
  In SCA, there is no "product status", we don't need/can't continue
  checking for it.
  • Loading branch information
m-horky committed Aug 13, 2024
1 parent 4e82e27 commit 7be06dd
Showing 1 changed file with 31 additions and 48 deletions.
79 changes: 31 additions & 48 deletions test/check-subscriptions
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,29 @@ import testvm

# candlepin on the services image has a lot of demo data preloaded
# useful info/commands:
# Login: doc password: password
# org: snowwhite
# login: huey
# password: password
# organizations: admin, snowwhite, donaldduck
#
# Login: admin password: admin
# org: admin
# login: duey
# password: password
# org: donaldduck
#
# of those, only the 'donaldduck' organization is in SCA mode
#
# product certificates are installed onto the test machine to make it possible
# to use those products; few sample products are used in the tests, because of
# the different subscriptions for doc and admin, see the PRODUCT_* variables
# the different subscriptions for users, see the PRODUCT_* variables
#
# to use the candlepin image on a test machine, either add the certificate or
# allow insecure connections (/etc/rhsm/rhsm.conf -> "insecure = 1")
#
# $IP is the ip of the candlepin machine
#
# add an activation key to a pool:
# curl --insecure --request POST --user admin:admin \
# curl --insecure --request POST --user huey:password \
# https://$IP:8443/candlepin/activation_keys/ff80808155ca50b10155ca50cd280010/pools/ff80808155ca50b10155ca51f04607e5
# register with: activation key "awesome_os_pool" and org "admin"
# register with: activation key "awesome_os_pool" and org "donaldduck"
#
# in order to get the right ids for the activation key and pool, see
# ACTIVATION_KEY_SCRIPT
Expand Down Expand Up @@ -80,12 +84,12 @@ import sys
import json
import requests
data = requests.get(sys.argv[1] + "/activation_keys", auth=("admin", "admin")).json()
data = requests.get(sys.argv[1] + "/activation_keys", auth=("huey", "password")).json()
key = [
e["id"] for e in data if e["name"] == "awesome_os_pool" and e["owner"]["displayName"] == "Admin Owner"
][0]
data = requests.get(sys.argv[1] + "/pools", auth=("admin", "admin")).json()
data = requests.get(sys.argv[1] + "/pools", auth=("huey", "password")).json()
pool = [
e["id"]
for e in data
Expand All @@ -95,7 +99,7 @@ pool = [
][0]
key_url = sys.argv[1] + "/activation_keys/{key}/pools/{pool}".format(key=key, pool=pool)
requests.post(key_url, auth=("admin", "admin"))
requests.post(key_url, auth=("huey", "password"))
"""

# fmt: off
Expand All @@ -104,9 +108,9 @@ CANDLEPIN_ADDR = "10.111.112.100"
CANDLEPIN_HOSTNAME = "services.cockpit.lan"
CANDLEPIN_URL = "https://%s:8443/candlepin" % CANDLEPIN_HOSTNAME

PRODUCT_SNOWY = {
"id": "6050",
"name": "Snowy OS Premium Architecture Bits"
PRODUCT_DONALDY = {
"id": "7050",
"name": "Donaldy OS Premium Architecture Bits"
}

PRODUCT_SHARED = {
Expand Down Expand Up @@ -163,7 +167,7 @@ class SubscriptionsCase(MachineCase):
m.upload([filename], "/etc/pki/product")

m.execute(["mkdir", "-p", "/etc/pki/product"])
download_product(PRODUCT_SNOWY)
download_product(PRODUCT_DONALDY)
download_product(PRODUCT_SHARED)

# download the candlepin CA certificate
Expand Down Expand Up @@ -218,12 +222,6 @@ authmethod=CERT
m.upload(["files/mock-insights"], "/var/tmp")
m.spawn("env PYTHONUNBUFFERED=1 /var/tmp/mock-insights", "mock-insights.log")

def wait_subscription(self, product, is_subscribed):
if is_subscribed is True:
self.browser.wait_text("tr[data-row-id='%s'] .pf-c-label" % product["name"], "Subscribed")
elif is_subscribed is False:
self.browser.wait_text_not("tr[data-row-id='%s'] .pf-c-label" % product["name"], "Subscribed")


class TestSubscriptions(SubscriptionsCase):
def testRegister(self):
Expand All @@ -242,7 +240,7 @@ class TestSubscriptions(SubscriptionsCase):
# enter server and incorrect login data
b.set_val("#subscription-register-url", "custom")
b.set_input_text("#subscription-register-url-custom", CANDLEPIN_URL)
b.set_input_text("#subscription-register-username", "doc")
b.set_input_text("#subscription-register-username", "huey")
b.set_input_text("#subscription-register-password", "wrongpass")

# Do not try to connect to insights
Expand All @@ -263,7 +261,7 @@ class TestSubscriptions(SubscriptionsCase):
b.wait_not_in_text("body", "Invalid credentials")

# wait for message that we need to specify our org
b.wait_in_text("body", "User doc is member of more organizations, but no organization was selected")
b.wait_in_text("body", "User huey is member of more organizations, but no organization was selected")

# now specify the org
b.set_input_text("#subscription-register-org", "snowwhite")
Expand All @@ -274,15 +272,12 @@ class TestSubscriptions(SubscriptionsCase):
# old error should disappear
with b.wait_timeout(60):
b.wait_not_in_text(
"body", "User doc is member of more organizations, but no organization was selected"
"body", "User huey is member of more organizations, but no organization was selected"
)

# dialog should disappear
b.wait_not_present(dialog_register_button_sel)

# make sure this product is subscribed
self.wait_subscription(PRODUCT_SNOWY, True)

# unregister
with b.wait_timeout(360):
b.click(unregister_button_sel)
Expand Down Expand Up @@ -314,7 +309,7 @@ class TestSubscriptions(SubscriptionsCase):
# make sure we have an activation key on the target machine
machine_python(self.machine, ACTIVATION_KEY_SCRIPT, CANDLEPIN_URL)
b.set_input_text("#subscription-register-key", "awesome_os_pool")
b.set_input_text("#subscription-register-org", "admin")
b.set_input_text("#subscription-register-org", "donaldduck")

dialog_register_button_sel = "footer .pf-m-primary"
b.click(dialog_register_button_sel)
Expand All @@ -323,21 +318,9 @@ class TestSubscriptions(SubscriptionsCase):
with b.wait_timeout(60):
b.wait_not_present(dialog_register_button_sel)

# make sure this product isn't subscribed
self.wait_subscription(PRODUCT_SNOWY, False)

# find another one that is subscribed
self.wait_subscription(PRODUCT_SHARED, True)

# unregister
b.click(unregister_button_sel)

# make sure this product isn't subscribed
self.wait_subscription(PRODUCT_SNOWY, False)

# find another one that isn't subscribed too
self.wait_subscription(PRODUCT_SHARED, False)

def testUnpriv(self):
self.machine.execute("useradd junior; echo junior:foobar | chpasswd")
self.login_and_go("/subscriptions", user="junior")
Expand All @@ -358,9 +341,9 @@ class TestSubscriptions(SubscriptionsCase):

b.set_val("#subscription-register-url", "custom")
b.set_input_text("#subscription-register-url-custom", CANDLEPIN_URL)
b.set_input_text("#subscription-register-username", "admin")
b.set_input_text("#subscription-register-password", "admin")
b.set_input_text("#subscription-register-org", "admin")
b.set_input_text("#subscription-register-username", "huey")
b.set_input_text("#subscription-register-password", "password")
b.set_input_text("#subscription-register-org", "donaldduck")

# Do not try to connect to insights
b.set_checked("#subscription-insights", False)
Expand Down Expand Up @@ -418,9 +401,9 @@ class TestSubscriptions(SubscriptionsCase):

b.set_val("#subscription-register-url", "custom")
b.set_input_text("#subscription-register-url-custom", CANDLEPIN_URL)
b.set_input_text("#subscription-register-username", "admin")
b.set_input_text("#subscription-register-password", "admin")
b.set_input_text("#subscription-register-org", "admin")
b.set_input_text("#subscription-register-username", "huey")
b.set_input_text("#subscription-register-password", "password")
b.set_input_text("#subscription-register-org", "donaldduck")
b.set_checked("#subscription-insights", True)
dialog_register_button_sel = "footer .pf-m-primary"
b.click(dialog_register_button_sel)
Expand Down Expand Up @@ -478,9 +461,9 @@ class TestSubscriptionsPackages(SubscriptionsCase, PackageCase):

b.set_val("#subscription-register-url", "custom")
b.set_input_text("#subscription-register-url-custom", CANDLEPIN_URL)
b.set_input_text("#subscription-register-username", "admin")
b.set_input_text("#subscription-register-password", "admin")
b.set_input_text("#subscription-register-org", "admin")
b.set_input_text("#subscription-register-username", "huey")
b.set_input_text("#subscription-register-password", "password")
b.set_input_text("#subscription-register-org", "donaldduck")
b.set_checked("#subscription-insights", True)
b.wait_visible('.pf-c-modal-box__body:contains("The insights-client package will be installed")')
b.click("footer button.apply")
Expand Down

0 comments on commit 7be06dd

Please sign in to comment.