diff --git a/capmonstercloud_client/requests/TenDiCustomTaskRequest.py b/capmonstercloud_client/requests/TenDiCustomTaskRequest.py index a46e344..ea0fb65 100644 --- a/capmonstercloud_client/requests/TenDiCustomTaskRequest.py +++ b/capmonstercloud_client/requests/TenDiCustomTaskRequest.py @@ -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]]: diff --git a/capmonstercloud_client/version.txt b/capmonstercloud_client/version.txt index 8191138..ecedc98 100644 --- a/capmonstercloud_client/version.txt +++ b/capmonstercloud_client/version.txt @@ -1 +1 @@ -4.3.0 \ No newline at end of file +4.3.1 \ No newline at end of file diff --git a/test/tendi_test.py b/test/tendi_test.py index d9d653d..d82a23f 100644 --- a/test/tendi_test.py +++ b/test/tendi_test.py @@ -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,