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
2 changes: 1 addition & 1 deletion .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] # asyncio isolated unittest work >= 3.8
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] # asyncio isolated unittest work >= 3.8

steps:
- uses: actions/checkout@v3
Expand Down
18 changes: 16 additions & 2 deletions capmonstercloud_client/requests/RecaptchaV2EnterpiseRequest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Dict, Union, Optional
from pydantic import Field
from pydantic import Field, field_validator

from .baseRequestWithProxy import BaseRequestWithProxy

Expand All @@ -22,6 +22,8 @@ class RecaptchaV2EnterpriseRequest(BaseRequestWithProxy):
domain.
pageAction: The action name configured for the reCAPTCHA Enterprise
challenge on the target website.
minScore: The minimum acceptable score for the token, in the range
0.1-0.9.
recaptchaDataSValue: The one-time token from the widget's "data-s"
parameter, if present on the page.
userAgent: The User-Agent string of the browser that should be
Expand All @@ -35,11 +37,21 @@ class RecaptchaV2EnterpriseRequest(BaseRequestWithProxy):
enterprisePayload: Optional[str] = Field(default=None, description='Additional parameters passed to the reCAPTCHA Enterprise widget, such as a custom "s" value used by some implementations.')
apiDomain: Optional[str] = Field(default=None, description='The domain to load the reCAPTCHA API from, used when the challenge is served from a domain other than the default Google domain.')
pageAction: Optional[str] = Field(default=None, description='The action name configured for the reCAPTCHA Enterprise challenge on the target website.')
minScore: Optional[float] = Field(default=None, description='Minimum acceptable score for the token, in the range 0.1-0.9.')
recaptchaDataSValue: Optional[str] = Field(default=None, description='The one-time token from the widget\'s "data-s" parameter, if present on the page.')
userAgent: Optional[str] = Field(default=None, description='The User-Agent string of the browser that should be emulated while solving the challenge.')
cookies: Optional[str] = Field(default=None, description='Cookies to be sent along with the request when solving the challenge.')

def getTaskDict(self) -> Dict[str, Union[str, int]]:
@field_validator('minScore')
@classmethod
def validate_min_score(cls, value):
if value is not None:
if not 0.1 <= value <= 0.9:
raise ValueError(f'Minimum score value should be found in interval 0.1 - 0.9, ' \
f'current "{value}".')
return value

def getTaskDict(self) -> Dict[str, Union[str, int, float]]:
task = {}
task['type'] = self.type
task['websiteURL'] = self.websiteUrl
Expand All @@ -56,6 +68,8 @@ def getTaskDict(self) -> Dict[str, Union[str, int]]:
task['apiDomain'] = self.apiDomain
if self.pageAction is not None:
task['pageAction'] = self.pageAction
if self.minScore is not None:
task['minScore'] = self.minScore
if self.recaptchaDataSValue is not None:
task['recaptchaDataSValue'] = self.recaptchaDataSValue
if self.userAgent is not None:
Expand Down
2 changes: 1 addition & 1 deletion capmonstercloud_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def parseVersion(versionFile: str = getDefaultVersionPath(),
else:
with open(versionFile, 'r') as f:
version = f.read()
return version
return version.strip()
2 changes: 1 addition & 1 deletion capmonstercloud_client/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.3
4.3.4
37 changes: 37 additions & 0 deletions test/recaptchaV2Enterprise_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import unittest

from pydantic import ValidationError
from capmonstercloudclient.requests import RecaptchaV2EnterpriseRequest


class RecaptchaV2EnterpriseRequestTest(unittest.TestCase):
websiteUrlExample = "https://example.com"
websiteKeyExample = "6Le0xVgUAAAAAIt20XEB4rVhYOODgTl00d8juDob"

def test_min_score_in_task_dict(self):
request = RecaptchaV2EnterpriseRequest(
websiteUrl=self.websiteUrlExample,
websiteKey=self.websiteKeyExample,
minScore=0.7,
)
self.assertEqual(request.getTaskDict()["minScore"], 0.7)

def test_min_score_omitted(self):
request = RecaptchaV2EnterpriseRequest(
websiteUrl=self.websiteUrlExample,
websiteKey=self.websiteKeyExample,
)
self.assertNotIn("minScore", request.getTaskDict())

def test_min_score_out_of_range(self):
for value in (0.0, 1.0):
with self.assertRaises(ValidationError):
RecaptchaV2EnterpriseRequest(
websiteUrl=self.websiteUrlExample,
websiteKey=self.websiteKeyExample,
minScore=value,
)


if __name__ == "__main__":
unittest.main()
Loading