From d7e7f5540a196041e4e77e67a0618a14db3624a7 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 2 May 2024 09:26:22 -0700 Subject: [PATCH] Fix handling of user_agent from array Closes #172. --- CHANGELOG.md | 7 +++++++ src/MinFraud.php | 4 +--- tests/MaxMind/Test/MinFraudTest.php | 11 +++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09b35cc..34ee593 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ CHANGELOG ========= +3.0.1 (2024-05-02) +------------------ + +* When calling `withDevice` with an array, an exception was incorrectly + thrown if `user_agent` was set but `session_id` was not set. Reported by + Gregor Kuhlmann. GitHub #172. + 3.0.0 (2024-04-16) ------------------ diff --git a/src/MinFraud.php b/src/MinFraud.php index dab89c0..ef996a7 100644 --- a/src/MinFraud.php +++ b/src/MinFraud.php @@ -213,9 +213,7 @@ public function withDevice( $sessionId = (string) $v; } } - if ($sessionId) { - $userAgent = $this->remove($values, 'user_agent'); - } + $userAgent = $this->remove($values, 'user_agent'); $this->verifyEmpty($values); } diff --git a/tests/MaxMind/Test/MinFraudTest.php b/tests/MaxMind/Test/MinFraudTest.php index 307f47a..0200d98 100644 --- a/tests/MaxMind/Test/MinFraudTest.php +++ b/tests/MaxMind/Test/MinFraudTest.php @@ -380,6 +380,17 @@ public function testMissingIpAddressWithoutValidation(string $class, string $ser ); } + /** + * @dataProvider services + */ + public function testUserAgentWithoutSessionId(string $class, string $service): void + { + $this->createMinFraudRequestWithFullResponse( + $service, + request: ['device' => ['user_agent' => 'test']], + )->withDevice(['user_agent' => 'test'])->{$service}(); + } + /** * @dataProvider withMethods */