|
3 | 3 | */ |
4 | 4 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
5 | 5 | import { listDomainGroups, openGoogleDirectory } from '@/connectors/google-drive/directory' |
| 6 | +import { ConnectorDirectoryGroupAccessError } from '@/connectors/source-error' |
6 | 7 |
|
7 | 8 | const mockFetch = vi.fn() |
8 | 9 |
|
@@ -234,6 +235,61 @@ describe('the membership a directory reports', () => { |
234 | 235 | }) |
235 | 236 | }) |
236 | 237 |
|
| 238 | + it.each([ |
| 239 | + { status: 403, reason: 'forbidden' }, |
| 240 | + { status: 404, reason: 'notFound' }, |
| 241 | + ])( |
| 242 | + 'classifies inaccessible external nested groups explicitly: $status $reason', |
| 243 | + async ({ status, reason }) => { |
| 244 | + directory({ 'eng@corp.com': [USER('alice@corp.com'), NESTED('restricted@external.com')] }) |
| 245 | + const healthy = mockFetch.getMockImplementation()! |
| 246 | + mockFetch.mockImplementation(async (url: string) => { |
| 247 | + if ( |
| 248 | + decodeURIComponent(new URL(url).pathname).includes('/restricted@external.com/members') |
| 249 | + ) { |
| 250 | + return jsonResponse( |
| 251 | + { error: { errors: [{ reason }], message: 'private detail' } }, |
| 252 | + status |
| 253 | + ) |
| 254 | + } |
| 255 | + return healthy(url) |
| 256 | + }) |
| 257 | + const failure = await membersOf(GROUP).catch((error: unknown) => error) |
| 258 | + expect(failure).toBeInstanceOf(ConnectorDirectoryGroupAccessError) |
| 259 | + expect(failure).toMatchObject({ |
| 260 | + cause: { status, diagnostic: { operation: 'directory.members.list', reasons: [reason] } }, |
| 261 | + }) |
| 262 | + expect(String(failure)).not.toContain('private detail') |
| 263 | + } |
| 264 | + ) |
| 265 | + |
| 266 | + it.each([ |
| 267 | + { email: 'restricted@corp.io', status: 403, reasons: ['forbidden'] }, |
| 268 | + { email: 'restricted@external.com', status: 403, reasons: [] }, |
| 269 | + { email: 'restricted@external.com', status: 403, reasons: ['forbidden', 'unknownReason'] }, |
| 270 | + { |
| 271 | + email: 'restricted@external.com', |
| 272 | + status: 403, |
| 273 | + reasons: ['forbidden', 'insufficientPermissions'], |
| 274 | + }, |
| 275 | + { email: 'restricted@external.com', status: 401, reasons: ['authError'] }, |
| 276 | + ])( |
| 277 | + 'does not classify uncertain or customer-owned failures as external access failures: $email $status $reasons', |
| 278 | + async ({ email, status, reasons }) => { |
| 279 | + directory({ 'eng@corp.com': [NESTED(email)] }) |
| 280 | + const healthy = mockFetch.getMockImplementation()! |
| 281 | + mockFetch.mockImplementation(async (url: string) => { |
| 282 | + if (decodeURIComponent(new URL(url).pathname).includes(`/${email}/members`)) { |
| 283 | + return jsonResponse({ error: { errors: reasons.map((reason) => ({ reason })) } }, status) |
| 284 | + } |
| 285 | + return healthy(url) |
| 286 | + }) |
| 287 | + const failure = await membersOf(GROUP).catch((error: unknown) => error) |
| 288 | + expect(failure).not.toBeInstanceOf(ConnectorDirectoryGroupAccessError) |
| 289 | + expect(failure).toMatchObject({ status }) |
| 290 | + } |
| 291 | + ) |
| 292 | + |
237 | 293 | /** A directory that hiccups must not cost a group its membership; transient errors are retried. */ |
238 | 294 | it('retries a transient directory error before giving up', async () => { |
239 | 295 | directory({ 'eng@corp.com': [USER('alice@corp.com')] }) |
|
0 commit comments