def test_hash(self):
     with mock_open() as a:
         a.write('the quick brown fox\n')
         a.seek(0)
         A = file_hash('foo')
     with mock_open() as b:
         b.write('the quick brown bar\n')
         b.seek(0)
         B = file_hash('bar')
     self.assertNotEqual(A, B)
 def test_hash(self):
     with mock_open() as a:
         a.write('the quick brown fox\n')
         a.seek(0)
         A = file_hash('foo')
     with mock_open() as b:
         b.write('the quick brown bar\n')
         b.seek(0)
         B = file_hash('bar')
     self.assertNotEqual(A, B)
Exemple #3
0
 def test_read_pid_partially_written(self):
     with mock_open() as s:
         s.write('1816')
         s.seek(0)
         p = Pidfile('/var/pid')
         with self.assertRaises(ValueError):
             p.read_pid()
Exemple #4
0
 def test_read_pid_bogus_pidfile(self):
     with mock_open() as s:
         s.write('eighteensixteen\n')
         s.seek(0)
         p = Pidfile('/var/pid')
         with self.assertRaises(ValueError):
             p.read_pid()
Exemple #5
0
 def test_read_pid_partially_written(self):
     with mock_open() as s:
         s.write('1816')
         s.seek(0)
         p = Pidfile('/var/pid')
         with self.assertRaises(ValueError):
             p.read_pid()
Exemple #6
0
 def test_read_pid_raises_IOError(self):
     exc = IOError()
     exc.errno = errno.EAGAIN
     with mock_open(side_effect=exc):
         p = Pidfile('/var/pid')
         with self.assertRaises(IOError):
             p.read_pid()
Exemple #7
0
 def test_read_pid_bogus_pidfile(self):
     with mock_open() as s:
         s.write('eighteensixteen\n')
         s.seek(0)
         p = Pidfile('/var/pid')
         with self.assertRaises(ValueError):
             p.read_pid()
Exemple #8
0
 def test_read_pid_raises_IOError(self):
     exc = IOError()
     exc.errno = errno.EAGAIN
     with mock_open(side_effect=exc):
         p = Pidfile('/var/pid')
         with self.assertRaises(IOError):
             p.read_pid()
Exemple #9
0
    def test_setup_registry_complete(self, dis, reg, key='KEY', cert='CERT'):
        calls = [0]

        def effect(*args):
            try:
                m = Mock()
                m.read.return_value = 'B' if calls[0] else 'A'
                return m
            finally:
                calls[0] += 1

        with mock_open(side_effect=effect):
            with patch('celery.security.registry') as registry:
                store = Mock()
                setup_security(['json'], key, cert, store)
                dis.assert_called_with(['json'])
                reg.assert_called_with('A', 'B', store, 'sha1', 'json')
                registry._set_default_serializer.assert_called_with('auth')
Exemple #10
0
    def test_setup_registry_complete(self, dis, reg, key='KEY', cert='CERT'):
        calls = [0]

        def effect(*args):
            try:
                m = Mock()
                m.read.return_value = 'B' if calls[0] else 'A'
                return m
            finally:
                calls[0] += 1

        self.app.conf.task_serializer = 'auth'
        with mock_open(side_effect=effect):
            with patch('celery.security.registry') as registry:
                store = Mock()
                self.app.setup_security(['json'], key, cert, store)
                dis.assert_called_with(['json'])
                reg.assert_called_with('A', 'B', store, 'sha1', 'json')
                registry._set_default_serializer.assert_called_with('auth')
Exemple #11
0
    def test_setup_registry_complete(self, dis, reg, key="KEY", cert="CERT"):
        calls = [0]

        def effect(*args):
            try:
                m = Mock()
                m.read.return_value = "B" if calls[0] else "A"
                return m
            finally:
                calls[0] += 1

        self.app.conf.CELERY_TASK_SERIALIZER = "auth"
        with mock_open(side_effect=effect):
            with patch("celery.security.registry") as registry:
                store = Mock()
                self.app.setup_security(["json"], key, cert, store)
                dis.assert_called_with(["json"])
                reg.assert_called_with("A", "B", store, "sha1", "json")
                registry._set_default_serializer.assert_called_with("auth")
Exemple #12
0
    def test_init(self, Certificate, glob, isdir):
        cert = Certificate.return_value = Mock()
        cert.has_expired.return_value = False
        isdir.return_value = True
        glob.return_value = ['foo.cert']
        with mock_open():
            cert.get_id.return_value = 1
            x = FSCertStore('/var/certs')
            self.assertIn(1, x._certs)
            glob.assert_called_with('/var/certs/*')

            # they both end up with the same id
            glob.return_value = ['foo.cert', 'bar.cert']
            with self.assertRaises(SecurityError):
                x = FSCertStore('/var/certs')
            glob.return_value = ['foo.cert']

            cert.has_expired.return_value = True
            with self.assertRaises(SecurityError):
                x = FSCertStore('/var/certs')

            isdir.return_value = False
            with self.assertRaises(SecurityError):
                x = FSCertStore('/var/certs')
    def test_init(self, Certificate, glob, isdir):
        cert = Certificate.return_value = Mock()
        cert.has_expired.return_value = False
        isdir.return_value = True
        glob.return_value = ['foo.cert']
        with mock_open():
            cert.get_id.return_value = 1
            x = FSCertStore('/var/certs')
            self.assertIn(1, x._certs)
            glob.assert_called_with('/var/certs/*')

            # they both end up with the same id
            glob.return_value = ['foo.cert', 'bar.cert']
            with self.assertRaises(SecurityError):
                x = FSCertStore('/var/certs')
            glob.return_value = ['foo.cert']

            cert.has_expired.return_value = True
            with self.assertRaises(SecurityError):
                x = FSCertStore('/var/certs')

            isdir.return_value = False
            with self.assertRaises(SecurityError):
                x = FSCertStore('/var/certs')
Exemple #14
0
 def test_read_pid_raises_ENOENT(self):
     exc = IOError()
     exc.errno = errno.ENOENT
     with mock_open(side_effect=exc):
         p = Pidfile('/var/pid')
         self.assertIsNone(p.read_pid())
Exemple #15
0
 def test_read_pid_raises_ENOENT(self):
     exc = IOError()
     exc.errno = errno.ENOENT
     with mock_open(side_effect=exc):
         p = Pidfile('/var/pid')
         self.assertIsNone(p.read_pid())
Exemple #16
0
 def test_read_pid(self):
     with mock_open() as s:
         s.write('1816\n')
         s.seek(0)
         p = Pidfile('/var/pid')
         self.assertEqual(p.read_pid(), 1816)
Exemple #17
0
 def test_read_pid(self):
     with mock_open() as s:
         s.write('1816\n')
         s.seek(0)
         p = Pidfile('/var/pid')
         self.assertEqual(p.read_pid(), 1816)