Skip to content

Commit 292c64e

Browse files
authored
PHP API now includes user agent string (#36)
* PHP API now includes user agent string * fix missing parenthesis * Add -dev to version for development
1 parent 1589f27 commit 292c64e

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"support": {
66
"email": "support@duosecurity.com"
77
},
8+
"extra": {
9+
"branch-alias": {
10+
"dev-master": "1.1.x-dev"
11+
}
12+
},
813
"autoload": {
914
"psr-4": {
1015
"DuoAPI\\": "src/"

src/Client.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use DateTime;
55

6+
const VERSION = "1.1.0-dev";
67
const INITIAL_BACKOFF_SECONDS = 1;
78
const MAX_BACKOFF_SECONDS = 32;
89
const BACKOFF_FACTOR = 2;
@@ -159,6 +160,7 @@ public function apiCall($method, $path, $params)
159160
$headers = [];
160161
$headers["Date"] = $now;
161162
$headers["Host"] = $this->host;
163+
$headers["User-Agent"] = "duo_api_php/" . VERSION;
162164
$headers["Authorization"] = self::signParameters(
163165
$method,
164166
$this->host,

tests/Unit/ClientTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,29 @@ public function testRateLimitedCompletely()
317317
32 + ($this->random_numbers[5] / 1000),
318318
], ($this->mock_sleep_svc->sleep_calls));
319319
}
320+
321+
public function testUserAgent()
322+
{
323+
$success_resp = [
324+
"success" => true,
325+
"response" => "not rate limited",
326+
"http_status_code" => 200,
327+
];
328+
329+
$response = [$success_resp];
330+
331+
$client = self::getMockedClient("Client", $response, $paged = true);
332+
$this->mocked_curl_requester->method('execute')->with(
333+
$this->anything(),
334+
$this->anything(),
335+
$this->callback(function($headers) {
336+
$version = "duo_api_php/" . \DuoAPI\VERSION;
337+
$this->assertArrayHasKey("User-Agent", $headers);
338+
$this->assertEquals($headers["User-Agent"], $version);
339+
return true;
340+
}),
341+
$this->anything()
342+
);
343+
$response = $client->apiCall("GET", "/foo/bar", []);
344+
}
320345
}

0 commit comments

Comments
 (0)