-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathSSOTest.php
More file actions
151 lines (137 loc) · 7.26 KB
/
SSOTest.php
File metadata and controls
151 lines (137 loc) · 7.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
declare(strict_types=1);
// This file is auto-generated by oagen. Do not edit.
namespace Tests\Service;
use PHPUnit\Framework\TestCase;
use WorkOS\TestHelper;
class SSOTest extends TestCase
{
use TestHelper;
public function testListConnections(): void
{
$fixture = $this->loadFixture('list_connection');
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
$result = $client->sso()->listConnections(before: 'test_value', after: 'test_value', limit: 1, order: \WorkOS\Resource\EventsOrder::Normal, connectionType: \WorkOS\Resource\ConnectionsConnectionType::Adfssaml, domain: 'test_value', organizationId: 'test_value', search: 'test_value');
$this->assertInstanceOf(\WorkOS\PaginatedResponse::class, $result);
$request = $this->getLastRequest();
$this->assertSame('GET', $request->getMethod());
$this->assertStringEndsWith('connections', $request->getUri()->getPath());
parse_str($request->getUri()->getQuery(), $query);
$this->assertSame('test_value', $query['before']);
$this->assertSame('test_value', $query['after']);
$this->assertArrayHasKey('limit', $query);
$this->assertSame('normal', $query['order']);
$this->assertSame('ADFSSAML', $query['connection_type']);
$this->assertSame('test_value', $query['domain']);
$this->assertSame('test_value', $query['organization_id']);
$this->assertSame('test_value', $query['search']);
}
public function testGetConnection(): void
{
$fixture = $this->loadFixture('connection');
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
$result = $client->sso()->getConnection('test_id');
$this->assertInstanceOf(\WorkOS\Resource\Connection::class, $result);
$this->assertSame($fixture['id'], $result->id);
$this->assertSame($fixture['name'], $result->name);
$this->assertIsArray($result->toArray());
$request = $this->getLastRequest();
$this->assertSame('GET', $request->getMethod());
$this->assertStringEndsWith('connections/test_id', $request->getUri()->getPath());
}
public function testDeleteConnection(): void
{
$client = $this->createMockClient([['status' => 204]]);
$client->sso()->deleteConnection('test_id');
$request = $this->getLastRequest();
$this->assertSame('DELETE', $request->getMethod());
$this->assertStringEndsWith('connections/test_id', $request->getUri()->getPath());
}
public function testGetAuthorizationUrl(): void
{
$client = $this->createMockClient([]);
$result = $client->sso()->getAuthorizationUrl(providerScopes: [], providerQueryParams: [], domain: 'test_value', provider: \WorkOS\Resource\SSOProvider::AppleOAuth, redirectUri: 'test_value', state: 'test_value', connection: 'test_value', organization: 'test_value', domainHint: 'test_value', loginHint: 'test_value', nonce: 'test_value');
$this->assertIsString($result);
$this->assertStringContainsString('sso/authorize', $result);
parse_str(parse_url($result, PHP_URL_QUERY) ?? '', $query);
$this->assertSame('test_value', $query['domain']);
$this->assertSame('AppleOAuth', $query['provider']);
$this->assertSame('test_value', $query['redirect_uri']);
$this->assertSame('test_value', $query['state']);
$this->assertSame('test_value', $query['connection']);
$this->assertSame('test_value', $query['organization']);
$this->assertSame('test_value', $query['domain_hint']);
$this->assertSame('test_value', $query['login_hint']);
$this->assertSame('test_value', $query['nonce']);
$this->assertSame('code', $query['response_type']);
$this->assertArrayHasKey('client_id', $query);
}
public function testGetLogoutUrl(): void
{
$client = $this->createMockClient([]);
$result = $client->sso()->getLogoutUrl(token: 'test_value');
$this->assertIsString($result);
$this->assertStringContainsString('sso/logout', $result);
parse_str(parse_url($result, PHP_URL_QUERY) ?? '', $query);
$this->assertSame('test_value', $query['token']);
}
public function testAuthorizeLogout(): void
{
$fixture = $this->loadFixture('sso_logout_authorize_response');
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
$result = $client->sso()->authorizeLogout(profileId: 'test_value');
$this->assertInstanceOf(\WorkOS\Resource\SSOLogoutAuthorizeResponse::class, $result);
$this->assertSame($fixture['logout_url'], $result->logoutUrl);
$this->assertIsArray($result->toArray());
$request = $this->getLastRequest();
$this->assertSame('POST', $request->getMethod());
$this->assertStringEndsWith('sso/logout/authorize', $request->getUri()->getPath());
$body = json_decode((string) $request->getBody(), true);
$this->assertSame('test_value', $body['profile_id']);
}
public function testGetProfile(): void
{
$fixture = $this->loadFixture('profile');
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
$result = $client->sso()->getProfile();
$this->assertInstanceOf(\WorkOS\Resource\Profile::class, $result);
$this->assertSame($fixture['id'], $result->id);
$this->assertSame($fixture['connection_id'], $result->connectionId);
$this->assertIsArray($result->toArray());
$request = $this->getLastRequest();
$this->assertSame('GET', $request->getMethod());
$this->assertStringEndsWith('sso/profile', $request->getUri()->getPath());
}
public function testGetProfileAndToken(): void
{
$fixture = $this->loadFixture('sso_token_response');
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
$result = $client->sso()->getProfileAndToken(code: 'test_value');
$this->assertInstanceOf(\WorkOS\Resource\SSOTokenResponse::class, $result);
$this->assertSame($fixture['access_token'], $result->accessToken);
$this->assertIsArray($result->toArray());
$request = $this->getLastRequest();
$this->assertSame('POST', $request->getMethod());
$this->assertStringEndsWith('sso/token', $request->getUri()->getPath());
$body = json_decode((string) $request->getBody(), true);
$this->assertSame('test_value', $body['code']);
}
public function testPaginationBoundary(): void
{
$fixture = $this->loadFixture('list_connection');
// Ensure cursors are null (first/last page boundary)
$fixture['list_metadata']['before'] = null;
$fixture['list_metadata']['after'] = null;
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
$result = $client->sso()->listConnections();
$this->assertInstanceOf(\WorkOS\PaginatedResponse::class, $result);
// Verify cursors are null on boundary page
$this->assertNull($result->listMetadata['before']);
$this->assertNull($result->listMetadata['after']);
// Iterating should not throw on null cursors
foreach ($result as $item) {
$this->assertNotNull($item);
break;
}
}
}