-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow IPv6 literals as Matrix server names.
According to the spec, Matrix server names are allowed to be IP addresses, including IPv6 literals.
- Loading branch information
Showing
6 changed files
with
108 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,37 @@ | ||
from twisted.trial import unittest | ||
from sydent.util.stringutils import is_valid_hostname | ||
from sydent.util.stringutils import is_valid_matrix_server_name | ||
|
||
|
||
class UtilTests(unittest.TestCase): | ||
"""Tests Sydent utility functions.""" | ||
def test_is_valid_hostname(self): | ||
"""Tests that the is_valid_hostname function accepts only valid | ||
hostnames (or domain names), with optional port number. | ||
|
||
def test_is_valid_matrix_server_name(self): | ||
"""Tests that the is_valid_matrix_server_name function accepts only | ||
valid hostnames (or domain names), with optional port number. | ||
""" | ||
self.assertTrue(is_valid_matrix_server_name("9.9.9.9")) | ||
self.assertTrue(is_valid_matrix_server_name("9.9.9.9:4242")) | ||
self.assertTrue(is_valid_matrix_server_name("[::]")) | ||
self.assertTrue(is_valid_matrix_server_name("[::]:4242")) | ||
self.assertTrue(is_valid_matrix_server_name("[a:b:c::]:4242")) | ||
|
||
self.assertTrue(is_valid_matrix_server_name("example.com")) | ||
self.assertTrue(is_valid_matrix_server_name("EXAMPLE.COM")) | ||
self.assertTrue(is_valid_matrix_server_name("ExAmPlE.CoM")) | ||
self.assertTrue(is_valid_matrix_server_name("example.com:4242")) | ||
self.assertTrue(is_valid_matrix_server_name("localhost")) | ||
self.assertTrue(is_valid_matrix_server_name("localhost:9000")) | ||
self.assertTrue(is_valid_matrix_server_name("a.b.c.d:1234")) | ||
|
||
self.assertTrue(is_valid_hostname("example.com")) | ||
self.assertTrue(is_valid_hostname("EXAMPLE.COM")) | ||
self.assertTrue(is_valid_hostname("ExAmPlE.CoM")) | ||
self.assertTrue(is_valid_hostname("example.com:4242")) | ||
self.assertTrue(is_valid_hostname("localhost")) | ||
self.assertTrue(is_valid_hostname("localhost:9000")) | ||
self.assertTrue(is_valid_hostname("a.b:1234")) | ||
self.assertFalse(is_valid_matrix_server_name("[:::]")) | ||
self.assertFalse(is_valid_matrix_server_name("a:b:c::")) | ||
|
||
self.assertFalse(is_valid_hostname("example.com:65536")) | ||
self.assertFalse(is_valid_hostname("example.com:0")) | ||
self.assertFalse(is_valid_hostname("example.com:a")) | ||
self.assertFalse(is_valid_hostname("example.com:04242")) | ||
self.assertFalse(is_valid_hostname("example.com: 4242")) | ||
self.assertFalse(is_valid_hostname("example.com/example.com")) | ||
self.assertFalse(is_valid_hostname("example.com#example.com")) | ||
self.assertFalse(is_valid_matrix_server_name("example.com:65536")) | ||
self.assertFalse(is_valid_matrix_server_name("example.com:0")) | ||
self.assertFalse(is_valid_matrix_server_name("example.com:-1")) | ||
self.assertFalse(is_valid_matrix_server_name("example.com:a")) | ||
self.assertFalse(is_valid_matrix_server_name("example.com: ")) | ||
self.assertFalse(is_valid_matrix_server_name("example.com:04242")) | ||
self.assertFalse(is_valid_matrix_server_name("example.com: 4242")) | ||
self.assertFalse(is_valid_matrix_server_name("example.com/example.com")) | ||
self.assertFalse(is_valid_matrix_server_name("example.com#example.com")) |