Example #1
0
  def testInstallCertInKeychainSuccessWithPassWithApp(self):
    """Test InstallCertInKeychain success, with passphrase and trusted app."""
    self.StubSetup()
    certs.logging.info('Installing downloaded key into the %s keychain',
                       'k').AndReturn(None)
    certs.tempfile.mkdtemp(prefix=mox.IgnoreArg()).AndReturn('tempdir')
    self.WriteFiles()
    command = [certs.CMD_SECURITY, 'import', 'tempdir/private.key', '-x',
               '-k', 'k', '-P', 'passphrase', '-T', 'trusted_app_path']
    certs.os.path.exists('trusted_app_path').AndReturn(True)
    certs.logging.debug('Command: %s', command).AndReturn(None)
    certs.gmacpyutil.RunProcess(command,
                                sudo=False,
                                sudo_password=None).AndReturn(('out', 'err', 0))
    certs.logging.debug('Private key installation output: %s',
                        'out').AndReturn(None)
    certs.shutil.rmtree('tempdir').AndReturn(None)
    certs.tempfile.mkdtemp(prefix=mox.IgnoreArg()).AndReturn('tempdir')
    certs.logging.info('Installing downloaded certificate into the %s keychain',
                       'k').AndReturn(None)
    command = [certs.CMD_SECURITY, 'import', 'tempdir/certificate.cer', '-x',
               '-k', 'k']
    certs.logging.debug('Command: %s', command).AndReturn(None)
    certs.gmacpyutil.RunProcess(command,
                                sudo=False,
                                sudo_password=None).AndReturn(('out', 'err', 0))
    certs.logging.debug('Certificate installation output: %s',
                        'out').AndReturn(None)
    certs.shutil.rmtree('tempdir').AndReturn(None)

    self.mox.ReplayAll()
    certs.InstallCertInKeychain('cert', 'key', keychain='k',
                                passphrase='passphrase',
                                trusted_app_path='trusted_app_path')
    self.mox.VerifyAll()
Example #2
0
  def testInstallCertInKeychainSuccessSystemKeychain(self):
    """Test InstallCertInKeychain success, system keychain."""
    self.StubSetup()
    certs.logging.info('Installing downloaded key into the %s keychain',
                       certs.SYSTEM_KEYCHAIN).AndReturn(None)
    certs.tempfile.mkdtemp(prefix=mox.IgnoreArg()).AndReturn('tempdir')
    self.WriteFiles()
    command = [certs.CMD_SECURITY, 'import', 'tempdir/private.key', '-x', '-k',
               certs.SYSTEM_KEYCHAIN, '-A']
    certs.logging.debug('Command: %s', command).AndReturn(None)
    certs.gmacpyutil.RunProcess(command,
                                sudo=True,
                                sudo_password=None).AndReturn(('out', 'err', 0))
    certs.logging.debug('Private key installation output: %s',
                        'out').AndReturn(None)
    certs.shutil.rmtree('tempdir').AndReturn(None)
    certs.tempfile.mkdtemp(prefix=mox.IgnoreArg()).AndReturn('tempdir')
    certs.logging.info('Installing downloaded certificate into the %s keychain',
                       certs.SYSTEM_KEYCHAIN).AndReturn(None)
    command = [certs.CMD_SECURITY, 'import', 'tempdir/certificate.cer', '-x',
               '-k', certs.SYSTEM_KEYCHAIN]
    certs.logging.debug('Command: %s', command).AndReturn(None)
    certs.gmacpyutil.RunProcess(command,
                                sudo=True,
                                sudo_password=None).AndReturn(('out', 'err', 0))
    certs.logging.debug('Certificate installation output: %s',
                        'out').AndReturn(None)
    certs.shutil.rmtree('tempdir').AndReturn(None)

    self.mox.ReplayAll()
    certs.InstallCertInKeychain('cert', 'key', keychain=certs.SYSTEM_KEYCHAIN)
    self.mox.VerifyAll()