Ejemplo n.º 1
0
    def test_unescape_with_escape(self):
        """Tests that Name.unescape for escaped string returns the correct
        string"""
        s = 'hello, "world"; insert <token + value>'

        self.assertEqual(
            s, Name.unescape(Name.escape(s)))
Ejemplo n.º 2
0
def Name_escape1():
    """Tests that Name.escape for string needing escaping returns the correct
    string"""
    s = 'hello, "world"; insert <token + value>'
    expected = 'hello#2C #22world#22#3B insert #3Ctoken #2B value#3E'

    assert_eq(expected, Name.escape(s))
Ejemplo n.º 3
0
def Name_escape0():
    """Tests that Name.escape for string not needing escaping returns the input
    string"""
    s = 'hello world'
    expected = s

    assert_eq(expected, Name.escape(s))
Ejemplo n.º 4
0
def Name_escape1():
    """Tests that Name.escape for string needing escaping returns the correct
    string"""
    s = 'hello, "world"; insert <token + value>'
    expected = 'hello#2C #22world#22#3B insert #3Ctoken #2B value#3E'

    assert_eq(expected, Name.escape(s))
Ejemplo n.º 5
0
def Name_escape0():
    """Tests that Name.escape for string not needing escaping returns the input
    string"""
    s = 'hello world'
    expected = s

    assert_eq(expected, Name.escape(s))
Ejemplo n.º 6
0
    def test_escape_with_escape(self):
        """Tests that Name.escape for string needing escaping returns the
        correct string"""
        s = 'hello, "world"; insert <token + value>'
        expected = 'hello#2C #22world#22#3B insert #3Ctoken #2B value#3E'

        self.assertEqual(expected, Name.escape(s))
Ejemplo n.º 7
0
    def test_unescape_no_escape(self):
        """Tests that Name.unescape for unescaped string returns the input
        string"""
        s = 'hello world'
        expected = s

        self.assertEqual(expected, Name.unescape(s))
Ejemplo n.º 8
0
    def test_escape_no_escape(self):
        """Tests that Name.escape for string not needing escaping returns the
        input string"""
        s = 'hello world'
        expected = s

        self.assertEqual(expected, Name.escape(s))
Ejemplo n.º 9
0
    def test_unescape_no_escape(self):
        """Tests that Name.unescape for unescaped string returns the input
        string"""
        s = 'hello world'
        expected = s

        self.assertEqual(
            expected, Name.unescape(s))
Ejemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
0
    def test_escape_with_escape(self):
        """Tests that Name.escape for string needing escaping returns the
        correct string"""
        s = 'hello, "world"; insert <token + value>'
        expected = 'hello#2C #22world#22#3B insert #3Ctoken #2B value#3E'

        self.assertEqual(
            expected,
            Name.escape(s))
Ejemplo n.º 15
0
    def test_escape_no_escape(self):
        """Tests that Name.escape for string not needing escaping returns the
        input string"""
        s = 'hello world'
        expected = s

        self.assertEqual(
            expected,
            Name.escape(s))
Ejemplo n.º 16
0
def LicenseData_valid_issuer():
    """Test LicenseData() for valid issuer"""
    name = 'CN=name,O=organisation'
    expected = [('CN', 'name'), ('O', 'organisation')]
    unknown = Name(LicenseData.UNKNOWN_NAME)

    license = LicenseData('2014-01-01T00:00:00',
                          '2014-01-01T00:00:01',
                          issuer=name)
    assert_eq(expected, license.issuer)
    assert_eq(unknown, license.holder)
Ejemplo n.º 17
0
    def test_valid_holder(self):
        """Test LicenseData() for valid holder"""
        name = 'CN=name,O=organisation'
        expected = [('CN', 'name'), ('O', 'organisation')]
        unknown = Name(LicenseData.UNKNOWN_NAME)

        license = LicenseData('2014-01-01T00:00:00',
                              '2014-01-01T00:00:01',
                              holder=name)
        self.assertEqual(unknown, license.issuer)
        self.assertEqual(expected, license.holder)
Ejemplo n.º 18
0
def Name_invalid_string():
    """Tests that Name() from invalid string raises ValueError"""
    with assert_exception(ValueError):
        Name('CN=invalid escape sequence#01')
    with assert_exception(ValueError):
        Name('CN=valid escape sequence, no type')
Ejemplo n.º 19
0
def Name_str0():
    """Tests that str(Name()) return the input string"""
    s = 'CN=#3Ctoken#3E,O=organisation'
    assert_eq(s, str(Name(s)))
Ejemplo n.º 20
0
def Name_unescape2():
    """Tests that Name.unescape for escaped string with invalid escape seqienmce
    raises ValueError"""
    with assert_exception(ValueError):
        Name.unescape('#01')
Ejemplo n.º 21
0
def Name_valid_string():
    """Tests Name() from valid string returns the correct sequence"""
    assert_eq([('CN', '<token>'), ('O', 'organisation')],
              Name('CN=#3Ctoken#3E,O=organisation'))
Ejemplo n.º 22
0
def Name_unescape0():
    """Tests that Name.unescape for unescaped string returns the input string"""
    s = 'hello world'
    expected = s

    assert_eq(expected, Name.unescape(s))
Ejemplo n.º 23
0
def Name_unescape1():
    """Tests that Name.unescape for escaped string returns the correct string"""
    s = 'hello, "world"; insert <token + value>'

    assert_eq(s, Name.unescape(Name.escape(s)))
Ejemplo n.º 24
0
 def test_unescape_invalid_escape(self):
     """Tests that Name.unescape for escaped string with invalid escape seqienmce
     raises ValueError"""
     with self.assertRaises(ValueError):
         Name.unescape('#01')
Ejemplo n.º 25
0
def Name_unescape2():
    """Tests that Name.unescape for escaped string with invalid escape seqienmce
    raises ValueError"""
    with assert_exception(ValueError):
        Name.unescape('#01')
Ejemplo n.º 26
0
 def test_unescape_invalid_escape(self):
     """Tests that Name.unescape for escaped string with invalid escape seqienmce
     raises ValueError"""
     with self.assertRaises(ValueError):
         Name.unescape('#01')
Ejemplo n.º 27
0
 def test_valid_string(self):
     """Tests Name() from valid string returns the correct sequence"""
     self.assertEqual([('CN', '<token>'), ('O', 'organisation')],
                      Name('CN=#3Ctoken#3E,O=organisation'))
Ejemplo n.º 28
0
 def test_invalid_string(self):
     """Tests that Name() from invalid string raises ValueError"""
     with self.assertRaises(ValueError):
         Name('CN=invalid escape sequence#01')
     with self.assertRaises(ValueError):
         Name('CN=valid escape sequence, no type')
Ejemplo n.º 29
0
def Name_unescape0():
    """Tests that Name.unescape for unescaped string returns the input string"""
    s = 'hello world'
    expected = s

    assert_eq(expected, Name.unescape(s))
Ejemplo n.º 30
0
def Name_unescape1():
    """Tests that Name.unescape for escaped string returns the correct string"""
    s = 'hello, "world"; insert <token + value>'

    assert_eq(s, Name.unescape(Name.escape(s)))
Ejemplo n.º 31
0
def Name_str1():
    """Tests that str(Name()) return the input string with leading and trailing
    space stripped for values"""
    s = 'CN=#3Ctoken#3E , O=organisation '
    expected = 'CN=#3Ctoken#3E,O=organisation'
    assert_eq(expected, str(Name(s)))
Ejemplo n.º 32
0
    def test_unescape_with_escape(self):
        """Tests that Name.unescape for escaped string returns the correct
        string"""
        s = 'hello, "world"; insert <token + value>'

        self.assertEqual(s, Name.unescape(Name.escape(s)))
Ejemplo n.º 33
0
 def test_str(self):
     """Tests that str(Name()) return the input string"""
     s = 'CN=#3Ctoken#3E,O=organisation'
     self.assertEqual(s, str(Name(s)))
Ejemplo n.º 34
0
 def test_str_strip_space(self):
     """Tests that str(Name()) return the input string with leading and
     trailing space stripped for values"""
     s = 'CN=#3Ctoken#3E , O=organisation '
     expected = 'CN=#3Ctoken#3E,O=organisation'
     self.assertEqual(expected, str(Name(s)))