use of com.redhat.qe.auto.tcms.ImplementsNitrateTest in project rhsm-qe by RedHatQE.
the class CertificateTests method testConsumerCertsAreNotAccessibleByNonRootUserUsingRct.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36641", "RHEL7-51452" }, 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 = "assert the rct cat-cert tool does not traceback when run as non-root user.", groups = { "Tier2Tests", "blockedByBug-1315901", "VerifyConsumerCertsAreNotAccessibleByNonRootUserUsingRct_Test", "blockedByBug-1503851" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testConsumerCertsAreNotAccessibleByNonRootUserUsingRct() {
if (clienttasks.isPackageVersion("python-rhsm", "<", "1.17.6-1")) {
// python-rhsm RHEL7.3 branch commit d21c8252b4bdcf2b57f316ecc604487a3ef6e2c2 1315901: Exception handling for PEM cert read
throw new SkipException("This test is not fixed in this version of python-rhsm. It was first fixed in python-rhsm-1.17.6-1");
}
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
// create a non root user
// as a precaution
deleteNonRootUser();
RemoteFileTasks.runCommandAndAssert(client, "useradd " + nonRootUser, 0);
// Before fix to Bug 1315901 - Stacktrace displayed when running rct against an inaccessible file
// [root@jsefler-6 ~]# su non-root-user --command "rct cat-cert /etc/pki/consumer/cert.pem"
// Traceback (most recent call last):
// File "/usr/bin/rct", line 49, in <module>
// sys.exit(abs(main() or 0))
// File "/usr/bin/rct", line 44, in main
// return RctCLI().main()
// File "/usr/share/rhsm/subscription_manager/cli.py", line 160, in main
// return cmd.main()
// File "/usr/share/rhsm/rct/commands.py", line 39, in main
// return_code = self._do_command()
// File "/usr/share/rhsm/rct/cert_commands.py", line 74, in _do_command
// cert = self._create_cert()
// File "/usr/share/rhsm/rct/cert_commands.py", line 43, in _create_cert
// return certificate.create_from_file(cert_file)
// File "/usr/lib64/python2.6/site-packages/rhsm/certificate.py", line 59, in create_from_file
// return _CertFactory().create_from_file(path)
// File "/usr/lib64/python2.6/site-packages/rhsm/certificate2.py", line 65, in create_from_file
// pem = open(path, 'r').read()
// IOError: [Errno 13] Permission denied: '/etc/pki/consumer/cert.pem'
// After fix to Bug 1315901 - Stacktrace displayed when running rct against an inaccessible file
// [root@jsefler-rhel7 ~]# su non-root-user --command 'rct cat-cert /etc/pki/consumer/cert.pem'
// Permission denied
String expectedStdout = "Permission denied";
Integer expectedExitCode = Integer.valueOf(1);
// Unable to read certificate file '/etc/pki/consumer/cert.pem': Error loading certificate: [Errno 13] Permission denied: '/etc/pki/consumer/cert.pem'
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.20.1-1")) {
// post commit f192653c46808239c2f193478c1dfeb55a6ee35c //Bug 1472715: Python module rhsm should never call exit()
expectedStdout = String.format("Unable to read certificate file '%s': Error loading certificate: [Errno 13] Permission denied: '%s'", consumerCert.file.getPath(), consumerCert.file.getPath());
expectedExitCode = Integer.valueOf(0);
}
// attempt to run command "rct cat-cert /etc/pki/consumer/cert.pem" as non-root-user
String command = "rct cat-cert " + consumerCert.file.getPath();
SSHCommandResult result = client.runCommandAndWait("su " + nonRootUser + " --command '" + command + "'");
// assert expected results
Assert.assertEquals(result.getExitCode(), expectedExitCode, "ExitCode from command '" + command + "' run as a non-root user.");
Assert.assertEquals(result.getStdout().trim(), expectedStdout, "Stdout from command '" + command + "' run as a non-root user.");
Assert.assertTrue(!result.getStderr().toLowerCase().contains("Traceback".toLowerCase()), "Stderr from command '" + command + "' run as a non-root user does not contain a traceback.");
// TEMPORARY WORKAROUND
if (clienttasks.redhatReleaseX.equals("6")) {
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1562412 - a DEBUG logging statement surfaces to stderr when trying to rct cat-cert a protected file as a non-root-user
String bugId = "1562412";
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("While bug '" + bugId + "' is open, we will skip the empty stderr assertion on RHEL6");
return;
}
}
// END OF WORKAROUND
Assert.assertEquals(result.getStderr().trim(), "", "Stderr from command '" + command + "' run as a non-root user.");
}
use of com.redhat.qe.auto.tcms.ImplementsNitrateTest in project rhsm-qe by RedHatQE.
the class CertificateTests method testBaseRHELProductCertVersionFromEachCDNReleaseVersion.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20028", "RHEL7-33082" }, 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 = "Verify that the base RHEL product certs on the CDN for each release correctly reflect the release version. For example, this affects users that want use subcription-manager release --set=6.3 to keep yum updates fixed to an older release.", groups = { "Tier1Tests", "VerifyBaseRHELProductCertVersionFromEachCDNReleaseVersion_Test" }, dataProvider = "VerifyBaseRHELProductCertVersionFromEachCDNReleaseVersion_TestData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testBaseRHELProductCertVersionFromEachCDNReleaseVersion(Object blockedByBug, String release, String rhelRepoUrl, File rhelEntitlementCertFile, File caCertFile) {
if (clienttasks.arch.equals("aarch64") && release.matches("7.0|7.1"))
throw new SkipException("This test variation for aarch64 against release '" + release + "' is blocked by CLOSED WONTFIX bug 1261163 https://bugzilla.redhat.com/show_bug.cgi?id=1261163");
File certFile = rhelEntitlementCertFile;
File keyFile = clienttasks.getEntitlementCertKeyFileCorrespondingToEntitlementCertFile(rhelEntitlementCertFile);
// determine the exact path to the productid on the CDN
// Repo URL: https://cdn.redhat.com/content/dist/rhel/server/6/$releasever/$basearch/os
// ProductId: https://cdn.redhat.com/content/dist/rhel/server/6/$releasever/$basearch/os/repodata/productid
String basearch = clienttasks.arch;
// releng content for these systems is published under arch i386
if (basearch.equals("i686") || basearch.equals("i586") || basearch.equals("i486"))
basearch = "i386";
String rhelRepoUrlToProductId = rhelRepoUrl.replace("$releasever", release).replace("$basearch", basearch) + "/repodata/productid";
// use the entitlement certificates to get the productid
File localProductIdFile = new File("/tmp/productid");
RemoteFileTasks.runCommandAndAssert(client, "wget -nv -O " + localProductIdFile + " --ca-certificate=" + caCertFile + " --certificate-type=PEM --certificate=" + certFile + " --private-key=" + keyFile + " --private-key-type=pem " + rhelRepoUrlToProductId, Integer.valueOf(0), null, "-> \"" + localProductIdFile + "\"");
// [root@dell-pe650-02 ~]# wget -nv -O /tmp/productid --ca-certificate=/etc/rhsm/ca/redhat-uep.pem --certificate-type=PEM --certificate=/etc/pki/entitlement/19553491962157768.pem --private-key=/etc/pki/entitlement/19553491962157768-key.pem --private-key-type=pem https://cdn.redhat.com/content/dist/rhel/server/6/6.1/x86_64/os/repodata/productid
// 2015-04-29 11:58:44 URL:https://cdn.redhat.com/content/dist/rhel/server/6/6.1/x86_64/os/repodata/productid [2163/2163] -> "/tmp/productid" [1]
// [root@dell-pe650-02 ~]# rct cat-cert /tmp/productid | grep -A8 "Product:"
// Product:
// ID: 69
// Name: Red Hat Enterprise Linux 6 Server
// Version: 6.1
// Arch: x86_64
// Tags: rhel-6,rhel-6-server
// Brand Type:
// Brand Name:
// create a ProductCert corresponding to the productid file
ProductCert productIdCert = clienttasks.getProductCertFromProductCertFile(localProductIdFile);
log.info("Actual product cert from CDN '" + rhelRepoUrlToProductId + "': " + productIdCert);
// assert the expected productIdCert release version
String expectedRelease = release;
if (!isFloat(expectedRelease)) {
// happens when release is 6Server
// in this case of 6Server, the newset release version should be expected (TODO, not sure this is entirely true)
expectedRelease = getNewestReleaseFromReleases(clienttasks.getCurrentlyAvailableReleases(null, null, null, null));
}
Assert.assertEquals(productIdCert.productNamespace.version, expectedRelease, "Version of the productid on the CDN at '" + rhelRepoUrlToProductId + "' that will be installed by the yum product-id plugin after setting the subscription-manager release to '" + release + "'.");
}
use of com.redhat.qe.auto.tcms.ImplementsNitrateTest in project rhsm-qe by RedHatQE.
the class MigrationTests method testRhnMigrateClassicToRhsmWithActivationKey.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20109", "RHEL7-51742" }, 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 = "Execute migration tool rhn-migrate-classic-to-rhsm with a valid activation-key (and a good org)", groups = { "Tier1Tests", "blockedByBug-1154375", "blockedByBug-1512948", "blockedByBug-1516832" }, enabled = true)
@ImplementsNitrateTest(caseId = 130765)
public void testRhnMigrateClassicToRhsmWithActivationKey() throws Exception {
if (clienttasks.isPackageVersion("subscription-manager", "<", "1.14.1-1"))
throw new SkipException("The --activation-key option was not implemented in this version of subscription-manager.");
// create a valid activation key
// randomly choose a valid available pool for this key
SubscriptionPool pool = getRandomListItem(availableSubscriptionPools);
// choose an activationKey name
String activationKeyName = String.format("activationKeyForOrg_%s_Pool_%s", clientOrgKey, pool.productId);
JSONObject jsonActivationKey = CandlepinTasks.createActivationKeyUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, clientOrgKey, activationKeyName, Arrays.asList(pool.poolId), null);
// register with the activation key
if (false) {
// debugTesting
clienttasks.register_(null, null, clientOrgKey, null, null, null, null, null, null, null, activationKeyName, null, null, null, true, null, null, null, null, null);
clienttasks.unregister_(null, null, null, null);
}
// TEMPORARY WORKAROUND FOR BUG
// Bug 1196416 - rhn-migrate-classic-to-rhsm with --activation-key option should not prompt for destination credentials
String bugId = "1196416";
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) {
testRhnMigrateClassicToRhsm(null, sm_rhnUsername, sm_rhnPassword, sm_rhnHostname, new ArrayList<String>(), "--activation-key=" + activationKeyName + " " + "--org=" + clientOrgKey, sm_rhnUsername, sm_rhnPassword, sm_clientUsername, sm_clientPassword, null, null, null);
} else
// call RhnMigrateClassicToRhsm_Test with rhsmUsername=null and rhsmPassword=null
// END OF WORKAROUND
// migrate from RHN Classic to RHSM using the activation key
testRhnMigrateClassicToRhsm(null, sm_rhnUsername, sm_rhnPassword, sm_rhnHostname, new ArrayList<String>(), "--activation-key=" + activationKeyName + " " + "--org=" + clientOrgKey, sm_rhnUsername, sm_rhnPassword, null, null, null, null, null);
// assert that the system is consuming the pool from the activation key.
List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
Assert.assertEquals(consumedProductSubscriptions.size(), 1, "Number of consumed subscriptions after migrating from RHN Classic to RHSM with activation key '" + activationKeyName + "'.");
Assert.assertEquals(consumedProductSubscriptions.get(0).poolId, pool.poolId, "The sole consumed subscription poolId after migrating from RHN Classic to RHSM with activation key '" + activationKeyName + "'.");
}
use of com.redhat.qe.auto.tcms.ImplementsNitrateTest in project rhsm-qe by RedHatQE.
the class MigrationTests method testRhnMigrateClassicToRhsmWithInvalidRhsmCredentials.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21890", "RHEL7-51746" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "Execute migration tool rhn-migrate-classic-to-rhsm with invalid RHSM credentials, but valid RHN credentials", groups = { "Tier3Tests", "blockedByBug-789008", "blockedByBug-807477", "blockedByBug-1052297" }, dependsOnMethods = {}, enabled = true)
@ImplementsNitrateTest(caseId = 136404)
public void testRhnMigrateClassicToRhsmWithInvalidRhsmCredentials() {
if (clienttasks.isPackageVersion("subscription-manager-migration", "<", "1.14.3-1"))
throw new SkipException("This test is implemented for subscription-manager-migration >= 1.14.3-1. See former RhnMigrateClassicToRhsmWithInvalidCredentials_Test.");
clienttasks.unregister(null, null, null, null);
// register to RHN Classic
String rhnSystemId = clienttasks.registerToRhnClassic(sm_rhnUsername, sm_rhnPassword, sm_rhnHostname);
Assert.assertTrue(clienttasks.isRhnSystemIdRegistered(sm_rhnUsername, sm_rhnPassword, sm_rhnHostname, rhnSystemId), "Confirmed that rhn systemId '" + rhnSystemId + "' is currently registered.");
String rhsmUsername = null, rhsmPassword = null, rhsmOrg = null;
if (sm_serverType.equals(CandlepinType.hosted))
throw new SkipException("This test is not functionally possible when migrating from RHN Classic to an RHSM Hosted entitlement server because the credentials are assumed to be equivalent; the customer account is the same.");
if (!sm_serverType.equals(CandlepinType.hosted)) {
rhsmUsername = "foo";
rhsmPassword = "bar";
}
SSHCommandResult sshCommandResult = executeRhnMigrateClassicToRhsm(null, sm_rhnUsername, sm_rhnPassword, rhsmUsername, rhsmPassword, rhsmOrg, null, null);
Assert.assertEquals(sshCommandResult.getExitCode(), new Integer(70), /*EX_SOFTWARE*/
"The expected exit code from call to '" + rhnMigrateTool + "' with invalid RHSM credentials.");
// Assert.assertContainsMatch(sshCommandResult.getStdout(), "Unable to connect to certificate server. See "+clienttasks.rhsmLogFile+" for more details.", "The expected stdout result from call to "+rhnMigrateTool+" with invalid credentials."); // valid prior to bug fix 789008
String expectedStdout = "Unable to connect to certificate server: " + servertasks.invalidCredentialsMsg() + ". See " + clienttasks.rhsmLogFile + " for more details.";
Assert.assertTrue(sshCommandResult.getStdout().trim().endsWith(expectedStdout), "The expected stdout result from call to '" + rhnMigrateTool + "' with invalid RHSM credentials ended with: " + expectedStdout);
}
use of com.redhat.qe.auto.tcms.ImplementsNitrateTest in project rhsm-qe by RedHatQE.
the class MigrationTests method testRhnMigrateClassicToRhsmWithInvalidCredentials.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-26763", "RHEL7-98220" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "Execute migration tool rhn-migrate-classic-to-rhsm with invalid credentials", groups = { "Tier3Tests", "blockedByBug-789008", "blockedByBug-807477", "blockedByBug-1052297" }, dependsOnMethods = {}, enabled = true)
@ImplementsNitrateTest(caseId = 136404)
public void testRhnMigrateClassicToRhsmWithInvalidCredentials() {
if (clienttasks.isPackageVersion("subscription-manager-migration", ">=", "1.14.3-1"))
throw new SkipException("This test was implemented for subscription-manager-migration < 1.14.3-1. See replacement RhnMigrateClassicToRhsmWithInvalidRhsmCredentials_Test.");
clienttasks.unregister(null, null, null, null);
String rhsmUsername = null, rhsmPassword = null, rhsmOrg = null;
if (!sm_serverType.equals(CandlepinType.hosted)) {
rhsmUsername = "foo";
rhsmPassword = "bar";
}
SSHCommandResult sshCommandResult = executeRhnMigrateClassicToRhsm(null, "foo", "bar", rhsmUsername, rhsmPassword, rhsmOrg, null, null);
Assert.assertEquals(sshCommandResult.getExitCode(), new Integer(1), "The expected exit code from call to '" + rhnMigrateTool + "' with invalid credentials.");
// Assert.assertContainsMatch(sshCommandResult.getStdout(), "Unable to connect to certificate server. See "+clienttasks.rhsmLogFile+" for more details.", "The expected stdout result from call to "+rhnMigrateTool+" with invalid credentials."); // valid prior to bug fix 789008
String expectedStdout = "Unable to connect to certificate server: " + servertasks.invalidCredentialsMsg() + ". See " + clienttasks.rhsmLogFile + " for more details.";
Assert.assertTrue(sshCommandResult.getStdout().trim().endsWith(expectedStdout), "The expected stdout result from call to '" + rhnMigrateTool + "' with invalid credentials ended with: " + expectedStdout);
}
Aggregations