示例#1
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 conftest.open():
            cert.get_id.return_value = 1

            path = os.path.join('var', 'certs')
            x = FSCertStore(path)
            assert 1 in x._certs
            glob.assert_called_with(os.path.join(path, '*'))

            # they both end up with the same id
            glob.return_value = ['foo.cert', 'bar.cert']
            with pytest.raises(SecurityError):
                x = FSCertStore(path)
            glob.return_value = ['foo.cert']

            cert.has_expired.return_value = True
            with pytest.raises(SecurityError):
                x = FSCertStore(path)

            isdir.return_value = False
            with pytest.raises(SecurityError):
                x = FSCertStore(path)
    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')
            assert 1 in x._certs
            glob.assert_called_with('/var/certs/*')

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

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

            isdir.return_value = False
            with pytest.raises(SecurityError):
                x = FSCertStore('/var/certs')
示例#3
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")
示例#4
0
def register_auth(key=None,
                  cert=None,
                  store=None,
                  digest='sha1',
                  serializer='json'):
    """Register security serializer."""
    s = SecureSerializer(key and PrivateKey(key),
                         cert and Certificate(cert),
                         store and FSCertStore(store),
                         digest=digest,
                         serializer=serializer)
    registry.register('auth',
                      s.serialize,
                      s.deserialize,
                      content_type='application/data',
                      content_encoding='utf-8')