diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 975c115..c6321c5 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -1,6 +1,3 @@ -# This workflow will install Python dependencies, run tests and lint -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - name: Check Black on: @@ -16,7 +13,7 @@ jobs: strategy: matrix: python-version: - - "3.8" + - "3.12" steps: - uses: actions/checkout@v3.5.2 diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml index c4567dc..a8557b7 100644 --- a/.github/workflows/flake8.yml +++ b/.github/workflows/flake8.yml @@ -1,6 +1,3 @@ -# This workflow will install Python dependencies, run tests and lint -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - name: Check flake8 on: @@ -16,7 +13,7 @@ jobs: strategy: matrix: python-version: - - "3.8" + - "3.12" steps: - uses: actions/checkout@v3.5.2 diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 97c2125..2c9e352 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,7 +1,4 @@ -# This workflow will install Python dependencies, run tests and lint -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Check pytest +name: Run pytest on: push: @@ -11,12 +8,11 @@ on: pull_request: jobs: - check-pytest: + run-pytest: runs-on: ubuntu-latest strategy: matrix: - python-version: - - "3.8" + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3.5.2 diff --git a/docs/conf.py b/docs/conf.py index b4cc551..9ee9283 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,7 +24,7 @@ author = "Tayler J Porter" # The full version, including alpha/beta/rc tags -release = "2.0.0a1" +release = "2.0.0a3" master_doc = "index" diff --git a/pyVoIP/SIP/__init__.py b/pyVoIP/SIP/__init__.py index a039aa5..a1bcd7e 100644 --- a/pyVoIP/SIP/__init__.py +++ b/pyVoIP/SIP/__init__.py @@ -1,7 +1,3 @@ -from pyVoIP.SIP import error -from pyVoIP.SIP import client -from pyVoIP.SIP import message - __all__ = [ "error", "client", diff --git a/pyVoIP/VoIP/__init__.py b/pyVoIP/VoIP/__init__.py index 8149dde..736e626 100644 --- a/pyVoIP/VoIP/__init__.py +++ b/pyVoIP/VoIP/__init__.py @@ -1,6 +1 @@ -from pyVoIP.VoIP import call, phone, status - -CallState = call.CallState -VoIPCall = call.VoIPCall -PhoneStatus = status.PhoneStatus -VoIPPhone = phone.VoIPPhone +__all__ = ["call", "phone", "status"] diff --git a/pyVoIP/VoIP/phone.py b/pyVoIP/VoIP/phone.py index fa23ddd..9526736 100644 --- a/pyVoIP/VoIP/phone.py +++ b/pyVoIP/VoIP/phone.py @@ -1,7 +1,7 @@ from pyVoIP import RTP from pyVoIP.credentials import CredentialsManager from pyVoIP.SIP.client import SIPClient -from pyVoIP.SIP.message import SIPMessage, SIPStatus +from pyVoIP.SIP.message import SIPMessage, SIPMessageType, SIPStatus from pyVoIP.sock.sock import VoIPConnection from pyVoIP.sock.transport import TransportMode from pyVoIP.types import KEY_PASSWORD @@ -105,7 +105,7 @@ def callback( self, conn: VoIPConnection, request: SIPMessage ) -> Optional[str]: # debug("Callback: "+request.summary()) - if request.type == pyVoIP.SIPMessageType.REQUEST: + if request.type == SIPMessageType.REQUEST: # debug("This is a message") if request.method == "INVITE": self._callback_MSG_Invite(conn, request) diff --git a/pyVoIP/__init__.py b/pyVoIP/__init__.py index ff6720d..6ceacf2 100644 --- a/pyVoIP/__init__.py +++ b/pyVoIP/__init__.py @@ -2,7 +2,7 @@ __all__ = ["SIP", "RTP", "VoIP"] -version_info = (2, 0, "0a1") +version_info = (2, 0, "0a3") __version__ = ".".join([str(x) for x in version_info]) diff --git a/setup.py b/setup.py index 02fd0ee..f8f77d3 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="pyVoIP", - version="2.0.0a1", + version="2.0.0a3", description="PyVoIP is a pure python VoIP/SIP/RTP library.", long_description=long_description, long_description_content_type="text/markdown", diff --git a/tests/test_nat.py b/tests/test_nat.py new file mode 100644 index 0000000..3b3385c --- /dev/null +++ b/tests/test_nat.py @@ -0,0 +1,139 @@ +from pyVoIP.networking.nat import NAT, NATError +import pytest + + +@pytest.mark.parametrize( + "nat_settings,test_against,expected", + [ + # Test Remote Host + ( + { + "bind_ip": "10.0.0.4", + "network": "10.0.0.0/24", + "remote_hostname": "example.com", + }, + "8.8.8.8", + "example.com", + ), + ( + { + "bind_ip": "10.0.0.4", + "network": "10.0.0.0/24", + "remote_hostname": "example.com", + }, + "example.org", + "example.com", + ), + ( + { + "bind_ip": "10.0.0.4", + "network": "10.0.0.0/24", + "remote_hostname": "example.com", + }, + "10.0.1.1", + "example.com", + ), + ( + { + "bind_ip": "10.0.0.4", + "network": "10.0.0.0/16", + "remote_hostname": "example.com", + }, + "10.1.0.1", + "example.com", + ), + # Test Remote Host with Bind 0.0.0.0 + ( + { + "bind_ip": "0.0.0.0", + "network": "10.0.0.0/24", + "hostname": "10.0.0.4", + "remote_hostname": "example.com", + }, + "8.8.8.8", + "example.com", + ), + ( + { + "bind_ip": "0.0.0.0", + "network": "10.0.0.0/24", + "hostname": "10.0.0.4", + "remote_hostname": "example.com", + }, + "10.0.1.1", + "example.com", + ), + ( + { + "bind_ip": "0.0.0.0", + "network": "10.0.0.0/16", + "hostname": "10.0.0.4", + "remote_hostname": "example.com", + }, + "10.1.0.1", + "example.com", + ), + # Test Local Host + ( + { + "bind_ip": "10.0.0.4", + "network": "10.0.0.0/24", + }, + "10.0.0.10", + "10.0.0.4", + ), + ( + { + "bind_ip": "10.0.0.4", + "network": "10.0.0.0/16", + }, + "10.0.1.1", + "10.0.0.4", + ), + ( + { + "bind_ip": "10.0.0.4", + "network": "10.0.0.0/8", + }, + "10.1.1.1", + "10.0.0.4", + ), + # Test Local Host with Bind 0.0.0.0 + ( + { + "bind_ip": "0.0.0.0", + "network": "10.0.0.0/24", + "hostname": "10.0.0.4", + }, + "10.0.0.10", + "10.0.0.4", + ), + ( + { + "bind_ip": "0.0.0.0", + "network": "10.0.0.0/16", + "hostname": "10.0.0.4", + }, + "10.0.1.1", + "10.0.0.4", + ), + ( + { + "bind_ip": "0.0.0.0", + "network": "10.0.0.0/8", + "hostname": "10.0.0.4", + }, + "10.1.1.10", + "10.0.0.4", + ), + ], +) +def test_nat(nat_settings, test_against, expected): + nat = NAT(**nat_settings) + assert nat.get_host(test_against) == expected + + +def test_nat_error(): + nat = NAT("192.168.0.5", "192.168.0.0/24") + with pytest.raises(NATError): + nat.get_host("google.com")