Esempio n. 1
0
    def test_process_request_noapp(self):
        """Test processing ticket request."""
        treadmill.zkutils.get.side_effect = kazoo.client.NoNodeError
        tkt_locker = locker.TicketLocker(kazoo.client.KazooClient(),
                                         '/var/spool/tickets')

        # With no node node error, result will be empty dict.
        self.assertEqual({},
                         tkt_locker.process_request('host/[email protected]',
                                                    'foo#1234'))
Esempio n. 2
0
    def locker_cmd(tkt_spool_dir, trusted, no_register):
        """Run ticket locker daemon."""
        trusted_apps = {}
        for hostname, app, tkts in trusted:
            tkts = list(set(tkts.split(',')))
            _LOGGER.info('Trusted: %s/%s : %r', hostname, app, tkts)
            trusted_apps[(hostname, app)] = tkts

        tkt_locker = locker.TicketLocker(context.GLOBAL.zk.conn,
                                         tkt_spool_dir,
                                         trusted=trusted_apps)
        locker.run_server(tkt_locker, register=(not no_register))
Esempio n. 3
0
    def test_process_trusted(self):
        """Test processing trusted app."""
        tkt_locker = locker.TicketLocker(kazoo.client.KazooClient(),
                                         self.tkt_dir,
                                         trusted={
                                             ('aaa.xxx.com', 'master'):
                                             ['x@r1']
                                         })
        with io.open(os.path.join(self.tkt_dir, 'x@r1'), 'w+') as f:
            f.write('x')

        # base64 encoded 'x'.
        self.assertEqual({'x@r1': b'eA=='},
                         tkt_locker.process_request('host/[email protected]',
                                                    'master'))
Esempio n. 4
0
    def test_process_request(self):
        """Test processing ticket request."""
        treadmill.zkutils.get.return_value = {'tickets': ['tkt1']}
        tkt_locker = locker.TicketLocker(kazoo.client.KazooClient(),
                                         '/var/spool/tickets')

        # With no ticket in /var/spool/tickets, result will be empty dict
        self.assertEqual({},
                         tkt_locker.process_request('host/[email protected]',
                                                    'foo#1234'))

        kazoo.client.KazooClient.exists.assert_called_with(
            '/placement/aaa.xxx.com/foo#1234')

        # Invalid (non host) principal
        self.assertEqual(
            None, tkt_locker.process_request('*****@*****.**', 'foo#1234'))