Files
speckle-server/packages/server/modules/workspaces/tests/unit/helpers/sso.spec.ts
T
Chuck Driesler b41b08d688 fix(sso): oidc state parameter (#3598)
* feat(sso): use state parameter

* chore(sso): fix tests

* fix(sso): entraid moment

* chore(sso): use specific errors
2024-12-02 18:16:28 +00:00

71 lines
2.8 KiB
TypeScript

import {
buildAuthRedirectUrl,
buildAuthFinalizeRedirectUrl,
buildAuthErrorRedirectUrl,
buildValidationErrorRedirectUrl
} from '@/modules/workspaces/helpers/sso'
import { expect } from 'chai'
import cryptoRandomString from 'crypto-random-string'
describe('buildAuthRedirectUrl', () => {
it('should include workspace slug provided', () => {
const url = buildAuthRedirectUrl('my-workspace')
expect(url.toString().includes('my-workspace')).to.equal(true)
})
})
describe('buildAuthFinalizeRedirectUrl', () => {
it('should include workspace slug provided', () => {
const url = buildAuthFinalizeRedirectUrl('my-workspace')
expect(url.toString().includes('my-workspace')).to.equal(true)
})
it('should include provided params', () => {
const url = buildAuthFinalizeRedirectUrl('my-workspace', { foo: 'bar' })
expect(url.toString().includes('foo')).to.equal(true)
})
})
describe('buildAuthErrorRedirectUrl', () => {
it('should include workspace slug provided', () => {
const url = buildAuthErrorRedirectUrl('my-workspace', 'Test error message')
expect(url.toString().includes('my-workspace')).to.equal(true)
})
it('should include error message provided', () => {
const url = buildAuthErrorRedirectUrl('my-workspace', 'Test error message')
expect(url.toString().includes('ssoError')).to.equal(true)
})
})
describe('buildValidationErrorRedirectUrl', () => {
it('should include workspace slug provided', () => {
const url = buildValidationErrorRedirectUrl('my-workspace', 'Test error message')
expect(url.toString().includes('my-workspace')).to.equal(true)
})
it('should flag the validation flow attempt as failed', () => {
const url = buildValidationErrorRedirectUrl('my-workspace', 'Test error message')
expect(url.toString().includes('ssoValidationSuccess=false')).to.equal(true)
})
it('should include error message provided', () => {
const url = buildValidationErrorRedirectUrl('my-workspace', 'Test error message')
expect(url.toString().includes('ssoError')).to.equal(true)
})
it('should include provider data, if present', () => {
const url = buildValidationErrorRedirectUrl('my-workspace', 'Test error message', {
providerName: 'My SSO Provider',
clientId: 'my-sso-provider',
clientSecret: cryptoRandomString({ length: 9 }),
issuerUrl: 'https://example.org'
})
expect(url.toString().includes('providerName')).to.equal(true)
})
it('should omit the client secret from provider data, if present', () => {
const url = buildValidationErrorRedirectUrl('my-workspace', 'Test error message', {
providerName: 'My SSO Provider',
clientId: 'my-sso-provider',
clientSecret: cryptoRandomString({ length: 9 }),
issuerUrl: 'https://example.org'
})
expect(url.toString().includes('clientSecret')).to.equal(false)
})
})