22
33from tests .conftest import BaseTest
44from python3_capsolver .aws_waf import AwsWaf
5- from python3_capsolver .core .enum import CaptchaTypeEnm
5+ from python3_capsolver .core .enum import CaptchaTypeEnm , ResponseStatusEnm
66
77
88class TestAwsWafBase (BaseTest ):
@@ -24,7 +24,7 @@ def test_api_key_err(self, captcha_type):
2424 task_payload = {"some" : "data" }
2525 )
2626 assert result ["errorId" ] == 1
27- assert result ["errorCode" ] in ("ERROR_KEY_DENIED_ACCESS " , "ERROR_INVALID_TASK_DATA " )
27+ assert result ["errorCode" ] in ("ERROR_INVALID_TASK_DATA " , "ERROR_KEY_DENIED_ACCESS " )
2828 assert result ["solution" ] is None
2929
3030 @pytest .mark .parametrize ("captcha_type" , captcha_types )
@@ -33,5 +33,83 @@ async def test_aio_api_key_err(self, captcha_type):
3333 task_payload = {"some" : "data" }
3434 )
3535 assert result ["errorId" ] == 1
36- assert result ["errorCode" ] in ("ERROR_KEY_DENIED_ACCESS" , "ERROR_INVALID_TASK_DATA" )
36+ assert result ["errorCode" ] in ("ERROR_INVALID_TASK_DATA" , "ERROR_KEY_DENIED_ACCESS" )
37+ assert result ["solution" ] is None
38+
39+
40+ class TestAwsWafClassification (BaseTest ):
41+ toycarcity_image = "tests/files/aws_waf_class_toycarcity.png"
42+
43+ def test_success (self ):
44+ result = AwsWaf (api_key = self .API_KEY , captcha_type = CaptchaTypeEnm .AwsWafClassification ).captcha_handler (
45+ task_payload = {
46+ "images" : [self .read_image_as_str (file_path = self .toycarcity_image )],
47+ "question" : "aws:toycarcity:carcity" ,
48+ }
49+ )
50+ assert result ["errorId" ] == 0
51+ assert result ["errorCode" ] is None
52+ assert isinstance (result ["solution" ], dict )
53+ assert result ["status" ] == ResponseStatusEnm .Ready .value
54+ assert result ["taskId" ] is not ""
55+
56+ def test_api_key_err (self ):
57+ result = AwsWaf (
58+ api_key = self .get_random_string (36 ), captcha_type = CaptchaTypeEnm .AwsWafClassification
59+ ).captcha_handler (
60+ task_payload = {
61+ "images" : [self .read_image_as_str ()],
62+ "question" : "aws:toycarcity:carcity" ,
63+ }
64+ )
65+ assert result ["errorId" ] == 1
66+ assert result ["errorCode" ] == "ERROR_KEY_DENIED_ACCESS"
67+ assert result ["solution" ] is None
68+
69+ async def test_aio_api_key_err (self ):
70+ result = await AwsWaf (
71+ api_key = self .get_random_string (36 ), captcha_type = CaptchaTypeEnm .AwsWafClassification
72+ ).aio_captcha_handler (
73+ task_payload = {
74+ "images" : [self .read_image_as_str ()],
75+ "question" : "aws:toycarcity:carcity" ,
76+ }
77+ )
78+ assert result ["errorId" ] == 1
79+ assert result ["errorCode" ] == "ERROR_KEY_DENIED_ACCESS"
80+ assert result ["solution" ] is None
81+
82+
83+ class TestAntiAwsWafTaskProxyLess (BaseTest ):
84+
85+ def test_api_key_err (self ):
86+ result = AwsWaf (
87+ api_key = self .get_random_string (36 ), captcha_type = CaptchaTypeEnm .AntiAwsWafTaskProxyLess
88+ ).captcha_handler (
89+ task_payload = {
90+ "websiteURL" : "https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest" ,
91+ "awsKey" : "AQIDAHjcYu/GjX+QlghicBg......shMIKvZswZemrVVqA==" ,
92+ "awsIv" : "CgAAFDIlckAAAAid" ,
93+ "awsContext" : "7DhQfG5CmoY90ZdxdHCi8WtJ3z......njNKULdcUUVEtxTk=" ,
94+ "awsChallengeJS" : "https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js" ,
95+ }
96+ )
97+ assert result ["errorId" ] == 1
98+ assert result ["errorCode" ] == "ERROR_KEY_DENIED_ACCESS"
99+ assert result ["solution" ] is None
100+
101+ async def test_aio_api_key_err (self ):
102+ result = await AwsWaf (
103+ api_key = self .get_random_string (36 ), captcha_type = CaptchaTypeEnm .AntiAwsWafTaskProxyLess
104+ ).aio_captcha_handler (
105+ task_payload = {
106+ "websiteURL" : "https://efw47fpad9.execute-api.us-east-1.amazonaws.com/latest" ,
107+ "awsKey" : "AQIDAHjcYu/GjX+QlghicBg......shMIKvZswZemrVVqA==" ,
108+ "awsIv" : "CgAAFDIlckAAAAid" ,
109+ "awsContext" : "7DhQfG5CmoY90ZdxdHCi8WtJ3z......njNKULdcUUVEtxTk=" ,
110+ "awsChallengeJS" : "https://41bcdd4fb3cb.610cd090.us-east-1.token.awswaf.com/41bcdd4fb3cb/0d21de737ccb/cd77baa6c832/challenge.js" ,
111+ }
112+ )
113+ assert result ["errorId" ] == 1
114+ assert result ["errorCode" ] == "ERROR_KEY_DENIED_ACCESS"
37115 assert result ["solution" ] is None
0 commit comments