-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add wait logic * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix wait logic * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * changelog * Fix type * Fix type * Fix test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove fixture * Fix param --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ae16e8e
commit 78eb75f
Showing
3 changed files
with
195 additions
and
53 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
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,36 +1,63 @@ | ||
import pytest | ||
from SRT.netfunnel import NetFunnelHelper, NetFunnelResponse | ||
|
||
from SRT.netfunnel import NetFunnelHelper, SRTNetFunnelError | ||
|
||
def test_get_netfunnel_key_success(): | ||
helper = NetFunnelHelper() | ||
helper._get_netfunnel_key(False) | ||
|
||
@pytest.fixture(scope="module") | ||
def helper(): | ||
return NetFunnelHelper() | ||
|
||
def test_set_complete_success(): | ||
helper = NetFunnelHelper() | ||
key = helper._get_netfunnel_key(False) | ||
helper._set_complete(key) | ||
|
||
def test_get_netfunnel_key_success(helper): | ||
try: | ||
key = helper._get_netfunnel_key(True) | ||
except SRTNetFunnelError as e: | ||
raise AssertionError() from e | ||
assert key is not None | ||
|
||
|
||
def test_set_complete_success(helper): | ||
key = helper._get_netfunnel_key(True) | ||
try: | ||
helper._set_complete(key) | ||
except SRTNetFunnelError as e: | ||
raise AssertionError() from e | ||
assert True | ||
|
||
|
||
def test_extract_netfunnel_key_success(helper): | ||
def test_netfunnel_response_parse(): | ||
key = "C75890BD44561ED79DFA180832F2D016F95C9F7BE965B2" | ||
response = f""" | ||
NetFunnel.gRtype = 5101; | ||
NetFunnel.gControl.result = '5002:200:key={key}&nwait=0&nnext=0&tps=0&ttl=0&ip=nf.letskorail.com&port=443'; | ||
response_text = f""" | ||
NetFunnel.gRtype=5101; | ||
NetFunnel.gControl.result='5002:200:key={key}&nwait=0&nnext=0&tps=0&ttl=0&ip=nf.letskorail.com&port=443'; | ||
NetFunnel.gControl._showResult(); | ||
""" | ||
response = NetFunnelResponse.parse(response_text) | ||
assert "key" in response.data | ||
assert response.data["key"] == key | ||
assert response.data["nwait"] == "0" | ||
assert response.data["nnext"] == "0" | ||
assert response.data["tps"] == "0" | ||
assert response.data["ttl"] == "0" | ||
assert response.data["ip"] == "nf.letskorail.com" | ||
assert response.data["port"] == "443" | ||
assert response.data["opcode"] == "5101" | ||
assert response.data["next_code"] == "5002" | ||
assert response.data["status"] == "200" | ||
|
||
response_text = """ | ||
NetFunnel.gRtype=5002; | ||
NetFunnel.gControl.result='5002:200:key=test_key&nwait=0&nnext=0&tps=0&ttl=0&ip=nf.letskorail.com&port=443'; | ||
NetFunnel.gControl._showResult(); | ||
""" | ||
key = helper._extract_netfunnel_key(response) | ||
assert key == key | ||
|
||
response = NetFunnelResponse.parse(response_text) | ||
assert "key" in response.data | ||
assert response.data["key"] == "test_key" | ||
assert response.data["nwait"] == "0" | ||
assert response.data["nnext"] == "0" | ||
assert response.data["tps"] == "0" | ||
assert response.data["ttl"] == "0" | ||
assert response.data["ip"] == "nf.letskorail.com" | ||
assert response.data["port"] == "443" | ||
assert response.data["opcode"] == "5002" | ||
assert response.data["next_code"] == "5002" | ||
assert response.data["status"] == "200" | ||
|
||
response_text = """ | ||
NetFunnel.gRtype=5004;NetFunnel.gControl.result='5004:502:msg="Already Completed"'; NetFunnel.gControl._showResult(); | ||
""" | ||
|
||
response = NetFunnelResponse.parse(response_text) | ||
assert "key" not in response.data | ||
assert response.data["opcode"] == "5004" | ||
assert response.data["next_code"] == "5004" | ||
assert response.data["status"] == "502" | ||
assert response.data["msg"] == '"Already Completed"' |