Exemplo n.º 1
0
    def testGPGVerify(self):
        """Test the GPG Verify method."""
        conf = {'gpg_fingerprint': 'AAA', 'gpg': True}
        source = zsyncsource.ZSyncSource(conf)
        self.mox.StubOutWithMock(curl, 'CurlFetch')
        curl.CurlFetch('remote_sig', source.conn, source.log).AndReturn(
            (200, 'headers', 'body'))

        sig = 1
        signed = 2
        self.mox.StubOutWithMock(pyme.core, 'Data')
        pyme.core.Data('body').AndReturn(sig)
        pyme.core.Data(file='local_file').AndReturn(signed)

        result = self.mox.CreateMockAnything()
        result.signatures = [self.mox.CreateMockAnything()]
        result.signatures[0].fpr = 'AAA'
        key_mock = self.mox.CreateMockAnything()
        key_mock.uids = [self.mox.CreateMockAnything()]
        key_mock.uids[0].uid = 'Foobar'
        context = self.mox.CreateMockAnything()
        context.op_verify(sig, signed, None)
        context.op_verify_result().AndReturn(result)
        context.get_key('AAA', 0).AndReturn(key_mock)

        self.mox.ReplayAll()

        self.assertTrue(source._GPGVerify('local_file', 'remote_sig', context))
Exemplo n.º 2
0
 def testDefaults(self):
     """Test that we set the expected defaults for HTTP connections."""
     source = zsyncsource.ZSyncSource({})
     self.assertEquals(source.conf['passwd_url'],
                       zsyncsource.ZSyncSource.PASSWD_URL)
     self.assertEquals(source.conf['shadow_url'],
                       zsyncsource.ZSyncSource.SHADOW_URL)
     self.assertEquals(source.conf['group_url'],
                       zsyncsource.ZSyncSource.GROUP_URL)
     self.assertEquals(source.conf['retry_max'],
                       zsyncsource.ZSyncSource.RETRY_MAX)
     self.assertEquals(source.conf['retry_delay'],
                       zsyncsource.ZSyncSource.RETRY_DELAY)
     self.assertEquals(source.conf['tls_cacertfile'],
                       zsyncsource.ZSyncSource.TLS_CACERTFILE)
     self.assertEquals(source.conf['zsync_suffix'],
                       zsyncsource.ZSyncSource.ZSYNC_SUFFIX)
     self.assertEquals(source.conf['automount_base_url'],
                       zsyncsource.ZSyncSource.AUTOMOUNT_BASE_URL)
     self.assertEquals(source.conf['gpg_pubkeyfile'],
                       zsyncsource.ZSyncSource.GPG_PUBKEYFILE)
     self.assertEquals(source.conf['gpg'], zsyncsource.ZSyncSource.GPG)
     self.assertEquals(source.conf['gpg_suffix'],
                       zsyncsource.ZSyncSource.GPG_SUFFIX)
     self.assertEquals(source.conf['http_proxy'], None)
Exemplo n.º 3
0
    def testGetFileGPG(self):
        """Test the GetFile method with gpg verification."""
        remote = 'https://www/nss_cache'
        local = '/tmp/nss_cache'
        current_file = '/etc/nss_cache'

        self.mox.StubOutWithMock(os.path, 'exists')
        os.path.exists(current_file).AndReturn(True)
        os.path.exists(local).AndReturn(True)

        zsync_object_mock = self.mox.CreateMock(zsync.Zsync)
        zsync_object_mock.Begin(remote + '.zsync')
        zsync_object_mock.SubmitSource(current_file)
        zsync_object_mock.Fetch(local)
        self.mox.StubOutWithMock(zsync, 'Zsync')
        zsync.Zsync(conn=mox.IgnoreArg(), retry_delay=5,
                    retry_max=3).AndReturn(zsync_object_mock)

        source = zsyncsource.ZSyncSource({'gpg': True})

        self.mox.StubOutWithMock(source, '_GPGVerify')
        source._GPGVerify(local, remote + '.asc').AndReturn(True)

        self.mox.ReplayAll()

        self.assertEquals(local, source._GetFile(remote, local, current_file))
Exemplo n.º 4
0
    def testGetFileNoGPGEmptyMap(self):
        """Test the GetFile method with an empty map."""
        remote = 'https://www/nss_cache'
        local = '/tmp/nss_cache'
        current_file = '/etc/nss_cache'

        self.mox.StubOutWithMock(os.path, 'exists')
        os.path.exists(current_file).AndReturn(True)
        os.path.exists(local).AndReturn(False)

        zsync_mock = self.mox.CreateMockAnything()
        zsync_mock.Begin(remote + '.zsync')
        zsync_mock.SubmitSource(current_file)
        zsync_mock.Fetch(local)

        self.mox.StubOutWithMock(zsync, 'Zsync')
        zsync.Zsync(conn=mox.IgnoreArg(), retry_delay=5,
                    retry_max=3).AndReturn(zsync_mock)

        source = zsyncsource.ZSyncSource({})

        self.mox.ReplayAll()

        self.assertRaises(error.EmptyMap, source._GetFile, remote, local,
                          current_file)
Exemplo n.º 5
0
 def testOverrideDefaults(self):
     """Test that we override the defaults for HTTP connections."""
     source = zsyncsource.ZSyncSource(self.config)
     self.assertEquals(source.conf['passwd_url'], 'PASSWD_URL')
     self.assertEquals(source.conf['group_url'], 'GROUP_URL')
     self.assertEquals(source.conf['shadow_url'], 'SHADOW_URL')
     self.assertEquals(source.conf['retry_delay'], 'TEST_RETRY_DELAY')
     self.assertEquals(source.conf['retry_max'], 'TEST_RETRY_MAX')
     self.assertEquals(source.conf['tls_cacertfile'], 'TEST_TLS_CACERTFILE')
     self.assertEquals(source.conf['automount_base_url'],
                       'AUTOMOUNT_BASE_URL')
     self.assertEquals(source.conf['gpg'], 'GPG')
     self.assertEquals(source.conf['gpg_pubkeyfile'], 'GPG_PUBKEYFILE')
     self.assertEquals(source.conf['zsync_suffix'], 'ZSYNC_SUFFIX')
     self.assertEquals(source.conf['gpg_suffix'], 'GPG_SUFFIX')
     self.assertEquals(source.conf['http_proxy'], 'HTTP_PROXY')
Exemplo n.º 6
0
    def testGetFileGPGFail(self):
        """Test the GetFile method with gpg verification failing."""
        # TODO(jaq): the duplicate calls in this test indicate that GetFileViaZsync is bad.
        remote = 'https://www/nss_cache'
        local = '/tmp/nss_cache'
        current_file = '/etc/nss_cache'

        self.mox.StubOutWithMock(os.path, 'exists')
        os.path.exists(current_file).AndReturn(True)
        os.path.exists(local).AndReturn(True)
        os.path.exists(local).AndReturn(True)

        zsync_mock1 = self.mox.CreateMock(zsync.Zsync)
        zsync_mock1.Begin(remote + '.zsync')
        zsync_mock1.SubmitSource(current_file)
        zsync_mock1.Fetch(local)

        zsync_mock2 = self.mox.CreateMock(zsync.Zsync)
        zsync_mock2.Begin(remote + '.zsync')
        zsync_mock2.Fetch(local)

        self.mox.StubOutWithMock(zsync, 'Zsync')
        zsync.Zsync(conn=mox.IgnoreArg(), retry_delay=5,
                    retry_max=3).AndReturn(zsync_mock1)
        zsync.Zsync(conn=mox.IgnoreArg(), retry_delay=5,
                    retry_max=3).AndReturn(zsync_mock2)

        source = zsyncsource.ZSyncSource({'gpg': True})

        self.mox.StubOutWithMock(source, '_GPGVerify')
        source._GPGVerify(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False)
        source._GPGVerify(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(False)

        self.mox.ReplayAll()

        self.assertRaises(error.InvalidMap, source._GetFile, remote, local,
                          current_file)