diff --git a/src/Client.php b/src/Client.php index 11f55a8..bd6a9c3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,6 +4,7 @@ use DateTime; const VERSION = "1.2.1-dev"; +const CA_BUNDLE_VERSION = "1.0"; const INITIAL_BACKOFF_SECONDS = 1; const MAX_BACKOFF_SECONDS = 32; const BACKOFF_FACTOR = 2; @@ -240,7 +241,10 @@ public function apiCall($method, $path, $params, $additional_headers = []) } $headers["Date"] = $now; - $headers["User-Agent"] = "duo_api_php/" . VERSION; + $ca_pinning_status = (!empty($this->options["disable_ca_pinning"])) ? "disabled" : "enabled"; + $headers["User-Agent"] = "duo_api_php/" . VERSION + . " ca_bundle/" . CA_BUNDLE_VERSION + . " (ca_pinning=" . $ca_pinning_status . ")"; $headers["Authorization"] = self::signParameters( $method, $this->host, diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index 416f127..b5adefd 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -493,9 +493,39 @@ public function testUserAgent() $this->anything(), $this->anything(), $this->callback(function($headers) { - $version = "duo_api_php/" . \DuoAPI\VERSION; + $expected = "duo_api_php/" . \DuoAPI\VERSION + . " ca_bundle/" . \DuoAPI\CA_BUNDLE_VERSION + . " (ca_pinning=enabled)"; $this->assertArrayHasKey("User-Agent", $headers); - $this->assertEquals($headers["User-Agent"], $version); + $this->assertEquals($expected, $headers["User-Agent"]); + return true; + }), + $this->anything() + ); + $response = $client->apiCall("GET", "/foo/bar", []); + } + + public function testUserAgentWithCaPinningDisabled() + { + $success_resp = [ + "success" => true, + "response" => "not rate limited", + "http_status_code" => 200, + ]; + + $response = [$success_resp]; + + $client = self::getMockedClient("Client", $response, $paged = true); + $client->disableCaPinning(); + $this->mocked_curl_requester->method('execute')->with( + $this->anything(), + $this->anything(), + $this->callback(function($headers) { + $expected = "duo_api_php/" . \DuoAPI\VERSION + . " ca_bundle/" . \DuoAPI\CA_BUNDLE_VERSION + . " (ca_pinning=disabled)"; + $this->assertArrayHasKey("User-Agent", $headers); + $this->assertEquals($expected, $headers["User-Agent"]); return true; }), $this->anything()