@anonympins/fingerprint 0.6.7 → 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 (63) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +3 -7
  3. package/composer.json +8 -1
  4. package/package.json +1 -1
  5. package/public/fingerprint-wordpress.zip +0 -0
  6. package/public/fp.wasm +0 -0
  7. package/src/js/build-client.js +9 -11
  8. package/src/js/dynamic-wasm.js +7 -7
  9. package/src/js/fingerprint.builder.js +37 -38
  10. package/src/js/fingerprint.client.js +236 -152
  11. package/src/js/fingerprint.client.obfuscated.js +1 -1
  12. package/src/js/fingerprint.js +517 -101
  13. package/src/js/fingerprint.utils.js +213 -213
  14. package/src/js/library.js +355 -384
  15. package/src/js/mongodb-store.js +1 -1
  16. package/src/js/optimization.worker.js +27 -27
  17. package/src/js/pow.solver.inline.js +206 -62
  18. package/src/js/pow.solver.js +235 -101
  19. package/src/js/pow.worker.js +48 -26
  20. package/src/js/redis-store.js +1 -1
  21. package/src/js/tests/fingerprint.client.init.test.js +146 -143
  22. package/src/js/tests/fingerprint.test.js +101 -40
  23. package/src/js/tests/ip-reputation.test.js +1 -0
  24. package/src/js/upow-model-task.js +14 -15
  25. package/src/php/AutoTuner.php +34 -34
  26. package/src/php/Challenge/ChallengeUtils.php +204 -32
  27. package/src/php/Config/SecurityProfiles.php +21 -0
  28. package/src/php/DirectFingerprint.php +190 -145
  29. package/src/php/FingerprintBuilder.php +29 -30
  30. package/src/php/FingerprintClient.php +24 -25
  31. package/src/php/FingerprintEngine.php +1836 -1880
  32. package/src/php/Ja3AnomalyDetector.php +258 -227
  33. package/src/php/Optimization/FunctionRegistry.php +7 -7
  34. package/src/php/Optimization/Optimization.php +24 -24
  35. package/src/php/Optimization/OptimizationOperators.php +28 -27
  36. package/src/php/Optimization/ProblemInitializers.php +52 -52
  37. package/src/php/ProblemManager.php +31 -34
  38. package/src/php/RequestContext.php +8 -1
  39. package/src/php/Store/IStore.php +7 -8
  40. package/src/php/Store/InMemoryStore.php +66 -66
  41. package/src/php/Store/MongoDbStore.php +5 -5
  42. package/src/php/Store/RedisStore.php +5 -5
  43. package/src/php/Store/StoreManager.php +35 -35
  44. package/src/php/Tests/ChallengeUtilsTest.php +453 -453
  45. package/src/php/Tests/DnsCircuitBreakerTest.php +105 -105
  46. package/src/php/Tests/FingerprintEngineTest.php +662 -693
  47. package/src/php/Tests/IpReputationTest.php +10 -0
  48. package/src/php/Tests/MaliciousPatternsTest.php +103 -103
  49. package/src/php/Tests/MetricsTest.php +97 -97
  50. package/src/php/Tests/ProblemManagerTest.php +376 -376
  51. package/src/php/Tests/QuicFingerprintTest.php +53 -53
  52. package/src/php/Tests/RequestUtilsTest.php +471 -471
  53. package/src/php/Tests/TLSClientHelloParserTest.php +177 -177
  54. package/src/php/Tests/config/ed25519_key.json +3 -3
  55. package/src/php/Utils/Env.php +49 -49
  56. package/src/php/Utils/MaliciousPatterns.php +74 -74
  57. package/src/php/Utils/MetricsManager.php +209 -209
  58. package/src/php/Utils/RequestUtils.php +236 -19
  59. package/src/php/Utils/TLSClientHelloParser.php +369 -212
  60. package/src/php/WordPress/WpDbStore.php +155 -0
  61. package/src/php/WordPress/fingerprint-wordpress.php +217 -0
  62. package/src/php/WordPress/package.php +123 -0
  63. 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
  }