Пример #1
0
    def test_store_ticket_expired(self):
        """Test storing invalid (expired) tickets.
        """
        tkt = tickets.Ticket('uid@realm', b'content')

        res = tickets.store_ticket(tkt, '/var/spool/tickets')

        self.assertFalse(res)
        treadmill.fs.symlink_safe.assert_not_called()
Пример #2
0
 def test_ticket_write_expired(self):
     """Tests expiration checking of ticket before writing to the file
     system.
     """
     tkt = tickets.Ticket('uid@realm', b'content')
     tkt_path = os.path.join(self.tkt_dir, 'x')
     tickets.krbcc_ok.return_value = False
     tkt.write(tkt_path)
     self.assertFalse(os.path.exists(tkt_path))
     treadmill.fs.rm_safe.assert_called_with(mock.ANY)
Пример #3
0
    def test_store_ticket(self):
        """Test storing tickets.
        """
        tkt = tickets.Ticket('uid@realm', b'content')

        res = tickets.store_ticket(tkt, '/var/spool/tickets')

        self.assertTrue(res)
        treadmill.fs.symlink_safe.assert_called_with('/var/spool/tickets/uid',
                                                     'uid@realm')
Пример #4
0
    def test_ticket_write(self):
        """Tests writing ticket to the file system.
        """
        tkt = tickets.Ticket('uid@realm', b'content')
        test_tkt_path = '/tmp/krb5cc_%d' % 3

        self.assertEqual(tkt.tkt_path, test_tkt_path)
        tkt.write()

        self.assertTrue(os.path.exists(test_tkt_path))
        treadmill.fs.rm_safe.assert_called_with(mock.ANY)
Пример #5
0
    def test_request_tickets(self):
        """Test parsing output of request_tickets."""
        treadmill.zkutils.connect.return_value = kazoo.client.KazooClient()
        kazoo.client.KazooClient.get_children.return_value = [
            'xxx.xx.com:1234', 'yyy.xx.com:1234'
        ]

        # base64.urlsafe_b64encode('abcd') : YWJjZA==
        lines = ['foo@bar:YWJjZA==', '']
        treadmill.gssapiprotocol.GSSAPILineClient.read.side_effect = (
            lambda: lines.pop(0))
        reply = tickets.request_tickets(kazoo.client.KazooClient(), 'myapp')
        self.assertEqual([tickets.Ticket('foo@bar', b'abcd')], reply)
Пример #6
0
    def test_ticket_copy(self):
        """Test copying tickets.
        """
        tkt = tickets.Ticket('uid@realm', b'content')
        test_tkt_path = os.path.join(self.tkt_dir, 'foo')
        # touch a ticket
        with io.open(tkt.tkt_path, 'wb'):
            pass

        tkt.copy(dst=test_tkt_path)

        self.assertTrue(os.path.exists(test_tkt_path))
        os.fchown.assert_called_with(mock.ANY, 3, -1)
        treadmill.fs.rm_safe.assert_called_with(mock.ANY)