You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_rawsocket_url.py 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ###############################################################################
  2. #
  3. # The MIT License (MIT)
  4. #
  5. # Copyright (c) Crossbar.io Technologies GmbH
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8. # of this software and associated documentation files (the "Software"), to deal
  9. # in the Software without restriction, including without limitation the rights
  10. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. # copies of the Software, and to permit persons to whom the Software is
  12. # furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in
  15. # all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. # THE SOFTWARE.
  24. #
  25. ###############################################################################
  26. from __future__ import absolute_import
  27. import unittest
  28. from autobahn.rawsocket.util import create_url, parse_url
  29. class TestCreateRsUrl(unittest.TestCase):
  30. def test_create_url01(self):
  31. self.assertEqual(create_url("localhost"), "rs://localhost:80")
  32. def test_create_url02(self):
  33. self.assertEqual(create_url("localhost", port=8090), "rs://localhost:8090")
  34. def test_create_url03(self):
  35. self.assertEqual(create_url("localhost", isSecure=True), "rss://localhost:443")
  36. def test_create_url04(self):
  37. self.assertEqual(create_url("localhost", isSecure=True, port=443), "rss://localhost:443")
  38. def test_create_url05(self):
  39. self.assertEqual(create_url("localhost", isSecure=True, port=80), "rss://localhost:80")
  40. def test_create_url06(self):
  41. self.assertEqual(create_url("unix", port="file.sock"), "rs://unix:file.sock")
  42. def test_create_url07(self):
  43. self.assertEqual(create_url("unix", port="/tmp/file.sock"), "rs://unix:/tmp/file.sock")
  44. def test_create_url08(self):
  45. self.assertEqual(create_url("unix", port="../file.sock"), "rs://unix:../file.sock")
  46. def test_create_url09(self):
  47. self.assertEqual(create_url("unix", isSecure=True, port="file.sock"), "rss://unix:file.sock")
  48. def test_create_url10(self):
  49. self.assertEqual(create_url("unix", isSecure=True, port="/tmp/file.sock"), "rss://unix:/tmp/file.sock")
  50. def test_create_url11(self):
  51. self.assertEqual(create_url("unix", isSecure=True, port="../file.sock"), "rss://unix:../file.sock")
  52. class TestParseWsUrl(unittest.TestCase):
  53. # parse_url -> (isSecure, host, port)
  54. def test_parse_url01(self):
  55. self.assertEqual(parse_url("rs://localhost"), (False, 'localhost', 80))
  56. def test_parse_url02(self):
  57. self.assertEqual(parse_url("rss://localhost"), (True, 'localhost', 443))
  58. def test_parse_url03(self):
  59. self.assertEqual(parse_url("rs://localhost:9000"), (False, 'localhost', 9000))
  60. def test_parse_url04(self):
  61. self.assertEqual(parse_url("rss://localhost:9000"), (True, 'localhost', 9000))
  62. def test_parse_url05(self):
  63. self.assertRaises(Exception, parse_url, "ws://localhost")
  64. def test_parse_url06(self):
  65. self.assertRaises(Exception, parse_url, "wss://localhost")
  66. def test_parse_url07(self):
  67. self.assertRaises(Exception, parse_url, "ws://localhost:80")
  68. def test_parse_url08(self):
  69. self.assertRaises(Exception, parse_url, "rs://localhost/somepath")
  70. def test_parse_url09(self):
  71. self.assertRaises(Exception, parse_url, "rs://localhost#somefrag")
  72. def test_parse_url10(self):
  73. self.assertRaises(Exception, parse_url, "rs://localhost?foo=bar")
  74. def test_parse_url11(self):
  75. self.assertRaises(Exception, parse_url, "rss://")
  76. def test_parse_url12(self):
  77. self.assertRaises(Exception, parse_url, "rs://")
  78. def test_parse_url13(self):
  79. self.assertEqual(parse_url("rs://unix:file.sock"), (False, 'unix', 'file.sock'))
  80. def test_parse_url14(self):
  81. self.assertEqual(parse_url("rs://unix:/tmp/file.sock"), (False, 'unix', '/tmp/file.sock'))
  82. def test_parse_url15(self):
  83. self.assertEqual(parse_url("rs://unix:../file.sock"), (False, 'unix', '../file.sock'))
  84. def test_parse_url16(self):
  85. self.assertEqual(parse_url("rss://unix:file.sock"), (True, 'unix', 'file.sock'))
  86. def test_parse_url17(self):
  87. self.assertEqual(parse_url("rss://unix:/tmp/file.sock"), (True, 'unix', '/tmp/file.sock'))
  88. def test_parse_url18(self):
  89. self.assertEqual(parse_url("rss://unix:../file.sock"), (True, 'unix', '../file.sock'))