Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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_cookiejar.py 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import unittest
  2. from websocket._cookiejar import SimpleCookieJar
  3. """
  4. test_cookiejar.py
  5. websocket - WebSocket client library for Python
  6. Copyright 2023 engn33r
  7. Licensed under the Apache License, Version 2.0 (the "License");
  8. you may not use this file except in compliance with the License.
  9. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. """
  17. class CookieJarTest(unittest.TestCase):
  18. def testAdd(self):
  19. cookie_jar = SimpleCookieJar()
  20. cookie_jar.add("")
  21. self.assertFalse(cookie_jar.jar, "Cookie with no domain should not be added to the jar")
  22. cookie_jar = SimpleCookieJar()
  23. cookie_jar.add("a=b")
  24. self.assertFalse(cookie_jar.jar, "Cookie with no domain should not be added to the jar")
  25. cookie_jar = SimpleCookieJar()
  26. cookie_jar.add("a=b; domain=.abc")
  27. self.assertTrue(".abc" in cookie_jar.jar)
  28. cookie_jar = SimpleCookieJar()
  29. cookie_jar.add("a=b; domain=abc")
  30. self.assertTrue(".abc" in cookie_jar.jar)
  31. self.assertTrue("abc" not in cookie_jar.jar)
  32. cookie_jar = SimpleCookieJar()
  33. cookie_jar.add("a=b; c=d; domain=abc")
  34. self.assertEqual(cookie_jar.get("abc"), "a=b; c=d")
  35. self.assertEqual(cookie_jar.get(None), "")
  36. cookie_jar = SimpleCookieJar()
  37. cookie_jar.add("a=b; c=d; domain=abc")
  38. cookie_jar.add("e=f; domain=abc")
  39. self.assertEqual(cookie_jar.get("abc"), "a=b; c=d; e=f")
  40. cookie_jar = SimpleCookieJar()
  41. cookie_jar.add("a=b; c=d; domain=abc")
  42. cookie_jar.add("e=f; domain=.abc")
  43. self.assertEqual(cookie_jar.get("abc"), "a=b; c=d; e=f")
  44. cookie_jar = SimpleCookieJar()
  45. cookie_jar.add("a=b; c=d; domain=abc")
  46. cookie_jar.add("e=f; domain=xyz")
  47. self.assertEqual(cookie_jar.get("abc"), "a=b; c=d")
  48. self.assertEqual(cookie_jar.get("xyz"), "e=f")
  49. self.assertEqual(cookie_jar.get("something"), "")
  50. def testSet(self):
  51. cookie_jar = SimpleCookieJar()
  52. cookie_jar.set("a=b")
  53. self.assertFalse(cookie_jar.jar, "Cookie with no domain should not be added to the jar")
  54. cookie_jar = SimpleCookieJar()
  55. cookie_jar.set("a=b; domain=.abc")
  56. self.assertTrue(".abc" in cookie_jar.jar)
  57. cookie_jar = SimpleCookieJar()
  58. cookie_jar.set("a=b; domain=abc")
  59. self.assertTrue(".abc" in cookie_jar.jar)
  60. self.assertTrue("abc" not in cookie_jar.jar)
  61. cookie_jar = SimpleCookieJar()
  62. cookie_jar.set("a=b; c=d; domain=abc")
  63. self.assertEqual(cookie_jar.get("abc"), "a=b; c=d")
  64. cookie_jar = SimpleCookieJar()
  65. cookie_jar.set("a=b; c=d; domain=abc")
  66. cookie_jar.set("e=f; domain=abc")
  67. self.assertEqual(cookie_jar.get("abc"), "e=f")
  68. cookie_jar = SimpleCookieJar()
  69. cookie_jar.set("a=b; c=d; domain=abc")
  70. cookie_jar.set("e=f; domain=.abc")
  71. self.assertEqual(cookie_jar.get("abc"), "e=f")
  72. cookie_jar = SimpleCookieJar()
  73. cookie_jar.set("a=b; c=d; domain=abc")
  74. cookie_jar.set("e=f; domain=xyz")
  75. self.assertEqual(cookie_jar.get("abc"), "a=b; c=d")
  76. self.assertEqual(cookie_jar.get("xyz"), "e=f")
  77. self.assertEqual(cookie_jar.get("something"), "")
  78. def testGet(self):
  79. cookie_jar = SimpleCookieJar()
  80. cookie_jar.set("a=b; c=d; domain=abc.com")
  81. self.assertEqual(cookie_jar.get("abc.com"), "a=b; c=d")
  82. self.assertEqual(cookie_jar.get("x.abc.com"), "a=b; c=d")
  83. self.assertEqual(cookie_jar.get("abc.com.es"), "")
  84. self.assertEqual(cookie_jar.get("xabc.com"), "")
  85. cookie_jar.set("a=b; c=d; domain=.abc.com")
  86. self.assertEqual(cookie_jar.get("abc.com"), "a=b; c=d")
  87. self.assertEqual(cookie_jar.get("x.abc.com"), "a=b; c=d")
  88. self.assertEqual(cookie_jar.get("abc.com.es"), "")
  89. self.assertEqual(cookie_jar.get("xabc.com"), "")
  90. if __name__ == "__main__":
  91. unittest.main()