Esempio 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)))
Esempio 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))
Esempio 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))
Esempio 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))
Esempio 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))
Esempio 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))
Esempio 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))
Esempio 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))
Esempio 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))
Esempio 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))))
Esempio 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))))
Esempio 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))))
Esempio 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))))
Esempio 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))
Esempio 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))
Esempio 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)
Esempio 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)
Esempio 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')
Esempio 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)))
Esempio 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')
Esempio 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'))
Esempio 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))
Esempio 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)))
Esempio 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')
Esempio 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')
Esempio 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')
Esempio 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'))
Esempio 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')
Esempio 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))
Esempio 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)))
Esempio 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)))
Esempio 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)))
Esempio 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)))
Esempio 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)))