An attempt at adding UDP support to aiosocks. Untested due to lack of server support.
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.
 
 

86 lines
1.9 KiB

  1. import pytest
  2. import aiosocks
  3. def test_socks4_auth1():
  4. with pytest.raises(ValueError):
  5. aiosocks.Socks4Auth(None)
  6. def test_socks4_auth2():
  7. auth = aiosocks.Socks4Auth('usr', encoding='ascii')
  8. assert auth.login == b'usr'
  9. def test_socks4_auth3():
  10. auth = aiosocks.Socks4Auth('usrё', encoding='utf-8')
  11. assert auth.login == b'usr\xd1\x91'
  12. def test_socks5_auth1():
  13. with pytest.raises(ValueError):
  14. aiosocks.Socks5Auth(None, '')
  15. def test_socks5_auth2():
  16. with pytest.raises(ValueError):
  17. aiosocks.Socks5Auth('', None)
  18. def test_socks5_auth3():
  19. auth = aiosocks.Socks5Auth('usr', 'pwd', encoding='ascii')
  20. assert auth.login == b'usr'
  21. assert auth.password == b'pwd'
  22. def test_socks5_auth4():
  23. auth = aiosocks.Socks5Auth('usrё', 'pwdё', encoding='utf-8')
  24. assert auth.login == b'usr\xd1\x91'
  25. assert auth.password == b'pwd\xd1\x91'
  26. def test_socks4_addr1():
  27. with pytest.raises(ValueError):
  28. aiosocks.Socks4Addr(None)
  29. def test_socks4_addr2():
  30. addr = aiosocks.Socks4Addr('localhost')
  31. assert addr.host == 'localhost'
  32. assert addr.port == 1080
  33. def test_socks4_addr3():
  34. addr = aiosocks.Socks4Addr('localhost', 1)
  35. assert addr.host == 'localhost'
  36. assert addr.port == 1
  37. def test_socks4_addr4():
  38. addr = aiosocks.Socks4Addr('localhost', None)
  39. assert addr.host == 'localhost'
  40. assert addr.port == 1080
  41. def test_socks5_addr1():
  42. with pytest.raises(ValueError):
  43. aiosocks.Socks5Addr(None)
  44. def test_socks5_addr2():
  45. addr = aiosocks.Socks5Addr('localhost')
  46. assert addr.host == 'localhost'
  47. assert addr.port == 1080
  48. def test_socks5_addr3():
  49. addr = aiosocks.Socks5Addr('localhost', 1)
  50. assert addr.host == 'localhost'
  51. assert addr.port == 1
  52. def test_socks5_addr4():
  53. addr = aiosocks.Socks5Addr('localhost', None)
  54. assert addr.host == 'localhost'
  55. assert addr.port == 1080