-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathBearerAuthAwareSabreClientTest.php
More file actions
73 lines (61 loc) · 2.26 KB
/
Copy pathBearerAuthAwareSabreClientTest.php
File metadata and controls
73 lines (61 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Files\Storage;
use OC\Files\Storage\BearerAuthAwareSabreClient;
use PHPUnit\Framework\Attributes\CoversClass;
use Test\TestCase;
/**
* @package Test\Files\Storage
*/
#[CoversClass(BearerAuthAwareSabreClient::class)]
class BearerAuthAwareSabreClientTest extends TestCase {
private function getCurlSetting(BearerAuthAwareSabreClient $client, int $key): mixed {
$reflection = new \ReflectionObject($client);
$property = $reflection->getProperty('curlSettings');
$settings = $property->getValue($client);
return $settings[$key] ?? null;
}
public function testBearerTokenIsUsedForAuthentication(): void {
$client = new BearerAuthAwareSabreClient([
'baseUri' => 'https://example.com/',
// The user name holds the long-lived share secret, never the bearer.
'userName' => 'refresh-secret',
'password' => '',
'authType' => BearerAuthAwareSabreClient::AUTH_BEARER,
'bearerToken' => 'the-access-jwt',
]);
$this->assertSame('the-access-jwt', $this->getCurlSetting($client, CURLOPT_XOAUTH2_BEARER));
}
public function testShareSecretIsNotUsedAsBearer(): void {
$client = new BearerAuthAwareSabreClient([
'baseUri' => 'https://example.com/',
'userName' => 'refresh-secret',
'password' => '',
'authType' => BearerAuthAwareSabreClient::AUTH_BEARER,
'bearerToken' => 'the-access-jwt',
]);
$this->assertNotSame('refresh-secret', $this->getCurlSetting($client, CURLOPT_XOAUTH2_BEARER));
}
public function testNoBearerAppliedWithoutBearerAuthType(): void {
$client = new BearerAuthAwareSabreClient([
'baseUri' => 'https://example.com/',
'userName' => 'user',
'password' => 'pass',
'authType' => \Sabre\DAV\Client::AUTH_BASIC,
'bearerToken' => 'the-access-jwt',
]);
$this->assertNull($this->getCurlSetting($client, CURLOPT_XOAUTH2_BEARER));
}
public function testNoBearerAppliedWithoutBearerToken(): void {
$client = new BearerAuthAwareSabreClient([
'baseUri' => 'https://example.com/',
'userName' => 'refresh-secret',
'password' => '',
'authType' => BearerAuthAwareSabreClient::AUTH_BEARER,
]);
$this->assertNull($this->getCurlSetting($client, CURLOPT_XOAUTH2_BEARER));
}
}