LibreChat/api/server/routes/__tests__/config.spec.js

291 lines
9.9 KiB
JavaScript
Raw Normal View History

jest.mock('~/cache/getLogStores');
⚖️ refactor: Split Config Route into Unauthenticated and Authenticated Paths (#12490) * refactor: split /api/config into unauthenticated and authenticated response paths - Replace preAuthTenantMiddleware with optionalJwtAuth on the /api/config route so the handler can detect whether the request is authenticated - When unauthenticated: call getAppConfig({ baseOnly: true }) for zero DB queries, return only login-relevant fields (social logins, turnstile, privacy policy / terms of service from interface config) - When authenticated: call getAppConfig({ role, userId, tenantId }) to resolve per-user DB overrides (USER + ROLE + GROUP + PUBLIC principals), return full payload including modelSpecs, balance, webSearch, etc. - Extract buildSharedPayload() and addWebSearchConfig() helpers to avoid duplication between the two code paths - Fixes per-user balance overrides not appearing in the frontend because userId was never passed to getAppConfig (follow-up to #12474) * test: rewrite config route tests for unauthenticated vs authenticated paths - Replace the previously-skipped supertest tests with proper mocked tests - Cover unauthenticated path: baseOnly config call, minimal payload, interface subset (privacyPolicy/termsOfService only), exclusion of authenticated-only fields - Cover authenticated path: getAppConfig called with userId, full payload including modelSpecs/balance/webSearch, per-user balance override merging * fix: address review findings — restore multi-tenant support, improve tests - Chain preAuthTenantMiddleware back before optionalJwtAuth on /api/config so unauthenticated requests in multi-tenant deployments still get tenant-scoped config via X-Tenant-Id header (Finding #1) - Use getAppConfig({ tenantId }) instead of getAppConfig({ baseOnly: true }) when a tenant context is present; fall back to baseOnly for single-tenant - Fix @type annotation: unauthenticated payload is Partial<TStartupConfig> - Refactor addWebSearchConfig into pure buildWebSearchConfig that returns a value instead of mutating the payload argument - Hoist isBirthday() to module level - Remove inline narration comments - Assert tenantId propagation in tests, including getTenantId fallback and user.tenantId preference - Add error-path tests for both unauthenticated and authenticated branches - Expand afterEach env var cleanup for proper test isolation * test: fix mock isolation and add tenant-scoped response test - Replace jest.clearAllMocks() with jest.resetAllMocks() so mockReturnValue implementations don't leak between tests - Add test verifying tenant-scoped socialLogins and turnstile are correctly mapped in the unauthenticated response * fix: add optionalJwtAuth to /api/config in experimental.js Without this middleware, req.user is never populated in the experimental cluster entrypoint, so authenticated users always receive the minimal unauthenticated config payload.
2026-03-31 19:22:51 -04:00
const mockGetAppConfig = jest.fn();
jest.mock('~/server/services/Config/app', () => ({
getAppConfig: (...args) => mockGetAppConfig(...args),
}));
jest.mock('~/server/services/Config/ldap', () => ({
getLdapConfig: jest.fn(() => null),
}));
const mockGetTenantId = jest.fn(() => undefined);
jest.mock('@librechat/data-schemas', () => ({
...jest.requireActual('@librechat/data-schemas'),
getTenantId: (...args) => mockGetTenantId(...args),
}));
const request = require('supertest');
const express = require('express');
*️⃣ feat: Reuse OpenID Auth Tokens (#7397) * feat: integrate OpenID Connect support with token reuse - Added `jwks-rsa` and `new-openid-client` dependencies for OpenID Connect functionality. - Implemented OpenID token refresh logic in `AuthController`. - Enhanced `LogoutController` to handle OpenID logout and session termination. - Updated JWT authentication middleware to support OpenID token provider. - Modified OAuth routes to accommodate OpenID authentication and token management. - Created `setOpenIDAuthTokens` function to manage OpenID tokens in cookies. - Upgraded OpenID strategy with user info fetching and token exchange protocol. - Introduced `openIdJwtLogin` strategy for handling OpenID JWT tokens. - Added caching mechanism for exchanged OpenID tokens. - Updated configuration to include OpenID exchanged tokens cache key. - updated .env.example to include the new env variables needed for the feature. * fix: update return type in downloadImage documentation for clarity and fixed openIdJwtLogin env variables * fix: update Jest configuration and tests for OpenID strategy integration * fix: update OpenID strategy to include callback URL in setup * fix: fix optionalJwtAuth middleware to support OpenID token reuse and improve currentUrl method in CustomOpenIDStrategy to override the dynamic host issue related to proxy (e.g. cloudfront) * fix: fixed code formatting * Fix: Add mocks for openid-client and passport strategy in Jest configuration to fix unit tests * fix eslint errors: Format mock file openid-client. * ✨ feat: Add PKCE support for OpenID and default handling in strategy setup --------- Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com> Co-authored-by: Ruben Talstra <RubenTalstra1211@outlook.com>
2025-05-22 14:19:24 +02:00
const configRoute = require('../config');
⚖️ refactor: Split Config Route into Unauthenticated and Authenticated Paths (#12490) * refactor: split /api/config into unauthenticated and authenticated response paths - Replace preAuthTenantMiddleware with optionalJwtAuth on the /api/config route so the handler can detect whether the request is authenticated - When unauthenticated: call getAppConfig({ baseOnly: true }) for zero DB queries, return only login-relevant fields (social logins, turnstile, privacy policy / terms of service from interface config) - When authenticated: call getAppConfig({ role, userId, tenantId }) to resolve per-user DB overrides (USER + ROLE + GROUP + PUBLIC principals), return full payload including modelSpecs, balance, webSearch, etc. - Extract buildSharedPayload() and addWebSearchConfig() helpers to avoid duplication between the two code paths - Fixes per-user balance overrides not appearing in the frontend because userId was never passed to getAppConfig (follow-up to #12474) * test: rewrite config route tests for unauthenticated vs authenticated paths - Replace the previously-skipped supertest tests with proper mocked tests - Cover unauthenticated path: baseOnly config call, minimal payload, interface subset (privacyPolicy/termsOfService only), exclusion of authenticated-only fields - Cover authenticated path: getAppConfig called with userId, full payload including modelSpecs/balance/webSearch, per-user balance override merging * fix: address review findings — restore multi-tenant support, improve tests - Chain preAuthTenantMiddleware back before optionalJwtAuth on /api/config so unauthenticated requests in multi-tenant deployments still get tenant-scoped config via X-Tenant-Id header (Finding #1) - Use getAppConfig({ tenantId }) instead of getAppConfig({ baseOnly: true }) when a tenant context is present; fall back to baseOnly for single-tenant - Fix @type annotation: unauthenticated payload is Partial<TStartupConfig> - Refactor addWebSearchConfig into pure buildWebSearchConfig that returns a value instead of mutating the payload argument - Hoist isBirthday() to module level - Remove inline narration comments - Assert tenantId propagation in tests, including getTenantId fallback and user.tenantId preference - Add error-path tests for both unauthenticated and authenticated branches - Expand afterEach env var cleanup for proper test isolation * test: fix mock isolation and add tenant-scoped response test - Replace jest.clearAllMocks() with jest.resetAllMocks() so mockReturnValue implementations don't leak between tests - Add test verifying tenant-scoped socialLogins and turnstile are correctly mapped in the unauthenticated response * fix: add optionalJwtAuth to /api/config in experimental.js Without this middleware, req.user is never populated in the experimental cluster entrypoint, so authenticated users always receive the minimal unauthenticated config payload.
2026-03-31 19:22:51 -04:00
function createApp(user) {
const app = express();
app.disable('x-powered-by');
if (user) {
app.use((req, _res, next) => {
req.user = user;
next();
});
}
app.use('/api/config', configRoute);
return app;
}
const baseAppConfig = {
registration: { socialLogins: ['google', 'github'] },
interfaceConfig: {
privacyPolicy: { externalUrl: 'https://example.com/privacy' },
termsOfService: { externalUrl: 'https://example.com/tos' },
modelSelect: true,
},
turnstileConfig: { siteKey: 'test-key' },
modelSpecs: { list: [{ name: 'test-spec' }] },
webSearch: { searchProvider: 'tavily' },
};
const mockUser = {
id: 'user123',
role: 'USER',
tenantId: undefined,
};
afterEach(() => {
⚖️ refactor: Split Config Route into Unauthenticated and Authenticated Paths (#12490) * refactor: split /api/config into unauthenticated and authenticated response paths - Replace preAuthTenantMiddleware with optionalJwtAuth on the /api/config route so the handler can detect whether the request is authenticated - When unauthenticated: call getAppConfig({ baseOnly: true }) for zero DB queries, return only login-relevant fields (social logins, turnstile, privacy policy / terms of service from interface config) - When authenticated: call getAppConfig({ role, userId, tenantId }) to resolve per-user DB overrides (USER + ROLE + GROUP + PUBLIC principals), return full payload including modelSpecs, balance, webSearch, etc. - Extract buildSharedPayload() and addWebSearchConfig() helpers to avoid duplication between the two code paths - Fixes per-user balance overrides not appearing in the frontend because userId was never passed to getAppConfig (follow-up to #12474) * test: rewrite config route tests for unauthenticated vs authenticated paths - Replace the previously-skipped supertest tests with proper mocked tests - Cover unauthenticated path: baseOnly config call, minimal payload, interface subset (privacyPolicy/termsOfService only), exclusion of authenticated-only fields - Cover authenticated path: getAppConfig called with userId, full payload including modelSpecs/balance/webSearch, per-user balance override merging * fix: address review findings — restore multi-tenant support, improve tests - Chain preAuthTenantMiddleware back before optionalJwtAuth on /api/config so unauthenticated requests in multi-tenant deployments still get tenant-scoped config via X-Tenant-Id header (Finding #1) - Use getAppConfig({ tenantId }) instead of getAppConfig({ baseOnly: true }) when a tenant context is present; fall back to baseOnly for single-tenant - Fix @type annotation: unauthenticated payload is Partial<TStartupConfig> - Refactor addWebSearchConfig into pure buildWebSearchConfig that returns a value instead of mutating the payload argument - Hoist isBirthday() to module level - Remove inline narration comments - Assert tenantId propagation in tests, including getTenantId fallback and user.tenantId preference - Add error-path tests for both unauthenticated and authenticated branches - Expand afterEach env var cleanup for proper test isolation * test: fix mock isolation and add tenant-scoped response test - Replace jest.clearAllMocks() with jest.resetAllMocks() so mockReturnValue implementations don't leak between tests - Add test verifying tenant-scoped socialLogins and turnstile are correctly mapped in the unauthenticated response * fix: add optionalJwtAuth to /api/config in experimental.js Without this middleware, req.user is never populated in the experimental cluster entrypoint, so authenticated users always receive the minimal unauthenticated config payload.
2026-03-31 19:22:51 -04:00
jest.resetAllMocks();
delete process.env.APP_TITLE;
⚖️ refactor: Split Config Route into Unauthenticated and Authenticated Paths (#12490) * refactor: split /api/config into unauthenticated and authenticated response paths - Replace preAuthTenantMiddleware with optionalJwtAuth on the /api/config route so the handler can detect whether the request is authenticated - When unauthenticated: call getAppConfig({ baseOnly: true }) for zero DB queries, return only login-relevant fields (social logins, turnstile, privacy policy / terms of service from interface config) - When authenticated: call getAppConfig({ role, userId, tenantId }) to resolve per-user DB overrides (USER + ROLE + GROUP + PUBLIC principals), return full payload including modelSpecs, balance, webSearch, etc. - Extract buildSharedPayload() and addWebSearchConfig() helpers to avoid duplication between the two code paths - Fixes per-user balance overrides not appearing in the frontend because userId was never passed to getAppConfig (follow-up to #12474) * test: rewrite config route tests for unauthenticated vs authenticated paths - Replace the previously-skipped supertest tests with proper mocked tests - Cover unauthenticated path: baseOnly config call, minimal payload, interface subset (privacyPolicy/termsOfService only), exclusion of authenticated-only fields - Cover authenticated path: getAppConfig called with userId, full payload including modelSpecs/balance/webSearch, per-user balance override merging * fix: address review findings — restore multi-tenant support, improve tests - Chain preAuthTenantMiddleware back before optionalJwtAuth on /api/config so unauthenticated requests in multi-tenant deployments still get tenant-scoped config via X-Tenant-Id header (Finding #1) - Use getAppConfig({ tenantId }) instead of getAppConfig({ baseOnly: true }) when a tenant context is present; fall back to baseOnly for single-tenant - Fix @type annotation: unauthenticated payload is Partial<TStartupConfig> - Refactor addWebSearchConfig into pure buildWebSearchConfig that returns a value instead of mutating the payload argument - Hoist isBirthday() to module level - Remove inline narration comments - Assert tenantId propagation in tests, including getTenantId fallback and user.tenantId preference - Add error-path tests for both unauthenticated and authenticated branches - Expand afterEach env var cleanup for proper test isolation * test: fix mock isolation and add tenant-scoped response test - Replace jest.clearAllMocks() with jest.resetAllMocks() so mockReturnValue implementations don't leak between tests - Add test verifying tenant-scoped socialLogins and turnstile are correctly mapped in the unauthenticated response * fix: add optionalJwtAuth to /api/config in experimental.js Without this middleware, req.user is never populated in the experimental cluster entrypoint, so authenticated users always receive the minimal unauthenticated config payload.
2026-03-31 19:22:51 -04:00
delete process.env.CHECK_BALANCE;
delete process.env.START_BALANCE;
delete process.env.SANDPACK_BUNDLER_URL;
delete process.env.SANDPACK_STATIC_BUNDLER_URL;
delete process.env.CONVERSATION_IMPORT_MAX_FILE_SIZE_BYTES;
delete process.env.ALLOW_REGISTRATION;
delete process.env.ALLOW_SOCIAL_LOGIN;
delete process.env.ALLOW_PASSWORD_RESET;
delete process.env.DOMAIN_SERVER;
delete process.env.GOOGLE_CLIENT_ID;
delete process.env.GOOGLE_CLIENT_SECRET;
OpenID Authentication (#495) * Squashed commit of the following: commit 26ab03fb36fcc7fcee63fdf3ae8c2dfb29027eff Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:23:23 2023 -0500 Update Registration.spec.tsx commit e908dd82fe9ef1b43c75ee64c183d2f654bdac1c Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:23:01 2023 -0500 Update Login.spec.tsx commit 223734820fb77d7fb5af4802af642d1c1fd7c1f5 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:22:39 2023 -0500 Update Registration.tsx commit 7036d3dd0538979ee397d958ebc113bb0ea32411 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:21:55 2023 -0500 Update Login.tsx commit 76bb78221db3195fd930fe9cfd6a5da7194fa759 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:21:03 2023 -0500 Update envConstants.js commit ee2f69f33d75fbb57022afbcd9564bca38a46bee Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:20:08 2023 -0500 Update docker-compose.yml commit 5ac72d789b3446884c6e2f4f595cbf67d731d43c Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:18:41 2023 -0500 Update Dockerfile commit d24341db2bd5b17eb89ab01e171a5f51f3beab0a Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:16:38 2023 -0500 Update .env.example commit 22154f4a09c5fcdfee95d43609fb01a5a883b7a9 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:07:48 2023 -0500 Update Registration.spec.tsx commit 5163f7d372a6a03c94f4357b358211a03369456e Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:07:30 2023 -0500 Update Login.spec.tsx commit 61da49e330a9376e130b24dc944854f97ab58d80 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:07:00 2023 -0500 Update Registration.tsx commit 0e45d3f0dbde34388ff2f0b2dc51b983b472eb05 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:06:18 2023 -0500 Update Login.tsx commit dca1e5367e5f3b468c7964218cc5914ca53095af Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:05:07 2023 -0500 Update envConstants.js commit f48c058465d82b03716ba85224e9f97007e014d2 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:04:05 2023 -0500 Update .env.example commit 818226c9cb079acae4fcbfe5997e4aa9e3c6d2cc Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:59:08 2023 -0500 Update .env.example commit 9a805439189b352a38ac7654d7a31bb28f0f58dd Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:58:31 2023 -0500 Update env.d.ts commit 3f37ce54758b017c9281b7fad9b040a47630ec66 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:57:04 2023 -0500 Update .env.example commit 1026036f4dd529e9531c53084450ce768cfca4c1 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:50:36 2023 -0500 Update docker-compose.yml commit a61cf7b8c51d4a9bd73a20bd67abc29891c11463 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:50:00 2023 -0500 Update Dockerfile commit 79610d6648755cd5ec45215b9fdbe04ba8242fcf Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:35:34 2023 -0500 Update package-lock.json commit e40853fd2b77f2db5be1c3dfd8b170d650e23271 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:30:17 2023 -0500 Update envConstants.js commit 5529bc61b43f279fb4418c3851be2f9011b6454d Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:25:58 2023 -0500 Update docker-compose.yml commit 07848cc464a64f7cad484e24a1310dc61aa03b18 Merge: ec628a3 72e9828 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:24:03 2023 -0500 Merge branch 'danny-avila:main' into openid-client commit ec628a3044ba963b4e733c72229400074e7c2bc4 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:23:16 2023 -0500 Update envConstants.js commit 21272221db0f58c244f08335482d45b177d338ab Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:21:59 2023 -0500 Update Registration.spec.tsx commit d3f2949c0484d5760e7b689501852f86209992a3 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:21:12 2023 -0500 Update Login.spec.tsx commit f2cf23ddd6708a3bb8d032dde5f1ce300dbe8cad Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:20:15 2023 -0500 Update Registration.tsx commit 482c346b2a7baf958665c9474223d2557504dee5 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:17:53 2023 -0500 Update Login.tsx commit 2f017aa5bf4ef91b73fe027fb346132e1a5d8b87 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:14:17 2023 -0500 Update env.d.ts commit addfd95cf93ef19cae05bab652d634af64313e6a Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:13:16 2023 -0500 Create openidStrategy.js commit 84c3b5c2f078494d8380f3a02e3ba2d935d8d79f Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:09:02 2023 -0500 Update oauth.js commit 63225cdf33b7f42005b4a446797acbd91b7ee4a7 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:07:35 2023 -0500 Update index.js commit 6efe4dafd4359ed1c3139468bf9d43f70bbaf6aa Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:04:55 2023 -0500 Update package.json commit 201badbbb5a5c8d48f5c4cba3a1349d4cfc7a070 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:03:37 2023 -0500 Update User.js commit 7d13d5c303465be9b1268e5f6d9bdf7bb8dfb2e4 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:02:29 2023 -0500 Update Dockerfile commit 2ef7f84ea77f281c3dce61211d9fd841a6424e65 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:00:42 2023 -0500 Update .env.example * Update openidStrategy.js * Update .env.example * Update .env.example * Update docker-compose.yml * Update env.d.ts * Update .env.example * Update .env.example * Update config.js * Update Login.tsx * Update config.js * Update Login.tsx * Update Registration.tsx * Update docker-compose.yml * Update openidStrategy.js * Update docker-compose.yml * Update config.spec.js * Update Login.spec.tsx * Update Registration.spec.tsx * Update types.ts * Update .env.example * Update package-lock.json * Update openidStrategy.js * Update openidStrategy.js * Update config.js * Update config.js * Update Login.tsx * Update Registration.tsx * Update oauth.js * Update openidStrategy.js * Update openidStrategy.js * Update Registration.tsx * Update Login.tsx * Update Login.tsx * Update Registration.tsx * Update Registration.tsx * Update index.js * Update index.js * Update .env.example * Update user_auth_system.md updated instruction that includes OpenID set up * Update package.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update openidStrategy.js * Update openidStrategy.js Lookup user based on openID instead of email. This is because not all AzureAD users may have an email tied to their account * Update openidStrategy.js First try to match an email, then try openIdID * Update openidStrategy.js * Update openidStrategy.js Consider a family name or given name is not provided --------- Co-authored-by: Fuegovic <32828263+fuegovic@users.noreply.github.com>
2023-06-24 21:45:52 -05:00
delete process.env.OPENID_CLIENT_ID;
delete process.env.OPENID_CLIENT_SECRET;
delete process.env.OPENID_ISSUER;
delete process.env.OPENID_SESSION_SECRET;
delete process.env.GITHUB_CLIENT_ID;
delete process.env.GITHUB_CLIENT_SECRET;
Discord Login (#615) * Add files via upload * Create linode-setup.md * Create cloudflare-setup.md * Update cloudflare-setup.md * Delete 4-linode.png * Delete 3-linode.png * Add files via upload * Add files via upload * Update cloudflare-setup.md * Update linode-setup.md * Rename cloudflare-setup.md to cloudflare.md * Rename linode-setup.md to linode.md * Update mkdocs.yml * Update cloudflare.md * Update linode.md * Update README.md * Update README.md * Update linode.md sentence in Italian * v1 The frontend has been completed, along with the .env variables. However, there is an issue of infinite loading thereafter. * Fix email and remove deprecated GitHub passport * Update user_auth_system.md add How to Set Up a Github Authentication * Update .env.example Improved the comment above the GitHub client ID and secret. * Update user_auth_system.md * Update package.json * Remove unnecessary passport GitHub package * fixed conflicts fixed conflicts between Berry-13:main and danny-avila:main in api/server/index.js 45:54 * Delete e -i HEAD~2 * (WIP) Discord Login * Fix duplicate githubLoginEnabled * .env.example restore * Update user_auth_system.md Discord Login * Fix and new Feature 1. Added Discord login to .env.example. 2. Created Google, Github, and Discord icons in client\src\components\svg. 3. Added the social login option in the .env file; it fixes the ---or---. Check Discord for more information. * fix Login.tsx and Registration.tsx * Update user_auth_system.md * Update .env.example * Added OpenID Icon * quick discord icon fix * discord strategy fix * remove comment
2023-07-11 23:17:58 +02:00
delete process.env.DISCORD_CLIENT_ID;
delete process.env.DISCORD_CLIENT_SECRET;
delete process.env.SAML_ENTRY_POINT;
delete process.env.SAML_ISSUER;
delete process.env.SAML_CERT;
delete process.env.SAML_SESSION_SECRET;
});
⚖️ refactor: Split Config Route into Unauthenticated and Authenticated Paths (#12490) * refactor: split /api/config into unauthenticated and authenticated response paths - Replace preAuthTenantMiddleware with optionalJwtAuth on the /api/config route so the handler can detect whether the request is authenticated - When unauthenticated: call getAppConfig({ baseOnly: true }) for zero DB queries, return only login-relevant fields (social logins, turnstile, privacy policy / terms of service from interface config) - When authenticated: call getAppConfig({ role, userId, tenantId }) to resolve per-user DB overrides (USER + ROLE + GROUP + PUBLIC principals), return full payload including modelSpecs, balance, webSearch, etc. - Extract buildSharedPayload() and addWebSearchConfig() helpers to avoid duplication between the two code paths - Fixes per-user balance overrides not appearing in the frontend because userId was never passed to getAppConfig (follow-up to #12474) * test: rewrite config route tests for unauthenticated vs authenticated paths - Replace the previously-skipped supertest tests with proper mocked tests - Cover unauthenticated path: baseOnly config call, minimal payload, interface subset (privacyPolicy/termsOfService only), exclusion of authenticated-only fields - Cover authenticated path: getAppConfig called with userId, full payload including modelSpecs/balance/webSearch, per-user balance override merging * fix: address review findings — restore multi-tenant support, improve tests - Chain preAuthTenantMiddleware back before optionalJwtAuth on /api/config so unauthenticated requests in multi-tenant deployments still get tenant-scoped config via X-Tenant-Id header (Finding #1) - Use getAppConfig({ tenantId }) instead of getAppConfig({ baseOnly: true }) when a tenant context is present; fall back to baseOnly for single-tenant - Fix @type annotation: unauthenticated payload is Partial<TStartupConfig> - Refactor addWebSearchConfig into pure buildWebSearchConfig that returns a value instead of mutating the payload argument - Hoist isBirthday() to module level - Remove inline narration comments - Assert tenantId propagation in tests, including getTenantId fallback and user.tenantId preference - Add error-path tests for both unauthenticated and authenticated branches - Expand afterEach env var cleanup for proper test isolation * test: fix mock isolation and add tenant-scoped response test - Replace jest.clearAllMocks() with jest.resetAllMocks() so mockReturnValue implementations don't leak between tests - Add test verifying tenant-scoped socialLogins and turnstile are correctly mapped in the unauthenticated response * fix: add optionalJwtAuth to /api/config in experimental.js Without this middleware, req.user is never populated in the experimental cluster entrypoint, so authenticated users always receive the minimal unauthenticated config payload.
2026-03-31 19:22:51 -04:00
describe('GET /api/config', () => {
describe('unauthenticated (no req.user)', () => {
it('should call getAppConfig with baseOnly when no tenant context', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
mockGetTenantId.mockReturnValue(undefined);
const app = createApp(null);
await request(app).get('/api/config');
expect(mockGetAppConfig).toHaveBeenCalledWith({ baseOnly: true });
});
it('should call getAppConfig with tenantId when tenant context is present', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
mockGetTenantId.mockReturnValue('tenant-abc');
const app = createApp(null);
await request(app).get('/api/config');
expect(mockGetAppConfig).toHaveBeenCalledWith({ tenantId: 'tenant-abc' });
});
it('should map tenant-scoped config fields in unauthenticated response', async () => {
const tenantConfig = {
...baseAppConfig,
registration: { socialLogins: ['saml'] },
turnstileConfig: { siteKey: 'tenant-key' },
};
mockGetAppConfig.mockResolvedValue(tenantConfig);
mockGetTenantId.mockReturnValue('tenant-abc');
const app = createApp(null);
const response = await request(app).get('/api/config');
expect(response.statusCode).toBe(200);
expect(response.body.socialLogins).toEqual(['saml']);
expect(response.body.turnstile).toEqual({ siteKey: 'tenant-key' });
expect(response.body).not.toHaveProperty('modelSpecs');
});
it('should return minimal payload without authenticated-only fields', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
const app = createApp(null);
const response = await request(app).get('/api/config');
expect(response.statusCode).toBe(200);
expect(response.body).not.toHaveProperty('modelSpecs');
expect(response.body).not.toHaveProperty('balance');
expect(response.body).not.toHaveProperty('webSearch');
expect(response.body).not.toHaveProperty('bundlerURL');
expect(response.body).not.toHaveProperty('staticBundlerURL');
expect(response.body).not.toHaveProperty('sharePointFilePickerEnabled');
expect(response.body).not.toHaveProperty('conversationImportMaxFileSize');
});
it('should include socialLogins and turnstile from base config', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
const app = createApp(null);
const response = await request(app).get('/api/config');
expect(response.body.socialLogins).toEqual(['google', 'github']);
expect(response.body.turnstile).toEqual({ siteKey: 'test-key' });
});
it('should include only privacyPolicy and termsOfService from interface config', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
const app = createApp(null);
const response = await request(app).get('/api/config');
expect(response.body.interface).toEqual({
privacyPolicy: { externalUrl: 'https://example.com/privacy' },
termsOfService: { externalUrl: 'https://example.com/tos' },
});
expect(response.body.interface).not.toHaveProperty('modelSelect');
});
it('should not include interface if no privacyPolicy or termsOfService', async () => {
mockGetAppConfig.mockResolvedValue({
...baseAppConfig,
interfaceConfig: { modelSelect: true },
});
const app = createApp(null);
const response = await request(app).get('/api/config');
expect(response.body).not.toHaveProperty('interface');
});
it('should include shared env var fields', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
process.env.APP_TITLE = 'Test App';
const app = createApp(null);
const response = await request(app).get('/api/config');
expect(response.body.appTitle).toBe('Test App');
expect(response.body).toHaveProperty('emailLoginEnabled');
expect(response.body).toHaveProperty('serverDomain');
});
it('should return 500 when getAppConfig throws', async () => {
mockGetAppConfig.mockRejectedValue(new Error('Config service failure'));
const app = createApp(null);
const response = await request(app).get('/api/config');
expect(response.statusCode).toBe(500);
expect(response.body).toHaveProperty('error');
});
});
describe('authenticated (req.user exists)', () => {
it('should call getAppConfig with role, userId, and tenantId', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
mockGetTenantId.mockReturnValue('fallback-tenant');
const app = createApp(mockUser);
await request(app).get('/api/config');
expect(mockGetAppConfig).toHaveBeenCalledWith({
role: 'USER',
userId: 'user123',
tenantId: 'fallback-tenant',
});
});
it('should prefer user tenantId over getTenantId fallback', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
mockGetTenantId.mockReturnValue('fallback-tenant');
const app = createApp({ ...mockUser, tenantId: 'user-tenant' });
await request(app).get('/api/config');
expect(mockGetAppConfig).toHaveBeenCalledWith({
role: 'USER',
userId: 'user123',
tenantId: 'user-tenant',
});
});
it('should include modelSpecs, balance, and webSearch', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
process.env.CHECK_BALANCE = 'true';
process.env.START_BALANCE = '10000';
const app = createApp(mockUser);
const response = await request(app).get('/api/config');
expect(response.body.modelSpecs).toEqual({ list: [{ name: 'test-spec' }] });
expect(response.body.balance).toEqual({ enabled: true, startBalance: 10000 });
expect(response.body.webSearch).toEqual({ searchProvider: 'tavily' });
});
it('should include full interface config', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
const app = createApp(mockUser);
const response = await request(app).get('/api/config');
expect(response.body.interface).toEqual(baseAppConfig.interfaceConfig);
});
it('should include authenticated-only env var fields', async () => {
mockGetAppConfig.mockResolvedValue(baseAppConfig);
process.env.SANDPACK_BUNDLER_URL = 'https://bundler.test';
process.env.SANDPACK_STATIC_BUNDLER_URL = 'https://static-bundler.test';
process.env.CONVERSATION_IMPORT_MAX_FILE_SIZE_BYTES = '5000000';
const app = createApp(mockUser);
const response = await request(app).get('/api/config');
expect(response.body.bundlerURL).toBe('https://bundler.test');
expect(response.body.staticBundlerURL).toBe('https://static-bundler.test');
expect(response.body.conversationImportMaxFileSize).toBe(5000000);
});
it('should merge per-user balance override into config', async () => {
mockGetAppConfig.mockResolvedValue({
...baseAppConfig,
balance: {
enabled: true,
startBalance: 50000,
},
});
const app = createApp(mockUser);
const response = await request(app).get('/api/config');
expect(response.body.balance).toEqual(
expect.objectContaining({
enabled: true,
startBalance: 50000,
}),
);
});
it('should return 500 when getAppConfig throws', async () => {
mockGetAppConfig.mockRejectedValue(new Error('Config service failure'));
const app = createApp(mockUser);
const response = await request(app).get('/api/config');
expect(response.statusCode).toBe(500);
expect(response.body).toHaveProperty('error');
});
});
OpenID Authentication (#495) * Squashed commit of the following: commit 26ab03fb36fcc7fcee63fdf3ae8c2dfb29027eff Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:23:23 2023 -0500 Update Registration.spec.tsx commit e908dd82fe9ef1b43c75ee64c183d2f654bdac1c Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:23:01 2023 -0500 Update Login.spec.tsx commit 223734820fb77d7fb5af4802af642d1c1fd7c1f5 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:22:39 2023 -0500 Update Registration.tsx commit 7036d3dd0538979ee397d958ebc113bb0ea32411 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:21:55 2023 -0500 Update Login.tsx commit 76bb78221db3195fd930fe9cfd6a5da7194fa759 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:21:03 2023 -0500 Update envConstants.js commit ee2f69f33d75fbb57022afbcd9564bca38a46bee Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:20:08 2023 -0500 Update docker-compose.yml commit 5ac72d789b3446884c6e2f4f595cbf67d731d43c Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:18:41 2023 -0500 Update Dockerfile commit d24341db2bd5b17eb89ab01e171a5f51f3beab0a Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:16:38 2023 -0500 Update .env.example commit 22154f4a09c5fcdfee95d43609fb01a5a883b7a9 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:07:48 2023 -0500 Update Registration.spec.tsx commit 5163f7d372a6a03c94f4357b358211a03369456e Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:07:30 2023 -0500 Update Login.spec.tsx commit 61da49e330a9376e130b24dc944854f97ab58d80 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:07:00 2023 -0500 Update Registration.tsx commit 0e45d3f0dbde34388ff2f0b2dc51b983b472eb05 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:06:18 2023 -0500 Update Login.tsx commit dca1e5367e5f3b468c7964218cc5914ca53095af Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:05:07 2023 -0500 Update envConstants.js commit f48c058465d82b03716ba85224e9f97007e014d2 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Tue Jun 13 00:04:05 2023 -0500 Update .env.example commit 818226c9cb079acae4fcbfe5997e4aa9e3c6d2cc Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:59:08 2023 -0500 Update .env.example commit 9a805439189b352a38ac7654d7a31bb28f0f58dd Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:58:31 2023 -0500 Update env.d.ts commit 3f37ce54758b017c9281b7fad9b040a47630ec66 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:57:04 2023 -0500 Update .env.example commit 1026036f4dd529e9531c53084450ce768cfca4c1 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:50:36 2023 -0500 Update docker-compose.yml commit a61cf7b8c51d4a9bd73a20bd67abc29891c11463 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:50:00 2023 -0500 Update Dockerfile commit 79610d6648755cd5ec45215b9fdbe04ba8242fcf Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:35:34 2023 -0500 Update package-lock.json commit e40853fd2b77f2db5be1c3dfd8b170d650e23271 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:30:17 2023 -0500 Update envConstants.js commit 5529bc61b43f279fb4418c3851be2f9011b6454d Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:25:58 2023 -0500 Update docker-compose.yml commit 07848cc464a64f7cad484e24a1310dc61aa03b18 Merge: ec628a3 72e9828 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:24:03 2023 -0500 Merge branch 'danny-avila:main' into openid-client commit ec628a3044ba963b4e733c72229400074e7c2bc4 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:23:16 2023 -0500 Update envConstants.js commit 21272221db0f58c244f08335482d45b177d338ab Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:21:59 2023 -0500 Update Registration.spec.tsx commit d3f2949c0484d5760e7b689501852f86209992a3 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:21:12 2023 -0500 Update Login.spec.tsx commit f2cf23ddd6708a3bb8d032dde5f1ce300dbe8cad Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:20:15 2023 -0500 Update Registration.tsx commit 482c346b2a7baf958665c9474223d2557504dee5 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:17:53 2023 -0500 Update Login.tsx commit 2f017aa5bf4ef91b73fe027fb346132e1a5d8b87 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:14:17 2023 -0500 Update env.d.ts commit addfd95cf93ef19cae05bab652d634af64313e6a Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:13:16 2023 -0500 Create openidStrategy.js commit 84c3b5c2f078494d8380f3a02e3ba2d935d8d79f Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:09:02 2023 -0500 Update oauth.js commit 63225cdf33b7f42005b4a446797acbd91b7ee4a7 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:07:35 2023 -0500 Update index.js commit 6efe4dafd4359ed1c3139468bf9d43f70bbaf6aa Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:04:55 2023 -0500 Update package.json commit 201badbbb5a5c8d48f5c4cba3a1349d4cfc7a070 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:03:37 2023 -0500 Update User.js commit 7d13d5c303465be9b1268e5f6d9bdf7bb8dfb2e4 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:02:29 2023 -0500 Update Dockerfile commit 2ef7f84ea77f281c3dce61211d9fd841a6424e65 Author: bsu3338 <bsu3338@users.noreply.github.com> Date: Mon Jun 12 23:00:42 2023 -0500 Update .env.example * Update openidStrategy.js * Update .env.example * Update .env.example * Update docker-compose.yml * Update env.d.ts * Update .env.example * Update .env.example * Update config.js * Update Login.tsx * Update config.js * Update Login.tsx * Update Registration.tsx * Update docker-compose.yml * Update openidStrategy.js * Update docker-compose.yml * Update config.spec.js * Update Login.spec.tsx * Update Registration.spec.tsx * Update types.ts * Update .env.example * Update package-lock.json * Update openidStrategy.js * Update openidStrategy.js * Update config.js * Update config.js * Update Login.tsx * Update Registration.tsx * Update oauth.js * Update openidStrategy.js * Update openidStrategy.js * Update Registration.tsx * Update Login.tsx * Update Login.tsx * Update Registration.tsx * Update Registration.tsx * Update index.js * Update index.js * Update .env.example * Update user_auth_system.md updated instruction that includes OpenID set up * Update package.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update openidStrategy.js * Update openidStrategy.js Lookup user based on openID instead of email. This is because not all AzureAD users may have an email tied to their account * Update openidStrategy.js First try to match an email, then try openIdID * Update openidStrategy.js * Update openidStrategy.js Consider a family name or given name is not provided --------- Co-authored-by: Fuegovic <32828263+fuegovic@users.noreply.github.com>
2023-06-24 21:45:52 -05:00
});