hyper-sdk 4.3.1__tar.gz → 4.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/PKG-INFO +1 -1
  2. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/sec_cpt.py +133 -129
  3. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/datadome/parse.py +17 -14
  4. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/PKG-INFO +1 -1
  5. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/SOURCES.txt +1 -0
  6. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/pyproject.toml +1 -1
  7. hyper_sdk-4.3.2/tests/test_challenge_script_url.py +68 -0
  8. hyper_sdk-4.3.2/tests/test_sec_cpt.py +69 -0
  9. hyper_sdk-4.3.1/tests/test_challenge_script_url.py +0 -35
  10. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/LICENSE +0 -0
  11. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/README.md +0 -0
  12. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/__init__.py +0 -0
  13. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/__init__.py +0 -0
  14. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/pixel.py +0 -0
  15. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/script_path.py +0 -0
  16. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai/stop_signal.py +0 -0
  17. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/akamai_input.py +0 -0
  18. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/datadome/__init__.py +0 -0
  19. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/datadome_input.py +0 -0
  20. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/incapsula/__init__.py +0 -0
  21. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/incapsula/dynamic.py +0 -0
  22. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/incapsula/utmvc.py +0 -0
  23. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/incapsula_input.py +0 -0
  24. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada/__init__.py +0 -0
  25. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada/dv.py +0 -0
  26. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada/parse.py +0 -0
  27. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada/user_agent.py +0 -0
  28. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/kasada_input.py +0 -0
  29. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/payloads.py +0 -0
  30. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/results.py +0 -0
  31. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/session.py +0 -0
  32. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/session_async.py +0 -0
  33. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/shared.py +0 -0
  34. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk/trustdecision_input.py +0 -0
  35. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/dependency_links.txt +0 -0
  36. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/requires.txt +0 -0
  37. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/hyper_sdk.egg-info/top_level.txt +0 -0
  38. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/setup.cfg +0 -0
  39. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/tests/test_dv.py +0 -0
  40. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/tests/test_results.py +0 -0
  41. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/tests/test_script_hash.py +0 -0
  42. {hyper_sdk-4.3.1 → hyper_sdk-4.3.2}/tests/test_user_agent.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyper_sdk
3
- Version: 4.3.1
3
+ Version: 4.3.2
4
4
  Summary: Hyper Solutions Python SDK
5
5
  License: MIT License
6
6
 
@@ -1,130 +1,134 @@
1
- import base64
2
- import hashlib
3
- import json
4
- import os
5
- import re
6
- import time
7
- from collections import OrderedDict
8
- from typing import List
9
-
10
- sec_duration_expr = re.compile(r'data-duration=(\d+)')
11
- sec_challenge_expr = re.compile(r'challenge="(.*?)"')
12
- sec_page_expr = re.compile(r'data-duration=\d+\s+src="([^"]+)"')
13
-
14
-
15
- class SecCptChallengeData:
16
- def __init__(self, token: str, timestamp: int, nonce: str, difficulty: int, count: int):
17
- self.token = token
18
- self.timestamp = timestamp
19
- self.nonce = nonce
20
- self.difficulty = difficulty
21
- self.count = count
22
-
23
-
24
- class SecCptChallenge:
25
- def __init__(self, duration: int, challenge_path: str, challenge_data: SecCptChallengeData):
26
- self.duration = duration
27
- self.challenge_path = challenge_path
28
- self.challenge_data = challenge_data
29
-
30
- @staticmethod
31
- def parse(html: str) -> 'SecCptChallenge':
32
- challenge_data = SecCptChallenge._parse_challenge_data(html)
33
- duration = SecCptChallenge._parse_duration(html)
34
- challenge_path = SecCptChallenge._parse_challenge_path(html)
35
-
36
- return SecCptChallenge(duration, challenge_path, challenge_data)
37
-
38
- @staticmethod
39
- def parse_from_json(json_payload: str) -> 'SecCptChallenge':
40
- api_response = json.loads(json_payload)
41
-
42
- challenge_data = SecCptChallengeData(
43
- api_response.get('token', ''),
44
- api_response.get('timestamp', 0),
45
- api_response.get('nonce', ''),
46
- api_response.get('difficulty', 0)
47
- )
48
-
49
- duration = api_response.get('chlg_duration', 0)
50
- challenge_path = api_response.get('branding_url_content', '')
51
-
52
- return SecCptChallenge(duration, challenge_path, challenge_data)
53
-
54
- @staticmethod
55
- def _parse_challenge_data(src: str) -> SecCptChallengeData:
56
- challenge_match = sec_challenge_expr.search(src)
57
- if not challenge_match:
58
- raise Exception("hyper-sdk: Challenge data not found.")
59
-
60
- decoded_challenge = base64.b64decode(challenge_match.group(1))
61
- challenge_data = json.loads(decoded_challenge)
62
-
63
- return SecCptChallengeData(
64
- challenge_data.get('token', ''),
65
- challenge_data.get('timestamp', 0),
66
- challenge_data.get('nonce', ''),
67
- challenge_data.get('difficulty', 0),
68
- challenge_data.get('count', 0)
69
- )
70
-
71
- @staticmethod
72
- def _parse_duration(src: str) -> int:
73
- duration_match = sec_duration_expr.search(src)
74
- if not duration_match:
75
- raise Exception("hyper-sdk: Duration not found.")
76
-
77
- try:
78
- duration = int(duration_match.group(1))
79
- except ValueError as e:
80
- raise Exception(f"hyper-sdk: Invalid duration value: {e}")
81
-
82
- return duration
83
-
84
- @staticmethod
85
- def _parse_challenge_path(src: str) -> str:
86
- page_match = sec_page_expr.search(src)
87
- if not page_match:
88
- raise Exception("hyper-sdk: Challenge path not found.")
89
-
90
- return page_match.group(1)
91
-
92
- def generate_sec_cpt_payload(self, sec_cpt_cookie: str) -> str:
93
- sec, _, _ = sec_cpt_cookie.partition("~")
94
- if sec == sec_cpt_cookie:
95
- raise Exception("hyper-sdk: Malformed sec_cpt cookie.")
96
-
97
- answers = self._generate_sec_cpt_answers(sec)
98
-
99
- payload = OrderedDict([
100
- ("token", self.challenge_data.token),
101
- ("answers", answers)
102
- ])
103
-
104
- return json.dumps(payload)
105
-
106
- def sleep(self):
107
- time.sleep(self.duration)
108
-
109
- def _generate_sec_cpt_answers(self, sec: str) -> List[str]:
110
- answers = []
111
- difficulty = self.challenge_data.difficulty
112
-
113
- while True:
114
- answer = f"0.{os.urandom(8).hex()}"
115
- hash_input = f"{sec}{self.challenge_data.timestamp}{self.challenge_data.nonce}{difficulty}{answer}"
116
-
117
- output = 0
118
- for byte in hashlib.sha256(hash_input.encode('ascii')).digest():
119
- output = (output << 8) | byte
120
- output %= difficulty
121
-
122
- if output == 0:
123
- difficulty += 1
124
- answers.append(answer)
125
-
126
- if len(answers) == self.challenge_data.count:
127
- break
128
- continue
129
-
1
+ import base64
2
+ import hashlib
3
+ import json
4
+ import os
5
+ import re
6
+ import time
7
+ from collections import OrderedDict
8
+ from typing import List
9
+
10
+ sec_duration_expr = re.compile(r'data-duration=(\d+)')
11
+ sec_challenge_expr = re.compile(r'challenge="(.*?)"')
12
+ sec_page_expr = re.compile(r'data-duration=\d+\s+src="([^"]+)"')
13
+
14
+
15
+ class SecCptChallengeData:
16
+ def __init__(self, token: str, timestamp: int, nonce: str, difficulty: int, count: int):
17
+ self.token = token
18
+ self.timestamp = timestamp
19
+ self.nonce = nonce
20
+ self.difficulty = difficulty
21
+ self.count = count
22
+
23
+
24
+ class SecCptChallenge:
25
+ def __init__(self, duration: int, challenge_path: str, challenge_data: SecCptChallengeData):
26
+ self.duration = duration
27
+ self.challenge_path = challenge_path
28
+ self.challenge_data = challenge_data
29
+
30
+ @staticmethod
31
+ def parse(html: str) -> 'SecCptChallenge':
32
+ challenge_data = SecCptChallenge._parse_challenge_data(html)
33
+ duration = SecCptChallenge._parse_duration(html)
34
+ challenge_path = SecCptChallenge._parse_challenge_path(html)
35
+
36
+ return SecCptChallenge(duration, challenge_path, challenge_data)
37
+
38
+ @staticmethod
39
+ def parse_from_json(json_payload: str) -> 'SecCptChallenge':
40
+ api_response = json.loads(json_payload)
41
+
42
+ challenge_data = SecCptChallengeData(
43
+ api_response.get('token', ''),
44
+ api_response.get('timestamp', 0),
45
+ api_response.get('nonce', ''),
46
+ api_response.get('difficulty', 0),
47
+ api_response.get('count', 0)
48
+ )
49
+
50
+ duration = api_response.get('chlg_duration', 0)
51
+ challenge_path = api_response.get('branding_url_content', '')
52
+
53
+ return SecCptChallenge(duration, challenge_path, challenge_data)
54
+
55
+ @staticmethod
56
+ def _parse_challenge_data(src: str) -> SecCptChallengeData:
57
+ challenge_match = sec_challenge_expr.search(src)
58
+ if not challenge_match:
59
+ raise Exception("hyper-sdk: Challenge data not found.")
60
+
61
+ decoded_challenge = base64.b64decode(challenge_match.group(1))
62
+ challenge_data = json.loads(decoded_challenge)
63
+
64
+ return SecCptChallengeData(
65
+ challenge_data.get('token', ''),
66
+ challenge_data.get('timestamp', 0),
67
+ challenge_data.get('nonce', ''),
68
+ challenge_data.get('difficulty', 0),
69
+ challenge_data.get('count', 0)
70
+ )
71
+
72
+ @staticmethod
73
+ def _parse_duration(src: str) -> int:
74
+ duration_match = sec_duration_expr.search(src)
75
+ if not duration_match:
76
+ raise Exception("hyper-sdk: Duration not found.")
77
+
78
+ try:
79
+ duration = int(duration_match.group(1))
80
+ except ValueError as e:
81
+ raise Exception(f"hyper-sdk: Invalid duration value: {e}")
82
+
83
+ return duration
84
+
85
+ @staticmethod
86
+ def _parse_challenge_path(src: str) -> str:
87
+ page_match = sec_page_expr.search(src)
88
+ if not page_match:
89
+ raise Exception("hyper-sdk: Challenge path not found.")
90
+
91
+ return page_match.group(1)
92
+
93
+ def generate_sec_cpt_payload(self, sec_cpt_cookie: str) -> str:
94
+ sec, _, _ = sec_cpt_cookie.partition("~")
95
+ if sec == sec_cpt_cookie:
96
+ raise Exception("hyper-sdk: Malformed sec_cpt cookie.")
97
+
98
+ answers = self._generate_sec_cpt_answers(sec)
99
+
100
+ payload = OrderedDict([
101
+ ("token", self.challenge_data.token),
102
+ ("answers", answers)
103
+ ])
104
+
105
+ return json.dumps(payload)
106
+
107
+ def sleep(self):
108
+ time.sleep(self.duration)
109
+
110
+ def _generate_sec_cpt_answers(self, sec: str) -> List[str]:
111
+ answers = []
112
+ if self.challenge_data.count <= 0:
113
+ return answers
114
+
115
+ difficulty = self.challenge_data.difficulty
116
+
117
+ while True:
118
+ answer = f"0.{os.urandom(8).hex()}"
119
+ hash_input = f"{sec}{self.challenge_data.timestamp}{self.challenge_data.nonce}{difficulty}{answer}"
120
+
121
+ output = 0
122
+ for byte in hashlib.sha256(hash_input.encode('ascii')).digest():
123
+ output = (output << 8) | byte
124
+ output %= difficulty
125
+
126
+ if output == 0:
127
+ difficulty += 1
128
+ answers.append(answer)
129
+
130
+ if len(answers) == self.challenge_data.count:
131
+ break
132
+ continue
133
+
130
134
  return answers
@@ -3,15 +3,14 @@ import re
3
3
  from typing import Optional
4
4
  from urllib.parse import urlencode
5
5
 
6
- # Matches the tag a challenge page uses to load the bundle from
7
- # ct.captcha-delivery.com, capturing the URL. The name in front of the version
8
- # is left open so it keeps matching whatever DataDome calls the bundle, and the
9
- # build segment after the version is optional: the bundle can be
10
- # interstitial.1.33.0.202609141.js, captcha.1.34.0.202609141.js or
11
- # interstitial.1.36.0.js.
12
- _CHALLENGE_SCRIPT_REGEX = re.compile(
13
- r"""<script[^>]+src\s*=\s*["']([^"']*/[a-z_-]+\.\d+\.\d+\.\d+(?:\.[^"']*)?\.js)["']"""
14
- )
6
+ # A challenge page loads its bundle with the only deferred <script> tag on the
7
+ # page, so the bundle is the src of the first tag carrying a defer attribute.
8
+ # The file name is not checked: DataDome renames the bundle freely, e.g.
9
+ # interstitial.1.36.0.js or captcha.build623.01-c-v1.38.0-2026-11-17-05h07.js.
10
+ # The c.js and i.js loaders are not deferred and never match.
11
+ _SCRIPT_TAG_REGEX = re.compile(r"<script\b([^>]*)>", re.IGNORECASE)
12
+ _DEFER_ATTR_REGEX = re.compile(r"(?:^|\s)defer(?:\s|=|/|$)", re.IGNORECASE)
13
+ _SRC_ATTR_REGEX = re.compile(r"""(?:^|\s)src\s*=\s*["']([^"']+)["']""", re.IGNORECASE)
15
14
 
16
15
 
17
16
  def parse_slider_device_check_link(src: str, datadome_cookie: str, referer: str) -> str:
@@ -135,8 +134,12 @@ def parse_challenge_script_url(html: str) -> Optional[str]:
135
134
  script=script,
136
135
  ))
137
136
  """
138
- match = _CHALLENGE_SCRIPT_REGEX.search(html)
139
- if match is None:
140
- return None
141
-
142
- return match.group(1)
137
+ for tag in _SCRIPT_TAG_REGEX.finditer(html):
138
+ attrs = tag.group(1)
139
+ if not _DEFER_ATTR_REGEX.search(attrs):
140
+ continue
141
+ src = _SRC_ATTR_REGEX.search(attrs)
142
+ if src is not None:
143
+ return src.group(1)
144
+
145
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyper_sdk
3
- Version: 4.3.1
3
+ Version: 4.3.2
4
4
  Summary: Hyper Solutions Python SDK
5
5
  License: MIT License
6
6
 
@@ -35,4 +35,5 @@ tests/test_challenge_script_url.py
35
35
  tests/test_dv.py
36
36
  tests/test_results.py
37
37
  tests/test_script_hash.py
38
+ tests/test_sec_cpt.py
38
39
  tests/test_user_agent.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "hyper_sdk"
7
- version = "4.3.1"
7
+ version = "4.3.2"
8
8
  description = "Hyper Solutions Python SDK"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -0,0 +1,68 @@
1
+ """Finds the deferred DataDome challenge bundle on a device check or captcha page."""
2
+
3
+ import unittest
4
+
5
+ from hyper_sdk.datadome import parse_challenge_script_url
6
+
7
+ BUILD_PREFIX_URL = "https://ct.captcha-delivery.com/captcha.build623.01-c-v1.38.0-2026-11-17-05h07.js"
8
+
9
+
10
+ class TestParseChallengeScriptUrl(unittest.TestCase):
11
+ def test_interstitial_with_build(self):
12
+ html = '<head><script defer src="https://ct.captcha-delivery.com/interstitial.1.33.0.202609141.js"></script></head>'
13
+ self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial.1.33.0.202609141.js")
14
+
15
+ def test_captcha_with_build(self):
16
+ html = '<script defer src="https://ct.captcha-delivery.com/captcha.1.34.0.202609141.js"></script>'
17
+ self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/captcha.1.34.0.202609141.js")
18
+
19
+ def test_interstitial_without_build(self):
20
+ html = '<head><script defer src="https://ct.captcha-delivery.com/interstitial.1.36.0.js"></script></head>'
21
+ self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial.1.36.0.js")
22
+
23
+ def test_single_quotes(self):
24
+ html = "<script defer src='https://ct.captcha-delivery.com/captcha.1.37.0.js'></script>"
25
+ self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/captcha.1.37.0.js")
26
+
27
+ def test_captcha_with_build_prefix(self):
28
+ html = f'<script defer src="{BUILD_PREFIX_URL}"></script>'
29
+ self.assertEqual(parse_challenge_script_url(html), BUILD_PREFIX_URL)
30
+
31
+ def test_build_prefix_after_inline_dd_object(self):
32
+ html = (
33
+ "<script data-cfasync=\"false\">var dd={'rt':'c'}</script>"
34
+ '<script data-cfasync="false" src="https://ct.captcha-delivery.com/c.js"></script>'
35
+ f'<script defer src="{BUILD_PREFIX_URL}"></script>'
36
+ )
37
+ self.assertEqual(parse_challenge_script_url(html), BUILD_PREFIX_URL)
38
+
39
+ def test_any_file_name(self):
40
+ html = '<script defer src="https://ct.captcha-delivery.com/interstitial-next.js"></script>'
41
+ self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial-next.js")
42
+
43
+ def test_defer_after_src(self):
44
+ html = f'<script src="{BUILD_PREFIX_URL}" defer></script>'
45
+ self.assertEqual(parse_challenge_script_url(html), BUILD_PREFIX_URL)
46
+
47
+ def test_first_deferred_tag_wins(self):
48
+ html = (
49
+ f'<script defer src="{BUILD_PREFIX_URL}"></script>'
50
+ '<script defer src="https://example.com/other.js"></script>'
51
+ )
52
+ self.assertEqual(parse_challenge_script_url(html), BUILD_PREFIX_URL)
53
+
54
+ def test_defer_in_src_is_not_the_attribute(self):
55
+ html = '<script src="https://example.com/defer.js"></script>'
56
+ self.assertIsNone(parse_challenge_script_url(html))
57
+
58
+ def test_versionless_loader(self):
59
+ html = '<script src="https://ct.captcha-delivery.com/i.js"></script>'
60
+ self.assertIsNone(parse_challenge_script_url(html))
61
+
62
+ def test_inlined_bundle(self):
63
+ html = "<script>var ddm = {};/* DataDome is a cyberfraud solution v1.33.0 */!function(){}()</script>"
64
+ self.assertIsNone(parse_challenge_script_url(html))
65
+
66
+
67
+ if __name__ == "__main__":
68
+ unittest.main()
@@ -0,0 +1,69 @@
1
+ """SEC-CPT challenge parsing and answer generation."""
2
+
3
+ import base64
4
+ import json
5
+ import unittest
6
+
7
+ from hyper_sdk.akamai import SecCptChallenge
8
+
9
+ CHALLENGE = {
10
+ "token": "tok",
11
+ "timestamp": 1713283747,
12
+ "nonce": "ebccdb479fcb92636fbc",
13
+ "difficulty": 1500,
14
+ "count": 3,
15
+ }
16
+
17
+
18
+ class ParseFromJsonTest(unittest.TestCase):
19
+ def test_reads_every_challenge_field(self):
20
+ payload = json.dumps({
21
+ **CHALLENGE,
22
+ "sec-cp-challenge": "true",
23
+ "provider": "adaptive",
24
+ "chlg_duration": 5,
25
+ "branding_url_content": "/_sec/cp_challenge/ak-challenge-4-3.htm",
26
+ })
27
+
28
+ challenge = SecCptChallenge.parse_from_json(payload)
29
+
30
+ self.assertEqual(challenge.duration, 5)
31
+ self.assertEqual(challenge.challenge_path, "/_sec/cp_challenge/ak-challenge-4-3.htm")
32
+ data = challenge.challenge_data
33
+ self.assertEqual(
34
+ (data.token, data.timestamp, data.nonce, data.difficulty, data.count),
35
+ ("tok", 1713283747, "ebccdb479fcb92636fbc", 1500, 3),
36
+ )
37
+
38
+ def test_payload_has_count_answers(self):
39
+ challenge = SecCptChallenge.parse_from_json(json.dumps(CHALLENGE))
40
+
41
+ payload = json.loads(challenge.generate_sec_cpt_payload("ABCDEF~3~xyz"))
42
+
43
+ self.assertEqual(payload["token"], "tok")
44
+ self.assertEqual(len(payload["answers"]), 3)
45
+
46
+ def test_missing_count_yields_no_answers(self):
47
+ challenge = SecCptChallenge.parse_from_json(json.dumps({k: v for k, v in CHALLENGE.items() if k != "count"}))
48
+
49
+ payload = json.loads(challenge.generate_sec_cpt_payload("ABCDEF~3~xyz"))
50
+
51
+ self.assertEqual(payload["answers"], [])
52
+
53
+
54
+ class ParseHtmlTest(unittest.TestCase):
55
+ def test_html_and_json_parse_to_the_same_challenge_data(self):
56
+ encoded = base64.b64encode(json.dumps(CHALLENGE).encode()).decode()
57
+ html = (
58
+ f'<iframe id="sec-cpt-if" provider="crypto" challenge="{encoded}" '
59
+ f'data-duration=5 src="/_sec/cp_challenge/ak-challenge-4-3.htm"></iframe>'
60
+ )
61
+
62
+ from_html = SecCptChallenge.parse(html).challenge_data
63
+ from_json = SecCptChallenge.parse_from_json(json.dumps(CHALLENGE)).challenge_data
64
+
65
+ self.assertEqual(vars(from_html), vars(from_json))
66
+
67
+
68
+ if __name__ == "__main__":
69
+ unittest.main()
@@ -1,35 +0,0 @@
1
- """Finds the deferred DataDome challenge bundle on a device check or captcha page."""
2
-
3
- import unittest
4
-
5
- from hyper_sdk.datadome import parse_challenge_script_url
6
-
7
-
8
- class TestParseChallengeScriptUrl(unittest.TestCase):
9
- def test_interstitial_with_build(self):
10
- html = '<head><script defer src="https://ct.captcha-delivery.com/interstitial.1.33.0.202609141.js"></script></head>'
11
- self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial.1.33.0.202609141.js")
12
-
13
- def test_captcha_with_build(self):
14
- html = '<script defer src="https://ct.captcha-delivery.com/captcha.1.34.0.202609141.js"></script>'
15
- self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/captcha.1.34.0.202609141.js")
16
-
17
- def test_interstitial_without_build(self):
18
- html = '<head><script defer src="https://ct.captcha-delivery.com/interstitial.1.36.0.js"></script></head>'
19
- self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/interstitial.1.36.0.js")
20
-
21
- def test_single_quotes(self):
22
- html = "<script src='https://ct.captcha-delivery.com/captcha.1.37.0.js'></script>"
23
- self.assertEqual(parse_challenge_script_url(html), "https://ct.captcha-delivery.com/captcha.1.37.0.js")
24
-
25
- def test_versionless_loader(self):
26
- html = '<script src="https://ct.captcha-delivery.com/i.js"></script>'
27
- self.assertIsNone(parse_challenge_script_url(html))
28
-
29
- def test_inlined_bundle(self):
30
- html = "<script>var ddm = {};/* DataDome is a cyberfraud solution v1.33.0 */!function(){}()</script>"
31
- self.assertIsNone(parse_challenge_script_url(html))
32
-
33
-
34
- if __name__ == "__main__":
35
- unittest.main()
File without changes
File without changes
File without changes
File without changes
File without changes