Example #1
0
 def logout(self):
     """Release the AFS token."""
     if not get_bool('AFS_AKIMPERSONATE'):
         kdestroy = get_var('KDESTROY')
         krb5cc = "/tmp/afsrobot.krb5cc"
         cmd = "KRB5CCNAME=%s %s" % (krb5cc, kdestroy)
         rc, out, err = run_program(cmd)
         if rc:
             raise AssertionError("kdestroy failed: '%s'; exit code = %d" %
                                  (cmd, rc))
     unlog = get_var('UNLOG')
     rc, out, err = run_program(unlog)
     if rc:
         raise AssertionError("unlog failed: '%s'; exit code = %d" %
                              (unlog, rc))
Example #2
0
 def command_should_succeed(self, cmd, msg=None):
     """Fails if command does not exit with a zero status code."""
     rc,out,err = run_program(cmd)
     if rc != 0:
         if not msg:
             msg = "Command Failed! %s" % cmd
         raise AssertionError(msg)
 def command_should_fail(self, cmd):
     """Fails if command exits with a zero status code."""
     rc, out, err = run_program(cmd)
     logger.info("Output: " + out)
     logger.info("Error: " + err)
     logger.info("Code: %d" % rc)
     if rc == 0:
         raise AssertionError("Command should have failed: %s" % cmd)
 def command_should_succeed(self, cmd, msg=None):
     """Fails if command does not exit with a zero status code."""
     rc, out, err = run_program(cmd)
     logger.info("Output: " + out)
     logger.info("Error: " + err)
     if rc != 0:
         if not msg:
             msg = "Command Failed! %s" % cmd
         raise AssertionError(msg)
Example #5
0
def akimpersonate(user):
    """Acquire an AFS token for authenticated access without Kerberos."""
    if not user:
        raise AssertionError("User name is required")
    aklog = get_var('AKLOG')
    cell = get_var('AFS_CELL')
    realm = get_var('KRB_REALM')
    keytab = get_var('KRB_AFS_KEYTAB')
    principal = get_principal(user, realm)
    cmd = "%s -d -c %s -k %s -keytab %s -principal %s" % (aklog, cell, realm,
                                                          keytab, principal)
    rc, out, err = run_program(cmd)
    if rc:
        raise AssertionError("aklog failed: '%s'; exit code = %d" % (cmd, rc))
Example #6
0
def login_with_keytab(user, keytab):
    """Acquire an AFS token for authenticated access with Kerberos."""
    if not user:
        raise ValueError("User name is required.")
    if not keytab:
        raise ValueError("keytab is required.")
    kinit = get_var('KINIT')
    aklog = get_var('AKLOG')
    cell = get_var('AFS_CELL')
    realm = get_var('KRB_REALM')
    principal = get_principal(user, realm)
    logger.info("keytab: " + keytab)
    if not os.path.exists(keytab):
        raise AssertionError("Keytab file '%s' is missing." % keytab)
    krb5cc = "/tmp/afsrobot.krb5cc"
    cmd = "KRB5CCNAME=%s %s -5 -k -t %s %s" % (krb5cc, kinit, keytab,
                                               principal)
    rc, out, err = run_program(cmd)
    if rc:
        raise AssertionError("kinit failed: '%s'; exit code = %d" % (cmd, rc))
    cmd = "KRB5CCNAME=%s %s -d -c %s -k %s" % (krb5cc, aklog, cell, realm)
    rc, out, err = run_program(cmd)
    if rc:
        raise AssertionError("kinit failed: '%s'; exit code = %d" % (cmd, rc))
Example #7
0
def login_with_password(user, password):
    """Acquire a Kerberos ticket and AFS token with a password."""
    if not user:
        raise AssertionError("user is required")
    if not password:
        raise AssertionError("password is required")
    klog_krb5 = get_var('KLOG_KRB5')
    cell = get_var('AFS_CELL')
    realm = get_var('KRB_REALM')
    cmd = "%s -principal %s -password %s -cell %s -k %s" % (
        klog_krb5, user, password, cell, realm)
    rc, out, err = run_program(cmd)
    if rc:
        raise AssertionError("klog.krb5 failed: '%s'; exit code = %d" %
                             (cmd, rc))
Example #8
0
 def command_should_fail(self, cmd):
     """Fails if command exits with a zero status code."""
     rc,out,err = run_program(cmd)
     if rc == 0:
         raise AssertionError("Command should have failed: %s" % cmd)