-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] Added pytest and tests for SIP authentication header parsing.
[ADD] Added black checks for tests. [CHANGE] Changed auth_match compile to use r-string to fix deprecation. [CHANGE] Removed version pinning from requirements-test. [CHANGE] Ran black over setup.py
- Loading branch information
1 parent
234e6b0
commit 87e8d50
Showing
7 changed files
with
94 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 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 | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
- "development" | ||
pull_request: | ||
|
||
jobs: | ||
check-pytest: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: | ||
- "3.7" | ||
|
||
steps: | ||
- uses: actions/checkout@v3.0.2 | ||
with: | ||
fetch-depth: 2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4.0.0 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -e . -r requirements-test.txt | ||
- name: pytest | ||
run: pytest |
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 +1,2 @@ | ||
black==22.8.0 | ||
black | ||
pytest |
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from pyVoIP.SIP import SIPMessage | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"packet,expected", | ||
[ | ||
( | ||
b"""SIP/2.0 401 Unauthorized\r\nVia: SIP/2.0/UDP 0.0.0.0:5060;branch=z9hG4bK03150189fc65493a9d4e3a582;rport=5060;received=192.168.178.110\r\nFrom: "tarantulla" <sip:tarantulla@192.168.178.1>;tag=9338abd3\r\nTo: "tarantulla" <sip:tarantulla@192.168.178.1>;tag=950C00889AC0DB3B\r\nCall-ID: 6b86b273ff34fce19d6b804eff5a3f57@0.0.0.0:5060\r\nCSeq: 1 REGISTER\r\nWWW-Authenticate: Digest realm="fritz.box", nonce="78B29326485EAE52"\r\nUser-Agent: FRITZ!OS\r\nContent-Length: 0\r\n\r\n""", | ||
{"realm": "fritz.box", "nonce": "78B29326485EAE52"}, | ||
), | ||
( | ||
b"""SIP/2.0 401 Unauthorized\r\nVia: SIP/2.0/UDP 0.0.0.0:5060;branch=z9hG4bK03150189fc65493a9d4e3a582;rport=5060;received=192.168.178.110\r\nFrom: "tarantulla" <sip:tarantulla@192.168.178.1>;tag=9338abd3\r\nTo: "tarantulla" <sip:tarantulla@192.168.178.1>;tag=950C00889AC0DB3B\r\nCall-ID: 6b86b273ff34fce19d6b804eff5a3f57@0.0.0.0:5060\r\nCSeq: 1 REGISTER\r\nWWW-Authenticate: Digest algorithm=MD5,realm="local",nonce="111111:222222aaaaaa333333bbbbbb444444"\r\nUser-Agent: FRITZ!OS\r\nContent-Length: 0\r\n\r\n""", | ||
{ | ||
"algorithm": "MD5", | ||
"realm": "local", | ||
"nonce": "111111:222222aaaaaa333333bbbbbb444444", | ||
}, | ||
), | ||
( | ||
b"""SIP/2.0 401 Unauthorized\r\nVia: SIP/2.0/UDP 0.0.0.0:5060;branch=z9hG4bK03150189fc65493a9d4e3a582;rport=5060;received=192.168.178.110\r\nFrom: "tarantulla" <sip:tarantulla@192.168.178.1>;tag=9338abd3\r\nTo: "tarantulla" <sip:tarantulla@192.168.178.1>;tag=950C00889AC0DB3B\r\nCall-ID: 6b86b273ff34fce19d6b804eff5a3f57@0.0.0.0:5060\r\nCSeq: 1 REGISTER\r\nWWW-Authenticate: Digest algorithm=MD5, realm="asterisk",nonce="45f77cee"\r\nUser-Agent: FRITZ!OS\r\nContent-Length: 0\r\n\r\n""", | ||
{ | ||
"algorithm": "MD5", | ||
"realm": "asterisk", | ||
"nonce": "45f77cee", | ||
}, | ||
), | ||
( | ||
b"""SIP/2.0 401 Unauthorized\r\nVia: SIP/2.0/UDP 192.168.0.76:5060;rport=5060;received=192.168.0.76;branch=z9hG4bK92b19bf363d84d2ea95d18cd3\r\nCall-ID: 6b86b273ff34fce19d6b804eff5a3f57@192.168.0.76:5060\r\nFrom: "5555" <sip:5555@192.168.0.100>;tag=fb11549a\r\nTo: "5555" <sip:5555@192.168.0.100>;tag=z9hG4bK92b19bf363d84d2ea95d18cd3\r\nCSeq: 1 REGISTER\r\nWWW-Authenticate: Digest realm="asterisk",nonce="1664256201/30ff48bd45c78b935077262030d584bd",opaque="5f0937be1ccec4cf",algorithm=md5,qop="auth"\r\nServer: Asterisk PBX 18.2.0\r\nContent-Length: 0\r\n\r\n""", | ||
{ | ||
"algorithm": "md5", | ||
"realm": "asterisk", | ||
"nonce": "1664256201/30ff48bd45c78b935077262030d584bd", | ||
"opaque": "5f0937be1ccec4cf", | ||
"qop": "auth", | ||
}, | ||
), | ||
], | ||
) | ||
def test_sip_authentication(packet, expected): | ||
message = SIPMessage(packet) | ||
assert message.authentication == expected |