Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions capmonstercloud_client/requests/TenDiCustomTaskRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@ class TenDiCustomTaskRequest(CustomTaskRequestBase):
websiteKey: The captchaAppId (the "aid" value, e.g. "189123456") for
the target website, found in the page HTML or network traffic.
metadata: Optional additional parameters for the task. Currently
supports the "captchaUrl" key, whose value must be a string.
supports the "captchaUrl" key and the "aidEncrypted" key, whose
values must be strings. "aidEncrypted" is the single-use Aid value
obtained from the target website before creating the task; pass it
only if the website uses Aid.
"""
captchaClass: str = Field(default='TenDI', description='The identifier of the custom captcha class to solve.')
websiteKey: str = Field(description='The captchaAppId (the "aid" value, e.g. "189123456") for the target website, found in the page HTML or network traffic.')
metadata: Optional[Dict[str, str]] = Field(default=None, description='Optional additional parameters for the task; supports the "captchaUrl" key with a string value.')
metadata: Optional[Dict[str, str]] = Field(default=None, description='Optional additional parameters for the task; supports the "captchaUrl" and "aidEncrypted" keys with string values.')

@field_validator('metadata')
@classmethod
def validate_metadata(cls, value):
if value is not None:
if not set(value.keys()).issubset(set(["captchaUrl"])):
raise TypeError(f'Allowed keys for metadata are "captchaUrl"')
if not set(value.keys()).issubset(set(["captchaUrl", "aidEncrypted"])):
raise TypeError(f'Allowed keys for metadata are "captchaUrl", "aidEncrypted"')
if value.get('captchaUrl') is not None and not isinstance(value.get('captchaUrl'), str):
raise TypeError(f'captchaUrl must be str.')
if value.get('aidEncrypted') is not None and not isinstance(value.get('aidEncrypted'), str):
raise TypeError(f'aidEncrypted must be str.')
return value

def getTaskDict(self) -> Dict[str, Union[str, int, bool]]:
Expand Down
2 changes: 1 addition & 1 deletion capmonstercloud_client/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.0
4.3.1
30 changes: 30 additions & 0 deletions test/tendi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ def testMetadataWithCaptchaUrl(self):
request_dict = request.getTaskDict()
self.assertEqual(request_dict["metadata"]["captchaUrl"], "https://example.com/TCaptcha.js")

def testMetadataWithAidEncrypted(self):
request = TenDiCustomTaskRequest(
websiteUrl=TenDiCustomTaskRequestTest.websiteUrlExample,
websiteKey=TenDiCustomTaskRequestTest.websiteKeyExample,
metadata={
"captchaUrl": "https://example.com/TCaptcha.js",
"aidEncrypted": "YOUR_AID_ENCRYPTED",
},
)
request_dict = request.getTaskDict()
self.assertEqual(request_dict["metadata"]["aidEncrypted"], "YOUR_AID_ENCRYPTED")
self.assertEqual(request_dict["metadata"]["captchaUrl"], "https://example.com/TCaptcha.js")

def testMetadataAidEncryptedOnly(self):
request = TenDiCustomTaskRequest(
websiteUrl=TenDiCustomTaskRequestTest.websiteUrlExample,
websiteKey=TenDiCustomTaskRequestTest.websiteKeyExample,
metadata={"aidEncrypted": "YOUR_AID_ENCRYPTED"},
)
self.assertEqual(request.getTaskDict()["metadata"], {"aidEncrypted": "YOUR_AID_ENCRYPTED"})

def testMetadataAidEncryptedWrongType(self):
for bad_value in (123, True):
with self.assertRaises((TypeError, ValidationError)):
TenDiCustomTaskRequest(
websiteUrl=TenDiCustomTaskRequestTest.websiteUrlExample,
websiteKey=TenDiCustomTaskRequestTest.websiteKeyExample,
metadata={"aidEncrypted": bad_value},
)

def testMetadataInvalidKey(self):
self.assertRaises(
TypeError,
Expand Down
Loading