Skip to content

Commit

Permalink
PHP API now includes user agent string (#36)
Browse files Browse the repository at this point in the history
* PHP API now includes user agent string

* fix missing parenthesis

* Add -dev to version for development
  • Loading branch information
mbish authored Feb 2, 2024
1 parent 1589f27 commit 292c64e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"support": {
"email": "[email protected]"
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"DuoAPI\\": "src/"
Expand Down
2 changes: 2 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use DateTime;

const VERSION = "1.1.0-dev";
const INITIAL_BACKOFF_SECONDS = 1;
const MAX_BACKOFF_SECONDS = 32;
const BACKOFF_FACTOR = 2;
Expand Down Expand Up @@ -159,6 +160,7 @@ public function apiCall($method, $path, $params)
$headers = [];
$headers["Date"] = $now;
$headers["Host"] = $this->host;
$headers["User-Agent"] = "duo_api_php/" . VERSION;
$headers["Authorization"] = self::signParameters(
$method,
$this->host,
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,29 @@ public function testRateLimitedCompletely()
32 + ($this->random_numbers[5] / 1000),
], ($this->mock_sleep_svc->sleep_calls));
}

public function testUserAgent()
{
$success_resp = [
"success" => true,
"response" => "not rate limited",
"http_status_code" => 200,
];

$response = [$success_resp];

$client = self::getMockedClient("Client", $response, $paged = true);
$this->mocked_curl_requester->method('execute')->with(
$this->anything(),
$this->anything(),
$this->callback(function($headers) {
$version = "duo_api_php/" . \DuoAPI\VERSION;
$this->assertArrayHasKey("User-Agent", $headers);
$this->assertEquals($headers["User-Agent"], $version);
return true;
}),
$this->anything()
);
$response = $client->apiCall("GET", "/foo/bar", []);
}
}

0 comments on commit 292c64e

Please sign in to comment.