@anonympins/fingerprint 0.7.0 → 0.7.1

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 (61) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -1
  3. package/composer.json +8 -1
  4. package/package.json +1 -1
  5. package/public/fingerprint-wordpress.zip +0 -0
  6. package/src/js/build-client.js +8 -10
  7. package/src/js/fingerprint.builder.js +37 -38
  8. package/src/js/fingerprint.client.js +1531 -1463
  9. package/src/js/fingerprint.client.obfuscated.js +1 -0
  10. package/src/js/fingerprint.js +152 -10
  11. package/src/js/fingerprint.utils.js +213 -213
  12. package/src/js/library.js +340 -376
  13. package/src/js/mongodb-store.js +1 -1
  14. package/src/js/optimization.worker.js +27 -27
  15. package/src/js/pow.solver.inline.js +154 -56
  16. package/src/js/pow.solver.js +180 -92
  17. package/src/js/pow.worker.js +48 -48
  18. package/src/js/redis-store.js +1 -1
  19. package/src/js/tests/fingerprint.client.init.test.js +146 -143
  20. package/src/js/tests/fingerprint.test.js +34 -7
  21. package/src/js/tests/ip-reputation.test.js +1 -0
  22. package/src/js/upow-model-task.js +14 -15
  23. package/src/php/AutoTuner.php +34 -34
  24. package/src/php/Challenge/ChallengeUtils.php +56 -10
  25. package/src/php/Config/SecurityProfiles.php +20 -0
  26. package/src/php/DirectFingerprint.php +190 -145
  27. package/src/php/FingerprintBuilder.php +29 -30
  28. package/src/php/FingerprintClient.php +147 -148
  29. package/src/php/FingerprintEngine.php +7 -5
  30. package/src/php/Ja3AnomalyDetector.php +33 -32
  31. package/src/php/Optimization/FunctionRegistry.php +7 -7
  32. package/src/php/Optimization/Optimization.php +24 -24
  33. package/src/php/Optimization/OptimizationOperators.php +26 -25
  34. package/src/php/Optimization/ProblemInitializers.php +52 -52
  35. package/src/php/ProblemManager.php +31 -34
  36. package/src/php/RequestContext.php +8 -1
  37. package/src/php/Store/IStore.php +7 -8
  38. package/src/php/Store/InMemoryStore.php +66 -66
  39. package/src/php/Store/MongoDbStore.php +5 -5
  40. package/src/php/Store/RedisStore.php +5 -5
  41. package/src/php/Store/StoreManager.php +35 -35
  42. package/src/php/Tests/ChallengeUtilsTest.php +453 -453
  43. package/src/php/Tests/DnsCircuitBreakerTest.php +105 -105
  44. package/src/php/Tests/FingerprintEngineTest.php +662 -662
  45. package/src/php/Tests/IpReputationTest.php +10 -0
  46. package/src/php/Tests/MaliciousPatternsTest.php +103 -103
  47. package/src/php/Tests/MetricsTest.php +97 -97
  48. package/src/php/Tests/ProblemManagerTest.php +376 -376
  49. package/src/php/Tests/QuicFingerprintTest.php +53 -53
  50. package/src/php/Tests/RequestUtilsTest.php +471 -471
  51. package/src/php/Tests/TLSClientHelloParserTest.php +177 -177
  52. package/src/php/Tests/config/ed25519_key.json +3 -3
  53. package/src/php/Utils/Env.php +49 -49
  54. package/src/php/Utils/MaliciousPatterns.php +74 -74
  55. package/src/php/Utils/MetricsManager.php +209 -209
  56. package/src/php/Utils/RequestUtils.php +129 -7
  57. package/src/php/Utils/TLSClientHelloParser.php +369 -369
  58. package/src/php/WordPress/WpDbStore.php +155 -0
  59. package/src/php/WordPress/fingerprint-wordpress.php +217 -0
  60. package/src/php/WordPress/package.php +123 -0
  61. package/src/php/bin/auto-tune.php +118 -118
@@ -1,106 +1,106 @@
1
- <?php
2
-
3
- declare(strict_types=1);
4
-
5
- namespace Anonympins\Fingerprint\Tests;
6
-
7
- use Anonympins\Fingerprint\FingerprintEngine;
8
- use PHPUnit\Framework\TestCase;
9
- use ReflectionClass;
10
-
11
- class DnsCircuitBreakerTest extends TestCase
12
- {
13
- private ReflectionClass $reflection;
14
-
15
- protected function setUp(): void
16
- {
17
- parent::setUp();
18
- $this->reflection = new ReflectionClass(FingerprintEngine::class);
19
-
20
- // Réinitialise l'état statique du disjoncteur avant chaque test
21
- $this->setCircuitBreakerState([
22
- 'state' => 'CLOSED',
23
- 'failureCount' => 0,
24
- 'lastStateChange' => 0,
25
- 'threshold' => 5,
26
- 'cooldown' => 1, // 1 seconde de cooldown pour accélérer le test
27
- ]);
28
- }
29
-
30
- private function getCircuitBreakerState(): array
31
- {
32
- $property = $this->reflection->getProperty('dnsCircuitBreaker');
33
- if (PHP_VERSION_ID < 80100) {
34
- $property->setAccessible(true);
35
- }
36
- return $property->getValue();
37
- }
38
-
39
- private function setCircuitBreakerState(array $state): void
40
- {
41
- $property = $this->reflection->getProperty('dnsCircuitBreaker');
42
- if (PHP_VERSION_ID < 80100) {
43
- $property->setAccessible(true);
44
- }
45
- $property->setValue(null, $state);
46
- }
47
-
48
- private function invokeMethod(string $methodName, array $args = [])
49
- {
50
- $method = $this->reflection->getMethod($methodName);
51
- if (PHP_VERSION_ID < 80100) { // PHP 8.1.0
52
- $method->setAccessible(true);
53
- }
54
- return $method->invokeArgs(null, $args);
55
- }
56
-
57
- public function testInitialStateIsClosed(): void
58
- {
59
- $this->assertTrue($this->invokeMethod('canAttemptDns'));
60
- $state = $this->getCircuitBreakerState();
61
- $this->assertSame('CLOSED', $state['state']);
62
- }
63
-
64
- public function testFailureThresholdTripsBreaker(): void
65
- {
66
- for ($i = 0; $i < 4; $i++) {
67
- $this->invokeMethod('recordDnsFailure');
68
- $this->assertTrue($this->invokeMethod('canAttemptDns'));
69
- $state = $this->getCircuitBreakerState();
70
- $this->assertSame('CLOSED', $state['state']);
71
- }
72
-
73
- $this->invokeMethod('recordDnsFailure');
74
- $this->assertFalse($this->invokeMethod('canAttemptDns'));
75
- $state = $this->getCircuitBreakerState();
76
- $this->assertSame('OPEN', $state['state']);
77
- }
78
-
79
- public function testCooldownTransitionsToHalfOpen(): void
80
- {
81
- for ($i = 0; $i < 5; $i++) {
82
- $this->invokeMethod('recordDnsFailure');
83
- }
84
- $this->assertFalse($this->invokeMethod('canAttemptDns'));
85
-
86
- usleep(1100000); // 1.1s
87
-
88
- $this->assertTrue($this->invokeMethod('canAttemptDns'));
89
- $state = $this->getCircuitBreakerState();
90
- $this->assertSame('HALF-OPEN', $state['state']);
91
- }
92
-
93
- public function testSuccessOnHalfOpenResetsBreaker(): void
94
- {
95
- for ($i = 0; $i < 5; $i++) {
96
- $this->invokeMethod('recordDnsFailure');
97
- }
98
- usleep(1100000);
99
- $this->assertTrue($this->invokeMethod('canAttemptDns'));
100
-
101
- $this->invokeMethod('recordDnsSuccess');
102
- $state = $this->getCircuitBreakerState();
103
- $this->assertSame('CLOSED', $state['state']);
104
- $this->assertSame(0, $state['failureCount']);
105
- }
1
+ <?php
2
+
3
+ declare(strict_types=1);
4
+
5
+ namespace Anonympins\Fingerprint\Tests;
6
+
7
+ use Anonympins\Fingerprint\FingerprintEngine;
8
+ use PHPUnit\Framework\TestCase;
9
+ use ReflectionClass;
10
+
11
+ class DnsCircuitBreakerTest extends TestCase
12
+ {
13
+ private ReflectionClass $reflection;
14
+
15
+ protected function setUp(): void
16
+ {
17
+ parent::setUp();
18
+ $this->reflection = new ReflectionClass(FingerprintEngine::class);
19
+
20
+ // Réinitialise l'état statique du disjoncteur avant chaque test
21
+ $this->setCircuitBreakerState([
22
+ 'state' => 'CLOSED',
23
+ 'failureCount' => 0,
24
+ 'lastStateChange' => 0,
25
+ 'threshold' => 5,
26
+ 'cooldown' => 1, // 1 seconde de cooldown pour accélérer le test
27
+ ]);
28
+ }
29
+
30
+ private function getCircuitBreakerState(): array
31
+ {
32
+ $property = $this->reflection->getProperty('dnsCircuitBreaker');
33
+ if (PHP_VERSION_ID < 80100) {
34
+ $property->setAccessible(true);
35
+ }
36
+ return $property->getValue();
37
+ }
38
+
39
+ private function setCircuitBreakerState(array $state): void
40
+ {
41
+ $property = $this->reflection->getProperty('dnsCircuitBreaker');
42
+ if (PHP_VERSION_ID < 80100) {
43
+ $property->setAccessible(true);
44
+ }
45
+ $property->setValue(null, $state);
46
+ }
47
+
48
+ private function invokeMethod(string $methodName, array $args = [])
49
+ {
50
+ $method = $this->reflection->getMethod($methodName);
51
+ if (PHP_VERSION_ID < 80100) { // PHP 8.1.0
52
+ $method->setAccessible(true);
53
+ }
54
+ return $method->invokeArgs(null, $args);
55
+ }
56
+
57
+ public function testInitialStateIsClosed(): void
58
+ {
59
+ $this->assertTrue($this->invokeMethod('canAttemptDns'));
60
+ $state = $this->getCircuitBreakerState();
61
+ $this->assertSame('CLOSED', $state['state']);
62
+ }
63
+
64
+ public function testFailureThresholdTripsBreaker(): void
65
+ {
66
+ for ($i = 0; $i < 4; $i++) {
67
+ $this->invokeMethod('recordDnsFailure');
68
+ $this->assertTrue($this->invokeMethod('canAttemptDns'));
69
+ $state = $this->getCircuitBreakerState();
70
+ $this->assertSame('CLOSED', $state['state']);
71
+ }
72
+
73
+ $this->invokeMethod('recordDnsFailure');
74
+ $this->assertFalse($this->invokeMethod('canAttemptDns'));
75
+ $state = $this->getCircuitBreakerState();
76
+ $this->assertSame('OPEN', $state['state']);
77
+ }
78
+
79
+ public function testCooldownTransitionsToHalfOpen(): void
80
+ {
81
+ for ($i = 0; $i < 5; $i++) {
82
+ $this->invokeMethod('recordDnsFailure');
83
+ }
84
+ $this->assertFalse($this->invokeMethod('canAttemptDns'));
85
+
86
+ usleep(1100000); // 1.1s
87
+
88
+ $this->assertTrue($this->invokeMethod('canAttemptDns'));
89
+ $state = $this->getCircuitBreakerState();
90
+ $this->assertSame('HALF-OPEN', $state['state']);
91
+ }
92
+
93
+ public function testSuccessOnHalfOpenResetsBreaker(): void
94
+ {
95
+ for ($i = 0; $i < 5; $i++) {
96
+ $this->invokeMethod('recordDnsFailure');
97
+ }
98
+ usleep(1100000);
99
+ $this->assertTrue($this->invokeMethod('canAttemptDns'));
100
+
101
+ $this->invokeMethod('recordDnsSuccess');
102
+ $state = $this->getCircuitBreakerState();
103
+ $this->assertSame('CLOSED', $state['state']);
104
+ $this->assertSame(0, $state['failureCount']);
105
+ }
106
106
  }