uppy/packages/@uppy/companion/test/credentials.test.ts
Kevin van Zonneveld e99a17f1fe
companion: port to TypeScript (#6179)
Supersedes #6178.

This branch keeps the exact same final content as #6178, but splits
history for reviewability:

1. `chore(companion): rename source and test files from .js to .ts`
(pure `git mv`, no content changes)
2. `feat(companion): port Companion to TypeScript` (actual
content/type/schema/build updates)

Validation note:
- Final tree is byte-for-byte identical to `ts-companion`
(`7b5b16a298690b0492de4cc4fab744f998b45570`).

---------

Co-authored-by: Mikael Finstad <finstaden@gmail.com>
2026-05-04 20:50:43 +08:00

96 lines
2.5 KiB
TypeScript

import nock from 'nock'
import request from 'supertest'
import {
afterAll,
afterEach,
beforeEach,
describe,
expect,
test,
vi,
} from 'vitest'
import * as tokenService from '../src/server/helpers/jwt.js'
import { nockZoomRevoke, expects as zoomExpects } from './fixtures/zoom.js'
import { getServer } from './mockserver.js'
const { remoteZoomKey, remoteZoomSecret, remoteZoomVerificationToken } =
zoomExpects
vi.mock('express-prom-bundle')
const secret = 'secret'
const getZoomServer = async () =>
getServer({
COMPANION_ZOOM_KEYS_ENDPOINT: 'http://localhost:2111/zoom-keys',
})
const authData = {
zoom: { accessToken: 'token value' },
}
const token = tokenService.generateEncryptedAuthToken(authData, secret)
afterEach(() => {
nock.cleanAll()
})
afterAll(() => {
nock.restore()
})
describe('providers requests with remote oauth keys', () => {
beforeEach(() => {
// mocking request module used to fetch custom oauth credentials
nock('http://localhost:2111')
.post('/zoom-keys')
// @ts-ignore
.reply((uri, { provider, parameters }) => {
if (provider !== 'zoom' || parameters !== 'ZOOM-CREDENTIALS-PARAMS')
return [400]
return [
200,
{
credentials: {
key: remoteZoomKey,
secret: remoteZoomSecret,
verificationToken: remoteZoomVerificationToken,
},
},
]
})
})
test('zoom logout with remote oauth keys happy path', async () => {
nockZoomRevoke({ key: remoteZoomKey, secret: remoteZoomSecret })
const params = { params: 'ZOOM-CREDENTIALS-PARAMS' }
const encodedParams = Buffer.from(
JSON.stringify(params),
'binary',
).toString('base64')
const res = await request(await getZoomServer())
.get('/zoom/logout/')
.set('uppy-auth-token', token)
.set('uppy-credentials-params', encodedParams)
.expect(200)
expect(res.body).toMatchObject({
ok: true,
revoked: true,
})
})
test('zoom logout with wrong credentials params', async () => {
nockZoomRevoke({ key: remoteZoomKey, secret: remoteZoomSecret })
const params = { params: 'WRONG-ZOOM-CREDENTIALS-PARAMS' }
const encodedParams = Buffer.from(
JSON.stringify(params),
'binary',
).toString('base64')
return request(await getZoomServer())
.get('/zoom/logout/')
.set('uppy-auth-token', token)
.set('uppy-credentials-params', encodedParams)
.expect(424)
})
})