Search in sources :

Example 6 with ConsumerCert

use of rhsm.data.ConsumerCert in project rhsm-qe by RedHatQE.

the class EventTests method testExportCreated.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21850", "RHEL7-51671" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "subscription-manager: events: Export Created is sent over an RSS atom feed.", groups = { "Tier3Tests", "ExportCreated_Test" }, dependsOnGroups = { "ProductDeleted_Test" }, enabled = true, alwaysRun = true)
public // @ImplementsTCMS(id="")
void testExportCreated() throws Exception {
    if (sm_serverAdminUsername.equals("") || sm_serverAdminPassword.equals(""))
        throw new SkipException("This test requires the candlepin server admin username and password credentials.");
    // start fresh by unregistering
    clienttasks.unregister(null, null, null, null);
    // NOTE: Without the subscribe, this bugzilla is thrown:
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", /*TODO CHANGE TO ">" after candlepin 2.1.2-1 is tagged*/
    "2.1.1-1")) {
        // candlepin commit 739b51a0d196d9d3153320961af693a24c0b826f Bug 1455361: Disallow candlepin consumers to be registered via Subscription Manager
        clienttasks.registerCandlepinConsumer(sm_clientUsername, sm_clientPassword, sm_clientOrg, sm_serverUrl, "candlepin");
    } else {
        clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, ConsumerType.candlepin, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    }
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    // avoid "Too many content sets..." from Issue/Bug 1455361 - strange pool availability and bind behavior for consumer of type candlepin
    pools.remove(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "mktProductId-93x2", pools));
    // avoid "Too many content sets..." from Issue/Bug 1455361 - strange pool availability and bind behavior for consumer of type candlepin
    pools.remove(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "mktProductId-186", pools));
    // randomly pick a pool
    testPool = pools.get(randomGenerator.nextInt(pools.size()));
    clienttasks.subscribe(null, null, testPool.poolId, null, null, null, null, null, null, null, null, null, null);
    // String consumerKey = result.getStdout().split(" ")[0];
    // get the owner and consumer feeds before we test the firing of a new event
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    String ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid);
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldOwnerFeed = CandlepinTasks.getSyndFeedForOwner(ownerKey, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldConsumerFeed = CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
    consumerCert.consumerid, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // do something that will fire a exported created event
    CandlepinTasks.exportConsumerUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid, "/tmp/export.zip");
    String[] newEventTitles = new String[] { "EXPORT CREATED" };
    // TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=721136 - jsefler 07/14/2011
    boolean invokeWorkaroundWhileBugIsOpen = true;
    String bugId = "721136";
    try {
        if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
            log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
        } else {
            invokeWorkaroundWhileBugIsOpen = false;
        }
    } catch (BugzillaAPIException be) {
    /* ignore exception */
    } catch (RuntimeException re) {
    /* ignore exception */
    }
    if (invokeWorkaroundWhileBugIsOpen) {
        newEventTitles = new String[] { ownerKey + " created an export for consumer " + consumerCert.name };
    }
    // END OF WORKAROUND
    // assert the consumer feed...
    assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles);
    // assert the owner feed...
    assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles);
    // assert the feed...
    assertTheNewFeed(oldFeed, newEventTitles);
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SubscriptionPool(rhsm.data.SubscriptionPool) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 7 with ConsumerCert

use of rhsm.data.ConsumerCert in project rhsm-qe by RedHatQE.

the class EventTests method testEntitlementCreated.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21842", "RHEL7-51663" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "subscription-manager: events: Enitlement Created is sent over an RSS atom feed.", groups = { "Tier3Tests", "EntitlementCreated_Test" }, dependsOnGroups = { "ConsumerCreated_Test" }, enabled = true)
@ImplementsNitrateTest(caseId = 50403)
public void testEntitlementCreated() throws Exception {
    // test prerequisites
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    // 7/30/2012 updating consumer's autoheal to prevent an auto 'ENTITLEMENT CREATED' event
    CandlepinTasks.setAutohealForConsumer(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerCert.consumerid, false);
    // get the owner and consumer feeds before we test the firing of a new event
    String ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid);
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldOwnerFeed = CandlepinTasks.getSyndFeedForOwner(ownerKey, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldConsumerFeed = CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
    consumerCert.consumerid, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // fire a subscribe event
    // SubscriptionPool pool = pools.get(0); // pick the first pool
    // randomly pick a pool
    testPool = pools.get(randomGenerator.nextInt(pools.size()));
    // debugTesting randomly picked standalone non-zero virt_limit pools
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "awesomeos-virt-4", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "awesomeos-virt-unlimited", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "awesomeos-server-basic-dc", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", "8a90860f5eed6282015eed64099a0193", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("contract", "", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionType", "Standard (Temporary)", pools);
    // clienttasks.subscribeToSubscriptionPoolUsingPoolId(testPool);	// RHEL59: THIS IS GENERATING EXTRA CONSUMER MODIFIED EVENTS THAT WE DON'T REALLY WANT TO TEST
    clienttasks.subscribe(null, null, testPool.poolId, null, null, null, null, null, null, null, null, null, null);
    List<String> newEventTitles = new ArrayList<String>();
    // newEventTitles.add("COMPLIANCE CREATED");	// COMPLIANCE CREATED events were added to support gutterball
    newEventTitles.add("ENTITLEMENT CREATED");
    // newEventTitles.add("COMPLIANCE CREATED");
    // newEventTitles.add("COMPLIANCE CREATED");
    // TEMPORARY WORKAROUND FOR BUG
    // Status: 	CLOSED CURRENTRELEASE
    boolean invokeWorkaroundWhileBugIsOpen = false;
    // jsefler 07/14/2011 Bug 721136 - the content of the atom feeds has the same value for title and description
    String bugId = "721136";
    try {
        if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
            log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
        } else {
            invokeWorkaroundWhileBugIsOpen = false;
        }
    } catch (BugzillaAPIException be) {
    /* ignore exception */
    } catch (RuntimeException re) {
    /* ignore exception */
    }
    if (invokeWorkaroundWhileBugIsOpen) {
        newEventTitles.clear();
        newEventTitles.add(clienttasks.hostname + " consumed a subscription for product " + testPool.subscriptionName);
    }
    // END OF WORKAROUND
    // assert the consumer feed...
    // assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles.toArray(new String[]{}));	// worked prior to RHEL59
    // TODO Using the IgnoringEventTitles is a workaround bug 838123#c2
    assertTheNewConsumerFeedIgnoringEventTitles(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles.toArray(new String[] {}), new HashSet<String>() {

        {
            add("CONSUMER MODIFIED");
            add("COMPLIANCE CREATED");
        }
    });
    // adjust the expected events when the candlepin server is standalone and the pool has a non-zero virt_limit
    String virt_limit = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, testPool.poolId, "virt_limit");
    if (servertasks.statusStandalone && virt_limit != null && !virt_limit.equals("0")) {
        newEventTitles.add(1, "POOL CREATED");
    }
    // assert the owner feed...
    // assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles.toArray(new String[]{}));	// worked prior to RHEL59
    // TODO Using the IgnoringEventTitles is a workaround bug 838123#c2
    assertTheNewOwnerFeedIgnoringEventTitles(ownerKey, oldOwnerFeed, newEventTitles.toArray(new String[] {}), new HashSet<String>() {

        {
            add("CONSUMER MODIFIED");
            add("COMPLIANCE CREATED");
        }
    });
    // assert the feed...
    // assertTheNewFeed(oldFeed, newEventTitles.toArray(new String[]{}));	// worked prior to RHEL59
    assertTheNewFeedIgnoringEventTitles(oldFeed, newEventTitles.toArray(new String[] {}), new HashSet<String>() {

        {
            add("CONSUMER MODIFIED");
            add("COMPLIANCE CREATED");
        }
    });
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) ArrayList(java.util.ArrayList) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SubscriptionPool(rhsm.data.SubscriptionPool) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 8 with ConsumerCert

use of rhsm.data.ConsumerCert in project rhsm-qe by RedHatQE.

the class RegisterTests method testReregisterWithBadIdentityCert.

/**
 * https://tcms.engineering.redhat.com/case/56328/?from_plan=2476
 */
@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36529", "RHEL7-51302" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "subscription-manager-cli: bad identity cert\n" + "\t\tActions:\n" + "\n" + "\t \t\t* register a client to candlepin (take note of the uuid returned)\n" + "\t \t\t* take note of your identity cert info using openssl x509\n" + "\t \t\t* subscribe to a pool\n" + "\t \t\t* list consumed\n" + "\t \t\t* ls /etc/pki/entitlement/products\n" + "\t \t\t* Now.. mess up your identity..  mv /etc/pki/consumer/cert.pem /bak\n" + "\t \t\t* run the \"reregister\" command w/ username and passwd AND w/consumerid=<uuid>\n" + "\n" + "\t\tExpected Results:\n" + "\n" + "\t \t\t* after running reregister you should have a new identity cert\n" + "\t \t\t* after registering you should still the same products consumed (list consumed)\n" + "\t \t\t* the entitlement serials should be the same as before the registration", groups = { "Tier2Tests", "blockedByBug-624106", "blockedByBug-844069", "ReregisterWithBadIdentityCert_Test" }, enabled = true)
@ImplementsNitrateTest(caseId = 56328)
public void testReregisterWithBadIdentityCert() {
    // start fresh by unregistering and registering
    clienttasks.unregister(null, null, null, null);
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    // take note of your identity cert
    ConsumerCert consumerCertBefore = clienttasks.getCurrentConsumerCert();
    // subscribe to a random pool
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    if (pools.isEmpty())
        throw new SkipException("Cannot randomly pick a pool for subscribing when there are no available pools for testing.");
    // randomly pick a pool
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
    clienttasks.subscribeToSubscriptionPool(pool);
    // get a list of the consumed products
    List<ProductSubscription> consumedProductSubscriptionsBefore = clienttasks.getCurrentlyConsumedProductSubscriptions();
    // Now.. mess up your identity..  by borking its content
    log.info("Messing up the identity cert by borking its content...");
    RemoteFileTasks.runCommandAndAssert(client, "openssl x509 -noout -text -in " + clienttasks.consumerCertFile() + " > /tmp/stdout; mv /tmp/stdout -f " + clienttasks.consumerCertFile(), 0);
    // reregister w/ username, password, and consumerid
    // clienttasks.reregister(client1username,client1password,consumerCertBefore.consumerid);
    log.warning("The subscription-manager-cli reregister module has been eliminated and replaced by register --consumerid b3c728183c7259841100eeacb7754c727dc523cd...");
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.16.2-1")) {
        // commit f14d2618ea94c18a0295ae3a5526a2ff252a3f99 Doesnt allow using --force with --consumerid
        // [root@jsefler-6 ~]# subscription-manager register --username=testuser1 --password=password --consumerid=fc1b9613-2793-4017-8b9f-a8ab85c5ba96 --force
        // Error: Can not force registration while attempting to recover registration with consumerid. Please use --force without --consumerid to re-register or use the clean command and try again without --force.
        log.warning("The original point of this test is not really applicable after 1.16.2-1 where registering with --consumerid and --force has been more explicitly divided into two steps... clean and register --consumerid.");
        clienttasks.clean();
        clienttasks.register(sm_clientUsername, sm_clientPassword, null, null, null, null, consumerCertBefore.consumerid, null, null, null, (String) null, null, null, null, Boolean.FALSE, false, null, null, null, null);
    } else {
        clienttasks.register(sm_clientUsername, sm_clientPassword, null, null, null, null, consumerCertBefore.consumerid, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
    }
    // assert that the identity cert has not changed
    ConsumerCert consumerCertAfter = clienttasks.getCurrentConsumerCert();
    Assert.assertEquals(consumerCertBefore, consumerCertAfter, "The consumer identity cert has not changed after reregistering with consumerid.");
    // assert that the user is still consuming the same products
    List<ProductSubscription> consumedProductSubscriptionsAfter = clienttasks.getCurrentlyConsumedProductSubscriptions();
    Assert.assertTrue(consumedProductSubscriptionsAfter.containsAll(consumedProductSubscriptionsBefore) && consumedProductSubscriptionsBefore.size() == consumedProductSubscriptionsAfter.size(), "The list of consumed products after reregistering is identical.");
}
Also used : ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 9 with ConsumerCert

use of rhsm.data.ConsumerCert in project rhsm-qe by RedHatQE.

the class IdentityTests method testIdentityRegenerate.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19961", "RHEL7-33075" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "subscription-manager-cli: identity regenerate", groups = { "Tier1Tests" }, enabled = true)
@ImplementsNitrateTest(caseId = 64179)
public void testIdentityRegenerate() {
    // start fresh by unregistering and registering
    clienttasks.unregister(null, null, null, null);
    SSHCommandResult registerResult = clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    ConsumerCert origConsumerCert = clienttasks.getCurrentConsumerCert();
    // regenerate the identity... and assert
    log.info("Regenerating identity using the current cert for authentication...");
    SSHCommandResult identityResult = clienttasks.identity(null, null, Boolean.TRUE, null, null, null, null, null);
    // RHEL57 RHEL61 Assert.assertEquals(identityResult.getStdout().trim(), registerResult.getStdout().trim(),
    // "The original registered result is returned from identity regenerate with original authenticator.");
    // also assert that the newly regenerated cert matches but is newer than the original cert
    log.info("also asserting that the newly regenerated cert matches but is newer than original cert...");
    ConsumerCert newConsumerCert = clienttasks.getCurrentConsumerCert();
    Assert.assertEquals(newConsumerCert.consumerid, origConsumerCert.consumerid, "The consumerids are a match.");
    Assert.assertEquals(newConsumerCert.issuer, origConsumerCert.issuer, "The issuers are a match.");
    Assert.assertEquals(newConsumerCert.name, origConsumerCert.name, "The usernames are a match.");
    // Assert.assertEquals(newConsumerCert.validityNotAfter, origConsumerCert.validityNotAfter, "The validity end dates are a match."); //Not After : Jan 6 23:59:59 2012 GMT
    // with fix from https://bugzilla.redhat.com/show_bug.cgi?id=660713#c10
    Assert.assertTrue(newConsumerCert.validityNotAfter.after(origConsumerCert.validityNotAfter), "The new validity end date is after the original.");
    Assert.assertTrue(newConsumerCert.validityNotBefore.after(origConsumerCert.validityNotBefore), "The new validity start date is after the original.");
    Assert.assertNotSame(newConsumerCert.serialNumber, origConsumerCert.serialNumber, "The serial numbers should not match on a regenerated identity cert.");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 10 with ConsumerCert

use of rhsm.data.ConsumerCert in project rhsm-qe by RedHatQE.

the class IdentityTests method testIdentityIsBackedUpWhenConsumerIsDeletedServerSide.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19962", "RHEL7-51006" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "subscription-manager: assert that the consumer cert is backed up when a server-side deletion is detected.", groups = { "Tier1Tests", "VerifyIdentityIsBackedUpWhenConsumerIsDeletedServerSide_Test", "blockedByBug-814466", "blockedByBug-813296", "blockedByBug-838187", "blockedByBug-852706", "blockedByBug-872847", "blockedByBug-894633", "blockedByBug-907638", "blockedByBug-822402", "blockedByBug-986572", "blockedByBug-1000301", "blockedByBug-1026435", "blockedByBug-1019747", "blockedByBug-1026501", "blockedByBug-1366301", "blockedByBug-1397201" }, dataProvider = "getConsumerCertDirData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testIdentityIsBackedUpWhenConsumerIsDeletedServerSide(Object bugzilla, String consumerCertDir) throws Exception {
    // set the rhsm.consumerCertDir (DO NOT USE SubscriptionTasks.config(...))
    clienttasks.updateConfFileParameter(clienttasks.rhsmConfFile, "consumerCertDir", consumerCertDir);
    // register and remember the original consumer identity
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    clienttasks.config(null, null, true, new String[] { "rhsmcertd", /*"certFrequency" CHANGED BY BUG 882459 TO*/
    "certCheckInterval".toLowerCase(), "240" });
    // make sure that rhsmcertd will not interfere with test
    clienttasks.restart_rhsmcertd(null, null, true);
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    String consumerCert_md5sum = client.runCommandAndWait("md5sum " + clienttasks.consumerCertFile()).getStdout().trim();
    String consumerKey_md5sum = client.runCommandAndWait("md5sum " + clienttasks.consumerKeyFile()).getStdout().trim();
    // Subscribe to a randomly available pool...
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    if (pools.size() <= 0)
        throw new SkipException("No susbcriptions are available for which an entitlement could be granted.");
    log.info("Subscribe to a randomly available pool...");
    // randomly pick a pool
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
    File entitlementCertFile = clienttasks.subscribeToSubscriptionPool(pool, /*sm_serverAdminUsername*/
    sm_clientUsername, /*sm_serverAdminPassword*/
    sm_clientPassword, sm_serverUrl);
    // EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
    // do a server-side consumer deletion
    // # curl -k -u testuser1:password --request DELETE https://jsefler-f14-candlepin.usersys.redhat.com:8443/candlepin/consumers/8511a2a6-c2ec-4612-8186-af932a3b97cf
    CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerCert.consumerid);
    // give the server a chance to complete the job request	// TODO change this hard sleep to wait for a finished job status
    sleep(60 * 1000);
    // assert that all subscription-manager calls are blocked by a message stating that the consumer has been deleted
    // Original Stderr: Consumer with id b0f1ed9f-3dfa-4eea-8e04-72ab8075d533 could not be found
    String expectedMsg = String.format("Consumer %s has been deleted", consumerCert.consumerid);
    if (!clienttasks.workaroundForBug876764(sm_serverType))
        expectedMsg = String.format("Unit %s has been deleted", consumerCert.consumerid);
    String ignoreStderr = "stty: standard input: Invalid argument";
    SSHCommandResult result;
    Integer expectedExitCode = new Integer(255);
    // post commit df95529a5edd0be456b3528b74344be283c4d258 bug 1119688
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.8-1"))
        expectedExitCode = new Integer(70);
    result = clienttasks.identity_(null, null, null, null, null, null, null, null);
    Assert.assertEquals(result.getExitCode(), expectedExitCode, "Exitcode expected after the consumer has been deleted on the server-side.");
    Assert.assertEquals(result.getStdout().trim(), "", "Stdout expected after the consumer has been deleted on the server-side.");
    Assert.assertEquals(result.getStderr().trim(), expectedMsg, "Stderr expected after the consumer has been deleted on the server-side.");
    result = clienttasks.refresh_(null, null, null, null);
    Assert.assertEquals(result.getExitCode(), expectedExitCode, "Exitcode expected after the consumer has been deleted on the server-side.");
    Assert.assertEquals(result.getStdout().trim(), "", "Stdout expected after the consumer has been deleted on the server-side.");
    Assert.assertEquals(result.getStderr().trim(), expectedMsg, "Stderr expected after the consumer has been deleted on the server-side.");
    result = clienttasks.service_level_(null, null, null, null, null, null, null, null, null, null, null, null, null);
    Assert.assertEquals(result.getExitCode(), expectedExitCode, "Exitcode expected after the consumer has been deleted on the server-side.");
    Assert.assertEquals(result.getStdout().trim(), "", "Stdout expected after the consumer has been deleted on the server-side.");
    Assert.assertEquals(result.getStderr().trim(), expectedMsg, "Stderr expected after the consumer has been deleted on the server-side.");
    // Bug 798788:  Error updating system data, see /var/log/rhsm/rhsm.log for more details.
    result = clienttasks.facts_(null, true, null, null, null, null);
    // TEMPORARY WORKAROUND FOR BUG
    String bugId = "798788";
    boolean invokeWorkaroundWhileBugIsOpen = true;
    try {
        if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
            log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
        } else {
            invokeWorkaroundWhileBugIsOpen = false;
        }
    } catch (BugzillaAPIException be) {
    /* ignore exception */
    } catch (RuntimeException re) {
    /* ignore exception */
    }
    if (invokeWorkaroundWhileBugIsOpen) {
        log.warning("Skipping stderr assertion from subscription-manager facts --update.");
    } else {
        // END OF WORKAROUND
        Assert.assertEquals(result.getExitCode(), expectedExitCode, "Exitcode expected after the consumer has been deleted on the server-side.");
        Assert.assertEquals(result.getStdout().trim(), "", "Stdout expected after the consumer has been deleted on the server-side.");
        Assert.assertEquals(result.getStderr().trim(), expectedMsg, "Stderr expected after the consumer has been deleted on the server-side.");
    }
    result = clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
    Assert.assertEquals(result.getExitCode(), expectedExitCode, "Exitcode expected after the consumer has been deleted on the server-side.");
    // Assert.assertEquals(result.getStdout().trim(),expectedMsg,"Stdout expected after the consumer has been deleted on the server-side.");
    // Assert.assertEquals(result.getStderr().trim(),"",			"Stderr expected after the consumer has been deleted on the server-side.");
    Assert.assertEquals(result.getStdout().trim() + result.getStderr().trim(), expectedMsg, "Feedback expected after the consumer has been deleted on the server-side.");
    result = clienttasks.list_(null, true, null, null, null, null, null, null, null, null, null, null, null, null);
    // post commit 616ecda6db6ae8b054d7bbb8ba278bba242f4fd0 bug 1262989
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.16.4-1"))
        expectedExitCode = new Integer(69);
    // post commit 5c48d059bb07b64b92722f249b38aaee7219ab47 bug 1262989
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.16.3-1"))
        expectedMsg = String.format("This consumer's profile has been deleted from the server. You can use command clean or unregister to remove local profile.", consumerCert.consumerid);
    // post commit 3ad13c20f6ab34cf2621bc48cdd7d15a82791d4f bug 1262989
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.16.5-1"))
        expectedMsg = String.format("Consumer profile \"%s\" has been deleted from the server. You can use command clean or unregister to remove local profile.", consumerCert.consumerid);
    Assert.assertEquals(result.getExitCode(), expectedExitCode, "Exitcode expected after the consumer has been deleted on the server-side.");
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.9-1")) {
        // post commit a695ef2d1da882c5f851fde90a24f957b70a63ad
        Assert.assertEquals(result.getStdout().trim(), "", "Stdout expected after the consumer has been deleted on the server-side.");
        Assert.assertEquals(result.getStderr().trim(), expectedMsg, "Stderr expected after the consumer has been deleted on the server-side.");
    } else {
        Assert.assertEquals(result.getStdout().trim(), expectedMsg, "Stdout expected after the consumer has been deleted on the server-side.");
        Assert.assertEquals(result.getStderr().trim(), "", "Stderr expected after the consumer has been deleted on the server-side.");
    }
    result = clienttasks.subscribe_(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
    Assert.assertEquals(result.getExitCode(), expectedExitCode, "Exitcode expected after the consumer has been deleted on the server-side.");
    // Assert.assertEquals(result.getStdout().trim(),expectedMsg,"Stdout expected after the consumer has been deleted on the server-side.");
    // Assert.assertEquals(result.getStderr().trim(),"",			"Stderr expected after the consumer has been deleted on the server-side.");
    Assert.assertEquals(result.getStdout().trim() + result.getStderr().trim(), expectedMsg, "Feedback expected after the consumer has been deleted on the server-side.");
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.16.3-1")) {
        // pre commit 5c48d059bb07b64b92722f249b38aaee7219ab47 bug 1262989 which causes a call to unregister to effectively clean the local consumer cert
        result = clienttasks.unregister_(null, null, null, null);
        Assert.assertEquals(result.getExitCode(), expectedExitCode, "Exitcode expected after the consumer has been deleted on the server-side.");
        if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.9-1")) {
            // post commit a695ef2d1da882c5f851fde90a24f957b70a63ad
            Assert.assertEquals(result.getStdout().trim(), "", "Stdout expected after the consumer has been deleted on the server-side.");
            Assert.assertEquals(result.getStderr().trim(), expectedMsg, "Stderr expected after the consumer has been deleted on the server-side.");
        } else {
            Assert.assertEquals(result.getStdout().trim(), expectedMsg, "Stdout expected after the consumer has been deleted on the server-side.");
            Assert.assertEquals(result.getStderr().trim(), "", "Stderr expected after the consumer has been deleted on the server-side.");
        }
    }
    // restart rhsmcertd
    // assertCertificatesUpdate=false since the consumer has been deleted server side and the cert updates should fail
    clienttasks.restart_rhsmcertd(null, null, false);
    // assert that the consumer has been backed up and assert the md5sum matches
    String consumerCertFileOld = clienttasks.consumerCertFile().replace(clienttasks.consumerCertDir, clienttasks.consumerCertDir + ".old");
    String consumerCertKeyOld = clienttasks.consumerKeyFile().replace(clienttasks.consumerCertDir, clienttasks.consumerCertDir + ".old");
    Assert.assertTrue(RemoteFileTasks.testExists(client, consumerCertFileOld), "For emergency recovery after rhsmcertd triggers, the server-side deleted consumer cert should be copied to: " + consumerCertFileOld);
    Assert.assertTrue(RemoteFileTasks.testExists(client, consumerCertKeyOld), "For emergency recovery after rhsmcertd triggers, the server-side deleted consumer key should be copied to: " + consumerCertKeyOld);
    Assert.assertEquals(client.runCommandAndWait("md5sum " + consumerCertFileOld).getStdout().replaceAll(consumerCertFileOld, "").trim(), consumerCert_md5sum.replaceAll(clienttasks.consumerCertFile(), "").trim(), "After the deleted consumer cert is backed up, its md5sum matches that from the original consumer cert.");
    Assert.assertEquals(client.runCommandAndWait("md5sum " + consumerCertKeyOld).getStdout().replaceAll(consumerCertKeyOld, "").trim(), consumerKey_md5sum.replaceAll(clienttasks.consumerKeyFile(), "").trim(), "After the deleted consumer key is backed up, its md5sum matches that from the original consumer key.");
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.16.3-1")) {
        // post commit 5c48d059bb07b64b92722f249b38aaee7219ab47 bug 1262989 which causes a call to unregister to effectively clean the local consumer cert
        // no longer throws an exception when consumer has been deleted consumer side - no reason to - just cleans the local consumer cert
        clienttasks.unregister(null, null, null, null);
    }
    // assert that the system is no longer registered and no entitlements remain
    result = clienttasks.identity_(null, null, null, null, null, null, null, null);
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.8-1")) {
        // post commit df95529a5edd0be456b3528b74344be283c4d258 bug 1119688
        Assert.assertEquals(result.getStderr().trim(), clienttasks.msg_ConsumerNotRegistered, "The system should no longer be registered after rhsmcertd triggers following a server-side consumer deletion.");
    } else {
        Assert.assertEquals(result.getStdout().trim(), clienttasks.msg_ConsumerNotRegistered, "The system should no longer be registered after rhsmcertd triggers following a server-side consumer deletion.");
    }
    Assert.assertTrue(clienttasks.getCurrentEntitlementCertFiles().isEmpty(), "The system should no longer have any entitlements after rhsmcertd triggers following a server-side consumer deletion.");
    // assert that the clienttasks.consumerCertDir remains, but the cert.pem and key.pem are gone
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.10.14-1")) {
        Assert.assertTrue(RemoteFileTasks.testExists(client, clienttasks.consumerCertDir), "The original consumer cert dir '" + clienttasks.consumerCertDir + "' should remain after it has been backed up to: " + clienttasks.consumerCertDir + ".old");
        Assert.assertTrue(!RemoteFileTasks.testExists(client, clienttasks.consumerCertFile()), "After rhsmcertd triggers, the consumer cert '" + clienttasks.consumerCertFile() + "' should have been deleted.");
        Assert.assertTrue(!RemoteFileTasks.testExists(client, clienttasks.consumerKeyFile()), "After rhsmcertd triggers, the consumer key '" + clienttasks.consumerKeyFile() + "' should have been deleted.");
    }
}
Also used : BigInteger(java.math.BigInteger) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) BigInteger(java.math.BigInteger) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SubscriptionPool(rhsm.data.SubscriptionPool) File(java.io.File) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Aggregations

ConsumerCert (rhsm.data.ConsumerCert)24 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)23 Test (org.testng.annotations.Test)23 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)21 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)12 SkipException (org.testng.SkipException)12 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)9 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)8 SubscriptionPool (rhsm.data.SubscriptionPool)7 ProductSubscription (rhsm.data.ProductSubscription)6 EntitlementCert (rhsm.data.EntitlementCert)5 Calendar (java.util.Calendar)4 File (java.io.File)3 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3 InstalledProduct (rhsm.data.InstalledProduct)3 ProductCert (rhsm.data.ProductCert)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2