Ejemplo n.º 1
0
    def test_serialize_unknown(self):
        """Serialises an unknown value"""
        class unknown(object):
            pass

        with self.assertRaises(ValueError):
            serialize(unknown())
Ejemplo n.º 2
0
    def test_serialize_unknown(self):
        """Serialises an unknown value"""
        class unknown(object):
            pass

        with self.assertRaises(ValueError):
            serialize(unknown())
Ejemplo n.º 3
0
def serialize0():
    """Serialises an unknown value"""
    class unknown(object):
        pass

    with assert_exception(ValueError):
        serialize(unknown())
Ejemplo n.º 4
0
def serialize5():
    """Serialises datetime instances"""
    assert_eq(
        '<object class="java.util.Date">'
            '<long>0</long>'
        '</object>',
        tostring(serialize(datetime.strptime('1970-01-01 UTC', '%Y-%m-%d %Z'))))

    assert_eq(
        '<object class="java.util.Date">'
            '<long>86400000</long>'
        '</object>',
        tostring(serialize(datetime.strptime('1970-01-02 UTC', '%Y-%m-%d %Z'))))
Ejemplo n.º 5
0
def serialize2():
    """Serialises a class with an unknown property"""
    class unknown(object):
        pass

    class has_unknown(object):
        bean_class = 'test.class'
        @property
        def a(self):
            return unknown()

    with assert_exception(ValueError):
        serialize(has_unknown())
Ejemplo n.º 6
0
    def test_serialize_unknown_property(self):
        """Serialises a class with an unknown property"""
        class unknown(object):
            pass

        class has_unknown(object):
            bean_class = 'test.class'

            @property
            def test_a(self):
                return unknown()

        with self.assertRaises(ValueError):
            serialize(has_unknown())
Ejemplo n.º 7
0
    def test_serialize_unknown_property(self):
        """Serialises a class with an unknown property"""
        class unknown(object):
            pass

        class has_unknown(object):
            bean_class = 'test.class'

            @property
            def test_a(self):
                return unknown()

        with self.assertRaises(ValueError):
            serialize(has_unknown())
Ejemplo n.º 8
0
    def test_serialize_datetime(self):
        """Serialises datetime instances"""
        self.assertEqual(
            '<object class="java.util.Date">'
            '<long>0</long>'
            '</object>',
            tostring(serialize(
                datetime.strptime('1970-01-01 UTC', '%Y-%m-%d %Z'))))

        self.assertEqual(
            '<object class="java.util.Date">'
            '<long>86400000</long>'
            '</object>',
            tostring(serialize(
                datetime.strptime('1970-01-02 UTC', '%Y-%m-%d %Z'))))
Ejemplo n.º 9
0
    def test_serialize_datetime(self):
        """Serialises datetime instances"""
        self.assertEqual(
            '<object class="java.util.Date">'
            '<long>0</long>'
            '</object>',
            tostring(
                serialize(datetime.strptime('1970-01-01 UTC', '%Y-%m-%d %Z'))))

        self.assertEqual(
            '<object class="java.util.Date">'
            '<long>86400000</long>'
            '</object>',
            tostring(
                serialize(datetime.strptime('1970-01-02 UTC', '%Y-%m-%d %Z'))))
Ejemplo n.º 10
0
 def test_signature_algorithm_valid_non_default_signature_algo(self):
     """Tests License() for valid, non-default signature_algorithm"""
     License(
         to_document(serialize(
             LicenseData('2014-01-01T00:00:00', '2014-01-01T00:00:01'))),
         '<signature>',
         signature_algorithm='HELLOwithWORLD')
Ejemplo n.º 11
0
 def test_signature_algorithm_valid_non_default_signature_algo(self):
     """Tests License() for valid, non-default signature_algorithm"""
     License(to_document(
         serialize(LicenseData('2014-01-01T00:00:00',
                               '2014-01-01T00:00:01'))),
             '<signature>',
             signature_algorithm='HELLOwithWORLD')
Ejemplo n.º 12
0
def License_signature_algorithm0():
    """Tests License() for invalid signature_algorithm"""
    with assert_exception(ValueError):
        License(to_document(serialize(
            LicenseData('2014-01-01T00:00:00', '2014-01-01T00:00:01'))),
        '<signature>',
        signature_algorithm = 'invalid')
Ejemplo n.º 13
0
    def test_serialize_empty_class(self):
        """Serialises an empty class"""
        class empty(object):
            bean_class = 'test.class'

        self.assertEqual('<object class="test.class" />',
                         tostring(serialize(empty())))
Ejemplo n.º 14
0
    def test_to_document(self):
        """Tests that todocument creates a valid XML document"""
        expected = 'hello world'

        self.assertEqual(
            expected,
            deserialize(fromstring(to_document(serialize(expected)))[0]))
Ejemplo n.º 15
0
def License_signature_encoding0():
    """Tests License() for invalid signature_encoding"""
    with assert_exception(ValueError):
        License(to_document(serialize(
            LicenseData('2014-01-01T00:00:00', '2014-01-01T00:00:01'))),
        '<signature>',
        signature_encoding = 'UTF-8/Base64')
Ejemplo n.º 16
0
 def test_encoded_valid(self):
     """Tests that License() with valid encoded data has correct encoded
     value"""
     License(
         to_document(serialize(
             LicenseData('2014-01-01T00:00:00', '2014-01-01T00:00:01'))),
         '<signature>')
Ejemplo n.º 17
0
def LicenseData_deserialize():
    """Tests that a LicenseData can be serialised to XML"""
    license_data1 = LicenseData(
        '2014-01-01T00:00:00',
        '2014-01-01T00:00:01',
        '2014-01-01T00:00:01',
        issuer = 'CN=issuer',
        subject = 'subject',
        info = 'some information',
        extra = {'hello': 'world'})
    license_data2 = deserialize(serialize(license_data1))
    assert_eq(
        license_data1.not_before,
        license_data2.not_before)
    assert_eq(
        license_data1.not_after,
        license_data2.not_after)
    assert_eq(
        license_data1.issued,
        license_data2.issued)
    assert_eq(
        license_data1.issuer,
        license_data2.issuer)
    assert_eq(
        license_data1.subject,
        license_data2.subject)
    assert_eq(
        license_data1.info,
        license_data2.info)
    assert_eq(
        license_data1.extra,
        license_data2.extra)
Ejemplo n.º 18
0
def serialize4():
    """Serialises an object"""
    class test(object):
        bean_class = 'test.class'
        @property
        def z(self):
            return True
        @property
        def last(self):
            return 42
        @property
        def first(self):
            return 'hello world'

    assert_eq(
        '<object class="test.class">'
            '<void property="first">'
                '<string>hello world</string>'
            '</void>'
            '<void property="last">'
                '<int>42</int>'
            '</void>'
            '<void property="z">'
                '<boolean>true</boolean>'
            '</void>'
        '</object>',
        tostring(serialize(test())))
Ejemplo n.º 19
0
    def test_serialize_empty_class(self):
        """Serialises an empty class"""
        class empty(object):
            bean_class = 'test.class'

        self.assertEqual(
            '<object class="test.class" />',
            tostring(serialize(empty())))
Ejemplo n.º 20
0
def License_signature_encoding0():
    """Tests License() for invalid signature_encoding"""
    with assert_exception(ValueError):
        License(to_document(
            serialize(LicenseData('2014-01-01T00:00:00',
                                  '2014-01-01T00:00:01'))),
                '<signature>',
                signature_encoding='UTF-8/Base64')
Ejemplo n.º 21
0
def License_signature_algorithm0():
    """Tests License() for invalid signature_algorithm"""
    with assert_exception(ValueError):
        License(to_document(
            serialize(LicenseData('2014-01-01T00:00:00',
                                  '2014-01-01T00:00:01'))),
                '<signature>',
                signature_algorithm='invalid')
Ejemplo n.º 22
0
def Name_serialize0():
    """Tests that a name can be serialised to XML"""
    s = 'CN=#3Ctoken#3E , O=organisation '

    assert_eq(
        '<object class="javax.security.auth.x500.X500Principal">'
        '<string>CN=#3Ctoken#3E,O=organisation</string>'
        '</object>', tostring(serialize(Name(s))))
Ejemplo n.º 23
0
    def test_create_from_list(self):
        """Tests that a name can be created from a list"""
        s = [('CN', '<token>'), ('O', 'organisation')]

        self.assertEqual(
            '<object class="javax.security.auth.x500.X500Principal">'
            '<string>CN=#3Ctoken#3E,O=organisation</string>'
            '</object>', tostring(serialize(Name(s))))
Ejemplo n.º 24
0
 def test_create_from_name(self):
     """Tests that a name can be created from a cryptography.x509.Name"""
     self.assertEqual(
         '<object class="javax.security.auth.x500.X500Principal">'
         '<string>C=XX,ST=Some-State,L=Madeupville,O=Internet Widgits Pty '
         'Ltd,OU=Loafing dept.</string>'
         '</object>',
         tostring(serialize(Name.from_x509_name(self.certificate.subject))))
Ejemplo n.º 25
0
 def test_encoded_valid(self):
     """Tests that License() with valid encoded data has correct encoded
     value"""
     License(
         to_document(
             serialize(
                 LicenseData('2014-01-01T00:00:00',
                             '2014-01-01T00:00:01'))), '<signature>')
Ejemplo n.º 26
0
 def test_create_from_name(self):
     """Tests that a name can be created from a cryptography.x509.Name"""
     self.assertEqual(
         '<object class="javax.security.auth.x500.X500Principal">'
         '<string>C=XX,ST=Some-State,L=Madeupville,O=Internet Widgits Pty '
         'Ltd,OU=Loafing dept.</string>'
         '</object>',
         tostring(serialize(Name.from_x509_name(self.certificate.subject))))
Ejemplo n.º 27
0
def serialize1():
    """Serialises an empty class"""
    class empty(object):
        bean_class = 'test.class'

    assert_eq(
        '<object class="test.class" />',
        tostring(serialize(empty())))
Ejemplo n.º 28
0
    def test_serialize(self):
        """Tests that a name can be serialised to XML"""
        s = 'CN=#3Ctoken#3E , O=organisation '

        self.assertEqual(
            '<object class="javax.security.auth.x500.X500Principal">'
            '<string>CN=#3Ctoken#3E,O=organisation</string>'
            '</object>',
            tostring(serialize(Name(s))))
Ejemplo n.º 29
0
    def test_create_from_list(self):
        """Tests that a name can be created from a list"""
        s = [('CN', '<token>'), ('O', 'organisation')]

        self.assertEqual(
            '<object class="javax.security.auth.x500.X500Principal">'
            '<string>CN=#3Ctoken#3E,O=organisation</string>'
            '</object>',
            tostring(serialize(Name(s))))
Ejemplo n.º 30
0
 def test_signature_encoding_invalid(self):
     """Tests License() for invalid signature_encoding"""
     with self.assertRaises(ValueError):
         License(to_document(
             serialize(
                 LicenseData('2014-01-01T00:00:00',
                             '2014-01-01T00:00:01'))),
                 '<signature>',
                 signature_encoding='UTF-8/Base64')
Ejemplo n.º 31
0
 def test_signature_algorithm_invalid(self):
     """Tests License() for invalid signature_algorithm"""
     with self.assertRaises(ValueError):
         License(to_document(
             serialize(
                 LicenseData('2014-01-01T00:00:00',
                             '2014-01-01T00:00:01'))),
                 '<signature>',
                 signature_algorithm='invalid')
Ejemplo n.º 32
0
 def test_signature_encoding_invalid(self):
     """Tests License() for invalid signature_encoding"""
     with self.assertRaises(ValueError):
         License(
             to_document(serialize(
                 LicenseData(
                     '2014-01-01T00:00:00',
                     '2014-01-01T00:00:01'))),
             '<signature>',
             signature_encoding='UTF-8/Base64')
Ejemplo n.º 33
0
 def test_signature_algorithm_invalid(self):
     """Tests License() for invalid signature_algorithm"""
     with self.assertRaises(ValueError):
         License(
             to_document(serialize(
                 LicenseData(
                     '2014-01-01T00:00:00',
                     '2014-01-01T00:00:01'))),
             '<signature>',
             signature_algorithm='invalid')
Ejemplo n.º 34
0
def to_document0():
    """Tests that to_document creates a valid XML document"""
    expected = 'hello world'

    assert_eq(
        expected,
        deserialize(
            fromstring(
                to_document(
                    serialize(expected)))
            [0]))
Ejemplo n.º 35
0
    def test_to_document(self):
        """Tests that todocument creates a valid XML document"""
        expected = 'hello world'

        self.assertEqual(
            expected,
            deserialize(
                fromstring(
                    to_document(
                        serialize(expected)))
                [0]))
Ejemplo n.º 36
0
 def test_serialize(self):
     """Tests that a LicenseData can be serialised to XML"""
     expected = tostring(
         fromstring(
             '<object class="de.schlichtherle.license.LicenseContent">'
             '<void property="consumerType"><string /></void>'
             '<void property="extra">'
             '<string>{"hello": "world"}</string>'
             '</void>'
             '<void property="holder">'
             '<object class="javax.security.auth.x500.X500Principal">'
             '<string>CN=Unknown</string>'
             '</object>'
             '</void>'
             '<void property="info">'
             '<string>some information</string>'
             '</void>'
             '<void property="issued">'
             '<object class="java.util.Date">'
             '<long>1388534401000</long>'
             '</object>'
             '</void>'
             '<void property="issuer">'
             '<object class="javax.security.auth.x500.X500Principal">'
             '<string>CN=issuer</string>'
             '</object>'
             '</void>'
             '<void property="notAfter">'
             '<object class="java.util.Date">'
             '<long>1388534401000</long>'
             '</object>'
             '</void>'
             '<void property="notBefore">'
             '<object class="java.util.Date">'
             '<long>1388534400000</long>'
             '</object>'
             '</void>'
             '<void property="subject">'
             '<string>CN=subject</string>'
             '</void>'
             '</object>'))
     self.assertEqual(
         expected,
         tostring(
             serialize(
                 LicenseData('2014-01-01T00:00:00',
                             '2014-01-01T00:00:01',
                             '2014-01-01T00:00:01',
                             issuer='CN=issuer',
                             subject='CN=subject',
                             info='some information',
                             extra={'hello': 'world'}))))
Ejemplo n.º 37
0
 def test_serialize(self):
     """Tests that a LicenseData can be serialised to XML"""
     expected = tostring(fromstring(
         '<object class="de.schlichtherle.license.LicenseContent">'
         '<void property="consumerType"><string /></void>'
         '<void property="extra">'
         '<string>{"hello": "world"}</string>'
         '</void>'
         '<void property="holder">'
         '<object class="javax.security.auth.x500.X500Principal">'
         '<string>CN=Unknown</string>'
         '</object>'
         '</void>'
         '<void property="info">'
         '<string>some information</string>'
         '</void>'
         '<void property="issued">'
         '<object class="java.util.Date">'
         '<long>1388534401000</long>'
         '</object>'
         '</void>'
         '<void property="issuer">'
         '<object class="javax.security.auth.x500.X500Principal">'
         '<string>CN=issuer</string>'
         '</object>'
         '</void>'
         '<void property="notAfter">'
         '<object class="java.util.Date">'
         '<long>1388534401000</long>'
         '</object>'
         '</void>'
         '<void property="notBefore">'
         '<object class="java.util.Date">'
         '<long>1388534400000</long>'
         '</object>'
         '</void>'
         '<void property="subject">'
         '<string>CN=subject</string>'
         '</void>'
         '</object>'))
     self.assertEqual(
         expected,
         tostring(serialize(LicenseData(
             '2014-01-01T00:00:00',
             '2014-01-01T00:00:01',
             '2014-01-01T00:00:01',
             issuer='CN=issuer',
             subject='CN=subject',
             info='some information',
             extra={'hello': 'world'}))))
Ejemplo n.º 38
0
    def test_serialize_object(self):
        """Serialises an object"""
        class test(object):
            bean_class = 'test.class'

            @property
            def test_property(self):
                return True

        self.assertEqual(
            '<object class="test.class">'
            '<void property="testProperty">'
            '<boolean>true</boolean>'
            '</void>'
            '</object>', tostring(serialize(test())))
Ejemplo n.º 39
0
    def test_serialize_object(self):
        """Serialises an object"""
        class test(object):
            bean_class = 'test.class'

            @property
            def test_property(self):
                return True

        self.assertEqual(
            '<object class="test.class">'
            '<void property="testProperty">'
            '<boolean>true</boolean>'
            '</void>'
            '</object>',
            tostring(serialize(test())))
Ejemplo n.º 40
0
 def test_deserialize(self):
     """Tests that a LicenseData can be serialised to XML"""
     license_data1 = LicenseData('2014-01-01T00:00:00',
                                 '2014-01-01T00:00:01',
                                 '2014-01-01T00:00:01',
                                 issuer='CN=issuer',
                                 subject='subject',
                                 info='some information',
                                 extra={'hello': 'world'})
     license_data2 = deserialize(serialize(license_data1))
     self.assertEqual(license_data1.not_before, license_data2.not_before)
     self.assertEqual(license_data1.not_after, license_data2.not_after)
     self.assertEqual(license_data1.issued, license_data2.issued)
     self.assertEqual(license_data1.issuer, license_data2.issuer)
     self.assertEqual(license_data1.subject, license_data2.subject)
     self.assertEqual(license_data1.info, license_data2.info)
     self.assertEqual(license_data1.extra, license_data2.extra)
Ejemplo n.º 41
0
 def test_deserialize_datetime(self):
     """Deserialises datetime objects"""
     expected = datetime.strptime('2014-01-01 UTC', '%Y-%m-%d %Z')
     self.assertEqual(expected, deserialize(serialize(expected)))
Ejemplo n.º 42
0
 def test_serialize_string(self):
     """Serialises a string"""
     self.assertEqual('<string>hello world</string>',
                      tostring(serialize('hello world')))
Ejemplo n.º 43
0
 def test_deserialize_datetime(self):
     """Deserialises datetime objects"""
     expected = datetime.strptime('2014-01-01 UTC', '%Y-%m-%d %Z')
     self.assertEqual(
         expected,
         deserialize(serialize(expected)))
Ejemplo n.º 44
0
 def test_serialize_string(self):
     """Serialises a string"""
     self.assertEqual(
         '<string>hello world</string>',
         tostring(serialize('hello world')))
Ejemplo n.º 45
0
def serialize3():
    """Serialises a string"""
    assert_eq(
        '<string>hello world</string>',
        tostring(serialize('hello world')))
Ejemplo n.º 46
0
def deserialize4():
    """Deserialises datetime objects"""
    expected = datetime.strptime('2014-01-01 UTC', '%Y-%m-%d %Z')
    assert_eq(
        expected,
        deserialize(serialize(expected)))