@payloadcms/figma 0.0.1-alpha.1 → 0.0.1-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/control-plane.d.ts.map +1 -1
- package/dist/api/control-plane.js +2 -7
- package/dist/api/control-plane.js.map +1 -1
- package/dist/api/figma-api.js +3 -3
- package/dist/api/figma-api.js.map +1 -1
- package/dist/auth/jwt-validator.js.map +1 -1
- package/dist/auth/oauth-flow.d.ts.map +1 -1
- package/dist/auth/oauth-flow.js +3 -6
- package/dist/auth/oauth-flow.js.map +1 -1
- package/dist/auth/project-token.d.ts.map +1 -1
- package/dist/auth/project-token.js +1 -4
- package/dist/auth/project-token.js.map +1 -1
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +19 -28
- package/dist/auth/refresh.js.map +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/cli.js +1 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +17 -10
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +21 -85
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list-tokens.d.ts +1 -1
- package/dist/commands/list-tokens.d.ts.map +1 -1
- package/dist/commands/list-tokens.js +6 -5
- package/dist/commands/list-tokens.js.map +1 -1
- package/dist/commands/login.d.ts +2 -11
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +4 -7
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts +1 -1
- package/dist/commands/logout.js +1 -1
- package/dist/commands/logout.js.map +1 -1
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.d.ts +9 -0
- package/dist/oauth/components/LoginButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LoginButton/index.js +52 -0
- package/dist/oauth/components/LoginButton/index.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.scss +10 -0
- package/dist/oauth/components/LogoutButton/index.d.ts +7 -0
- package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LogoutButton/index.js +67 -0
- package/dist/oauth/components/LogoutButton/index.js.map +1 -0
- package/dist/oauth/components/LogoutButton/index.scss +10 -0
- package/dist/oauth/defaults.d.ts +10 -0
- package/dist/oauth/defaults.d.ts.map +1 -0
- package/dist/oauth/defaults.js +91 -0
- package/dist/oauth/defaults.js.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js +237 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts +12 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js +99 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js +25 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js +21 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +1 -0
- package/dist/oauth/exports/client.d.ts +3 -0
- package/dist/oauth/exports/client.d.ts.map +1 -0
- package/dist/oauth/exports/client.js +4 -0
- package/dist/oauth/exports/client.js.map +1 -0
- package/dist/oauth/hooks/afterLogout.d.ts +8 -0
- package/dist/oauth/hooks/afterLogout.d.ts.map +1 -0
- package/dist/oauth/hooks/afterLogout.js +27 -0
- package/dist/oauth/hooks/afterLogout.js.map +1 -0
- package/dist/oauth/hooks/me.d.ts +5 -0
- package/dist/oauth/hooks/me.d.ts.map +1 -0
- package/dist/oauth/hooks/me.js +55 -0
- package/dist/oauth/hooks/me.js.map +1 -0
- package/dist/oauth/hooks/refresh.d.ts +8 -0
- package/dist/oauth/hooks/refresh.d.ts.map +1 -0
- package/dist/oauth/hooks/refresh.js +91 -0
- package/dist/oauth/hooks/refresh.js.map +1 -0
- package/dist/oauth/index.d.ts +4 -0
- package/dist/oauth/index.d.ts.map +1 -0
- package/dist/oauth/index.js +222 -0
- package/dist/oauth/index.js.map +1 -0
- package/dist/oauth/strategy/index.d.ts +54 -0
- package/dist/oauth/strategy/index.d.ts.map +1 -0
- package/dist/oauth/strategy/index.js +280 -0
- package/dist/oauth/strategy/index.js.map +1 -0
- package/dist/oauth/types.d.ts +192 -0
- package/dist/oauth/types.d.ts.map +1 -0
- package/dist/oauth/types.js +3 -0
- package/dist/oauth/types.js.map +1 -0
- package/dist/oauth/utilities/clearCookie.d.ts +9 -0
- package/dist/oauth/utilities/clearCookie.d.ts.map +1 -0
- package/dist/oauth/utilities/clearCookie.js +21 -0
- package/dist/oauth/utilities/clearCookie.js.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts +10 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.js +42 -0
- package/dist/oauth/utilities/createCookieOptions.js.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts +4 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.js +16 -0
- package/dist/oauth/utilities/createDebugLogger.js.map +1 -0
- package/dist/oauth/utilities/extractOrigin.d.ts +2 -0
- package/dist/oauth/utilities/extractOrigin.d.ts.map +1 -0
- package/dist/oauth/utilities/extractOrigin.js +12 -0
- package/dist/oauth/utilities/extractOrigin.js.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +3 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js +18 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js.map +1 -0
- package/dist/oauth/utilities/getAdminPath.d.ts +8 -0
- package/dist/oauth/utilities/getAdminPath.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminPath.js +9 -0
- package/dist/oauth/utilities/getAdminPath.js.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +17 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +45 -0
- package/dist/oauth/utilities/getAuthorizeURL.js.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts +4 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.js +11 -0
- package/dist/oauth/utilities/getCookieExpiration.js.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts +2 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js +7 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getTokenExp.d.ts +6 -0
- package/dist/oauth/utilities/getTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getTokenExp.js +20 -0
- package/dist/oauth/utilities/getTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getUsernameField.d.ts +9 -0
- package/dist/oauth/utilities/getUsernameField.d.ts.map +1 -0
- package/dist/oauth/utilities/getUsernameField.js +20 -0
- package/dist/oauth/utilities/getUsernameField.js.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts +8 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js +25 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts +2 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.js +37 -0
- package/dist/oauth/utilities/mergeHeaders.js.map +1 -0
- package/dist/oauth/utilities/refreshTokens.d.ts +16 -0
- package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -0
- package/dist/oauth/utilities/refreshTokens.js +67 -0
- package/dist/oauth/utilities/refreshTokens.js.map +1 -0
- package/dist/plugin/build-config.d.ts +7 -1
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +29 -2
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/types/config.d.ts +0 -11
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +1 -1
- package/dist/types/config.js.map +1 -1
- package/dist/utils/config.d.ts +0 -22
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +0 -46
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/messages.js +11 -11
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/payload-config-ast.d.ts +17 -1
- package/dist/utils/payload-config-ast.d.ts.map +1 -1
- package/dist/utils/payload-config-ast.js +166 -14
- package/dist/utils/payload-config-ast.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts +2 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +50 -79
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/dist/utils/payload-package-check.d.ts.map +1 -1
- package/dist/utils/payload-package-check.js +14 -33
- package/dist/utils/payload-package-check.js.map +1 -1
- package/dist/utils/project.d.ts +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +3 -5
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/s3-upload.d.ts.map +1 -1
- package/dist/utils/s3-upload.js +3 -8
- package/dist/utils/s3-upload.js.map +1 -1
- package/dist/utils/token-display.d.ts.map +1 -1
- package/dist/utils/token-display.js +3 -2
- package/dist/utils/token-display.js.map +1 -1
- package/package.json +9 -3
- package/dist/api/control-plane.spec.d.ts +0 -2
- package/dist/api/control-plane.spec.d.ts.map +0 -1
- package/dist/api/control-plane.spec.js +0 -296
- package/dist/api/control-plane.spec.js.map +0 -1
- package/dist/api/figma-api.spec.d.ts +0 -14
- package/dist/api/figma-api.spec.d.ts.map +0 -1
- package/dist/api/figma-api.spec.js +0 -201
- package/dist/api/figma-api.spec.js.map +0 -1
- package/dist/auth/__tests__/fixtures.d.ts +0 -26
- package/dist/auth/__tests__/fixtures.d.ts.map +0 -1
- package/dist/auth/__tests__/fixtures.js +0 -67
- package/dist/auth/__tests__/fixtures.js.map +0 -1
- package/dist/auth/__tests__/mocks.d.ts +0 -33
- package/dist/auth/__tests__/mocks.d.ts.map +0 -1
- package/dist/auth/__tests__/mocks.js +0 -63
- package/dist/auth/__tests__/mocks.js.map +0 -1
- package/dist/auth/callback-server.spec.d.ts +0 -2
- package/dist/auth/callback-server.spec.d.ts.map +0 -1
- package/dist/auth/callback-server.spec.js +0 -85
- package/dist/auth/callback-server.spec.js.map +0 -1
- package/dist/auth/crypto-utils.spec.d.ts +0 -2
- package/dist/auth/crypto-utils.spec.d.ts.map +0 -1
- package/dist/auth/crypto-utils.spec.js +0 -36
- package/dist/auth/crypto-utils.spec.js.map +0 -1
- package/dist/auth/jwt-validator.spec.d.ts +0 -10
- package/dist/auth/jwt-validator.spec.d.ts.map +0 -1
- package/dist/auth/jwt-validator.spec.js +0 -236
- package/dist/auth/jwt-validator.spec.js.map +0 -1
- package/dist/auth/oauth-flow.spec.d.ts +0 -2
- package/dist/auth/oauth-flow.spec.d.ts.map +0 -1
- package/dist/auth/oauth-flow.spec.js +0 -134
- package/dist/auth/oauth-flow.spec.js.map +0 -1
- package/dist/auth/pkce.spec.d.ts +0 -2
- package/dist/auth/pkce.spec.d.ts.map +0 -1
- package/dist/auth/pkce.spec.js +0 -32
- package/dist/auth/pkce.spec.js.map +0 -1
- package/dist/auth/project-token.spec.d.ts +0 -2
- package/dist/auth/project-token.spec.d.ts.map +0 -1
- package/dist/auth/project-token.spec.js +0 -332
- package/dist/auth/project-token.spec.js.map +0 -1
- package/dist/auth/refresh.spec.d.ts +0 -2
- package/dist/auth/refresh.spec.d.ts.map +0 -1
- package/dist/auth/refresh.spec.js +0 -105
- package/dist/auth/refresh.spec.js.map +0 -1
- package/dist/auth/token-store.spec.d.ts +0 -2
- package/dist/auth/token-store.spec.d.ts.map +0 -1
- package/dist/auth/token-store.spec.js +0 -276
- package/dist/auth/token-store.spec.js.map +0 -1
- package/dist/commands/__tests__/test-utils.d.ts +0 -28
- package/dist/commands/__tests__/test-utils.d.ts.map +0 -1
- package/dist/commands/__tests__/test-utils.js +0 -34
- package/dist/commands/__tests__/test-utils.js.map +0 -1
- package/dist/commands/deploy.spec.d.ts +0 -2
- package/dist/commands/deploy.spec.d.ts.map +0 -1
- package/dist/commands/deploy.spec.js +0 -18
- package/dist/commands/deploy.spec.js.map +0 -1
- package/dist/commands/init.spec.d.ts +0 -2
- package/dist/commands/init.spec.d.ts.map +0 -1
- package/dist/commands/init.spec.js +0 -283
- package/dist/commands/init.spec.js.map +0 -1
- package/dist/plugin/build-config.spec.d.ts +0 -2
- package/dist/plugin/build-config.spec.d.ts.map +0 -1
- package/dist/plugin/build-config.spec.js +0 -72
- package/dist/plugin/build-config.spec.js.map +0 -1
- package/dist/utils/asset-collection.spec.d.ts +0 -2
- package/dist/utils/asset-collection.spec.d.ts.map +0 -1
- package/dist/utils/asset-collection.spec.js +0 -155
- package/dist/utils/asset-collection.spec.js.map +0 -1
- package/dist/utils/build-detection.spec.d.ts +0 -2
- package/dist/utils/build-detection.spec.d.ts.map +0 -1
- package/dist/utils/build-detection.spec.js +0 -110
- package/dist/utils/build-detection.spec.js.map +0 -1
- package/dist/utils/config.spec.d.ts +0 -2
- package/dist/utils/config.spec.d.ts.map +0 -1
- package/dist/utils/config.spec.js +0 -167
- package/dist/utils/config.spec.js.map +0 -1
- package/dist/utils/download-template.spec.d.ts +0 -2
- package/dist/utils/download-template.spec.d.ts.map +0 -1
- package/dist/utils/download-template.spec.js +0 -76
- package/dist/utils/download-template.spec.js.map +0 -1
- package/dist/utils/env-management.spec.d.ts +0 -2
- package/dist/utils/env-management.spec.d.ts.map +0 -1
- package/dist/utils/env-management.spec.js +0 -123
- package/dist/utils/env-management.spec.js.map +0 -1
- package/dist/utils/git.spec.d.ts +0 -2
- package/dist/utils/git.spec.d.ts.map +0 -1
- package/dist/utils/git.spec.js +0 -99
- package/dist/utils/git.spec.js.map +0 -1
- package/dist/utils/lambda-config.spec.d.ts +0 -2
- package/dist/utils/lambda-config.spec.d.ts.map +0 -1
- package/dist/utils/lambda-config.spec.js +0 -141
- package/dist/utils/lambda-config.spec.js.map +0 -1
- package/dist/utils/payload-config-ast.spec.d.ts +0 -2
- package/dist/utils/payload-config-ast.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-ast.spec.js +0 -303
- package/dist/utils/payload-config-ast.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.int.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.js +0 -116
- package/dist/utils/payload-config-modifier.int.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.spec.js +0 -162
- package/dist/utils/payload-config-modifier.spec.js.map +0 -1
- package/dist/utils/payload-package-check.spec.d.ts +0 -2
- package/dist/utils/payload-package-check.spec.d.ts.map +0 -1
- package/dist/utils/payload-package-check.spec.js +0 -148
- package/dist/utils/payload-package-check.spec.js.map +0 -1
- package/dist/utils/project.spec.d.ts +0 -2
- package/dist/utils/project.spec.d.ts.map +0 -1
- package/dist/utils/project.spec.js +0 -222
- package/dist/utils/project.spec.js.map +0 -1
- package/dist/utils/s3-upload.spec.d.ts +0 -2
- package/dist/utils/s3-upload.spec.d.ts.map +0 -1
- package/dist/utils/s3-upload.spec.js +0 -140
- package/dist/utils/s3-upload.spec.js.map +0 -1
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for JWT validator
|
|
3
|
-
*
|
|
4
|
-
* Tests our wrapper logic around jose's JWT validation:
|
|
5
|
-
* - Cache management (clearJWKSCache)
|
|
6
|
-
* - Environment-based JWKS URI routing
|
|
7
|
-
* - Error mapping from jose errors to our custom error codes
|
|
8
|
-
*/ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
9
|
-
import { clearJWKSCache, JWTValidationError, validateProjectToken } from './jwt-validator.js';
|
|
10
|
-
// Helper to create a simple test JWT (will fail validation but tests the flow)
|
|
11
|
-
function createTestJWT(payload, kid = 'test-key-id') {
|
|
12
|
-
const header = Buffer.from(JSON.stringify({
|
|
13
|
-
alg: 'RS256',
|
|
14
|
-
kid,
|
|
15
|
-
typ: 'JWT'
|
|
16
|
-
})).toString('base64url');
|
|
17
|
-
const payloadStr = Buffer.from(JSON.stringify(payload)).toString('base64url');
|
|
18
|
-
const signature = 'fake_signature';
|
|
19
|
-
return `${header}.${payloadStr}.${signature}`;
|
|
20
|
-
}
|
|
21
|
-
describe('JWT Validator', ()=>{
|
|
22
|
-
// Mock JWKS with RSA key
|
|
23
|
-
const mockJWKS = {
|
|
24
|
-
keys: [
|
|
25
|
-
{
|
|
26
|
-
alg: 'RS256',
|
|
27
|
-
e: 'AQAB',
|
|
28
|
-
kid: 'test-key-id',
|
|
29
|
-
kty: 'RSA',
|
|
30
|
-
n: 'xGOr-H7A-PWO8VcD4sqDpCciAuqYDPq8zKWb4Vh6YhP8Ny3KcJaJhLMDEBJB3fKVvT-pPlkHPFBv7L7iHzRrJMXz8uDJVK-FTYmTQhcvKPyMWUDGDPNlVXEGkBLdj3DZqKjJ8iVChSh5DzKJvzr-RyGnH8Z7nLqBa91zxWfm7ztJxqP0qPRKz6vb4h8QyN-5X4Gh8gU7ZcLLnqLqJ6FhPvqKVcBhfN3KjM6h8hLXz6pPzKqJ8z6r8-9KcZXlWvR',
|
|
31
|
-
use: 'sig'
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
};
|
|
35
|
-
beforeEach(()=>{
|
|
36
|
-
clearJWKSCache();
|
|
37
|
-
vi.restoreAllMocks();
|
|
38
|
-
});
|
|
39
|
-
afterEach(()=>{
|
|
40
|
-
clearJWKSCache();
|
|
41
|
-
});
|
|
42
|
-
describe('Cache Management', ()=>{
|
|
43
|
-
it('should clear resolver cache when clearJWKSCache is called', async ()=>{
|
|
44
|
-
const fetchMock = vi.fn().mockResolvedValue({
|
|
45
|
-
json: ()=>Promise.resolve(mockJWKS),
|
|
46
|
-
ok: true,
|
|
47
|
-
status: 200
|
|
48
|
-
});
|
|
49
|
-
global.fetch = fetchMock;
|
|
50
|
-
const token = createTestJWT({
|
|
51
|
-
exp: Math.floor(Date.now() / 1000) + 3600
|
|
52
|
-
});
|
|
53
|
-
// First validation - creates and caches resolver
|
|
54
|
-
try {
|
|
55
|
-
await validateProjectToken(token, 'staging');
|
|
56
|
-
} catch (_error) {
|
|
57
|
-
// Expected to fail on signature
|
|
58
|
-
}
|
|
59
|
-
const firstCallCount = fetchMock.mock.calls.length;
|
|
60
|
-
expect(firstCallCount).toBeGreaterThanOrEqual(1);
|
|
61
|
-
// Clear the cache - this is OUR logic
|
|
62
|
-
clearJWKSCache();
|
|
63
|
-
// Second validation after clearing cache - should create new resolver
|
|
64
|
-
try {
|
|
65
|
-
await validateProjectToken(token, 'staging');
|
|
66
|
-
} catch (_error) {
|
|
67
|
-
// Expected to fail on signature
|
|
68
|
-
}
|
|
69
|
-
// Verify fetch was called again after cache clear
|
|
70
|
-
expect(fetchMock.mock.calls.length).toBeGreaterThan(firstCallCount);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe('Error Code Mapping', ()=>{
|
|
74
|
-
it('should map network errors to JWKS_FETCH_FAILED code', async ()=>{
|
|
75
|
-
global.fetch = vi.fn().mockRejectedValue(new Error('ENOTFOUND'));
|
|
76
|
-
const token = createTestJWT({
|
|
77
|
-
exp: Math.floor(Date.now() / 1000) + 3600
|
|
78
|
-
});
|
|
79
|
-
try {
|
|
80
|
-
await validateProjectToken(token, 'staging');
|
|
81
|
-
expect.fail('Should have thrown an error');
|
|
82
|
-
} catch (error) {
|
|
83
|
-
expect(error).toBeInstanceOf(JWTValidationError);
|
|
84
|
-
if (error instanceof JWTValidationError) {
|
|
85
|
-
// Verify our error mapping logic
|
|
86
|
-
expect(error.code).toBe('JWKS_FETCH_FAILED');
|
|
87
|
-
expect(error.message).toContain('Failed to fetch JWKS');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
it('should map jose signature errors to SIGNATURE_INVALID code', async ()=>{
|
|
92
|
-
global.fetch = vi.fn().mockResolvedValue({
|
|
93
|
-
json: ()=>Promise.resolve(mockJWKS),
|
|
94
|
-
ok: true,
|
|
95
|
-
status: 200
|
|
96
|
-
});
|
|
97
|
-
const badToken = 'eyJhbGciOiJSUzI1NiIsImtpZCI6InRlc3Qta2V5LWlkIn0.e30.bad_signature';
|
|
98
|
-
try {
|
|
99
|
-
await validateProjectToken(badToken, 'staging');
|
|
100
|
-
expect.fail('Should have thrown an error');
|
|
101
|
-
} catch (error) {
|
|
102
|
-
expect(error).toBeInstanceOf(JWTValidationError);
|
|
103
|
-
if (error instanceof JWTValidationError) {
|
|
104
|
-
// Verify our error mapping logic - invalid tokens may fail at different stages
|
|
105
|
-
// The important thing is that signature-related errors map to either SIGNATURE_INVALID or MISSING_KID
|
|
106
|
-
expect([
|
|
107
|
-
'SIGNATURE_INVALID',
|
|
108
|
-
'MISSING_KID'
|
|
109
|
-
]).toContain(error.code);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
it('should map expired token errors to EXPIRED code', async ()=>{
|
|
114
|
-
global.fetch = vi.fn().mockResolvedValue({
|
|
115
|
-
json: ()=>Promise.resolve(mockJWKS),
|
|
116
|
-
ok: true,
|
|
117
|
-
status: 200
|
|
118
|
-
});
|
|
119
|
-
// Create token that expired 1 hour ago
|
|
120
|
-
const expiredToken = createTestJWT({
|
|
121
|
-
exp: Math.floor(Date.now() / 1000) - 3600,
|
|
122
|
-
iat: Math.floor(Date.now() / 1000) - 7200
|
|
123
|
-
});
|
|
124
|
-
try {
|
|
125
|
-
await validateProjectToken(expiredToken, 'staging');
|
|
126
|
-
expect.fail('Should have thrown an error');
|
|
127
|
-
} catch (error) {
|
|
128
|
-
expect(error).toBeInstanceOf(JWTValidationError);
|
|
129
|
-
if (error instanceof JWTValidationError) {
|
|
130
|
-
// Verify our error mapping logic
|
|
131
|
-
// Note: Mock tokens with bad signatures may fail signature validation before expiry check
|
|
132
|
-
// In real scenarios with valid signatures, EXPIRED would be returned
|
|
133
|
-
expect([
|
|
134
|
-
'EXPIRED',
|
|
135
|
-
'SIGNATURE_INVALID',
|
|
136
|
-
'MISSING_KID'
|
|
137
|
-
]).toContain(error.code);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
it('should map missing kid errors to MISSING_KID code', async ()=>{
|
|
142
|
-
global.fetch = vi.fn().mockResolvedValue({
|
|
143
|
-
json: ()=>Promise.resolve(mockJWKS),
|
|
144
|
-
ok: true,
|
|
145
|
-
status: 200
|
|
146
|
-
});
|
|
147
|
-
// Create token without kid in header
|
|
148
|
-
const header = Buffer.from(JSON.stringify({
|
|
149
|
-
alg: 'RS256',
|
|
150
|
-
typ: 'JWT'
|
|
151
|
-
})).toString('base64url');
|
|
152
|
-
const payload = Buffer.from(JSON.stringify({
|
|
153
|
-
exp: Math.floor(Date.now() / 1000) + 3600
|
|
154
|
-
})).toString('base64url');
|
|
155
|
-
const tokenWithoutKid = `${header}.${payload}.fake_signature`;
|
|
156
|
-
try {
|
|
157
|
-
await validateProjectToken(tokenWithoutKid, 'staging');
|
|
158
|
-
expect.fail('Should have thrown an error');
|
|
159
|
-
} catch (error) {
|
|
160
|
-
expect(error).toBeInstanceOf(JWTValidationError);
|
|
161
|
-
if (error instanceof JWTValidationError) {
|
|
162
|
-
// Verify our error mapping logic - tokens without kid may fail at various stages
|
|
163
|
-
expect([
|
|
164
|
-
'MISSING_KID',
|
|
165
|
-
'SIGNATURE_INVALID'
|
|
166
|
-
]).toContain(error.code);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
it('should map no matching key errors to SIGNATURE_INVALID code', async ()=>{
|
|
171
|
-
global.fetch = vi.fn().mockResolvedValue({
|
|
172
|
-
json: ()=>Promise.resolve(mockJWKS),
|
|
173
|
-
ok: true,
|
|
174
|
-
status: 200
|
|
175
|
-
});
|
|
176
|
-
// Create token with a kid that doesn't exist in JWKS
|
|
177
|
-
const tokenWithWrongKid = createTestJWT({
|
|
178
|
-
exp: Math.floor(Date.now() / 1000) + 3600
|
|
179
|
-
}, 'non-existent-key-id');
|
|
180
|
-
try {
|
|
181
|
-
await validateProjectToken(tokenWithWrongKid, 'staging');
|
|
182
|
-
expect.fail('Should have thrown an error');
|
|
183
|
-
} catch (error) {
|
|
184
|
-
expect(error).toBeInstanceOf(JWTValidationError);
|
|
185
|
-
if (error instanceof JWTValidationError) {
|
|
186
|
-
// Verify our error mapping logic
|
|
187
|
-
expect(error.code).toBe('SIGNATURE_INVALID');
|
|
188
|
-
expect(error.message).toContain('Key not found in JWKS');
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
it('should handle multiple network error formats', async ()=>{
|
|
193
|
-
const networkErrors = [
|
|
194
|
-
new Error('fetch failed'),
|
|
195
|
-
new Error('network error'),
|
|
196
|
-
new Error('ECONNREFUSED')
|
|
197
|
-
];
|
|
198
|
-
for (const networkError of networkErrors){
|
|
199
|
-
clearJWKSCache();
|
|
200
|
-
global.fetch = vi.fn().mockRejectedValue(networkError);
|
|
201
|
-
const token = createTestJWT({
|
|
202
|
-
exp: Math.floor(Date.now() / 1000) + 3600
|
|
203
|
-
});
|
|
204
|
-
try {
|
|
205
|
-
await validateProjectToken(token, 'staging');
|
|
206
|
-
expect.fail('Should have thrown an error');
|
|
207
|
-
} catch (error) {
|
|
208
|
-
expect(error).toBeInstanceOf(JWTValidationError);
|
|
209
|
-
if (error instanceof JWTValidationError) {
|
|
210
|
-
expect(error.code).toBe('JWKS_FETCH_FAILED');
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
it('should handle generic errors with fallback', async ()=>{
|
|
216
|
-
// Mock an unexpected error type
|
|
217
|
-
global.fetch = vi.fn().mockRejectedValue('string error');
|
|
218
|
-
const token = createTestJWT({
|
|
219
|
-
exp: Math.floor(Date.now() / 1000) + 3600
|
|
220
|
-
});
|
|
221
|
-
try {
|
|
222
|
-
await validateProjectToken(token, 'staging');
|
|
223
|
-
expect.fail('Should have thrown an error');
|
|
224
|
-
} catch (error) {
|
|
225
|
-
expect(error).toBeInstanceOf(JWTValidationError);
|
|
226
|
-
if (error instanceof JWTValidationError) {
|
|
227
|
-
// Generic errors fall back to SIGNATURE_INVALID
|
|
228
|
-
expect(error.code).toBe('SIGNATURE_INVALID');
|
|
229
|
-
expect(error.message).toContain('JWT validation failed');
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
//# sourceMappingURL=jwt-validator.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/jwt-validator.spec.ts"],"sourcesContent":["/**\n * Unit tests for JWT validator\n *\n * Tests our wrapper logic around jose's JWT validation:\n * - Cache management (clearJWKSCache)\n * - Environment-based JWKS URI routing\n * - Error mapping from jose errors to our custom error codes\n */\n\nimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'\n\nimport { clearJWKSCache, JWTValidationError, validateProjectToken } from './jwt-validator.js'\n\n// Helper to create a simple test JWT (will fail validation but tests the flow)\nfunction createTestJWT(payload: Record<string, unknown>, kid = 'test-key-id'): string {\n const header = Buffer.from(JSON.stringify({ alg: 'RS256', kid, typ: 'JWT' })).toString(\n 'base64url',\n )\n const payloadStr = Buffer.from(JSON.stringify(payload)).toString('base64url')\n const signature = 'fake_signature'\n return `${header}.${payloadStr}.${signature}`\n}\n\ndescribe('JWT Validator', () => {\n // Mock JWKS with RSA key\n const mockJWKS = {\n keys: [\n {\n alg: 'RS256',\n e: 'AQAB',\n kid: 'test-key-id',\n kty: 'RSA',\n n: 'xGOr-H7A-PWO8VcD4sqDpCciAuqYDPq8zKWb4Vh6YhP8Ny3KcJaJhLMDEBJB3fKVvT-pPlkHPFBv7L7iHzRrJMXz8uDJVK-FTYmTQhcvKPyMWUDGDPNlVXEGkBLdj3DZqKjJ8iVChSh5DzKJvzr-RyGnH8Z7nLqBa91zxWfm7ztJxqP0qPRKz6vb4h8QyN-5X4Gh8gU7ZcLLnqLqJ6FhPvqKVcBhfN3KjM6h8hLXz6pPzKqJ8z6r8-9KcZXlWvR',\n use: 'sig',\n },\n ],\n }\n\n beforeEach(() => {\n clearJWKSCache()\n vi.restoreAllMocks()\n })\n\n afterEach(() => {\n clearJWKSCache()\n })\n\n describe('Cache Management', () => {\n it('should clear resolver cache when clearJWKSCache is called', async () => {\n const fetchMock = vi.fn().mockResolvedValue({\n json: () => Promise.resolve(mockJWKS),\n ok: true,\n status: 200,\n })\n global.fetch = fetchMock\n\n const token = createTestJWT({ exp: Math.floor(Date.now() / 1000) + 3600 })\n\n // First validation - creates and caches resolver\n try {\n await validateProjectToken(token, 'staging')\n } catch (_error) {\n // Expected to fail on signature\n }\n\n const firstCallCount = fetchMock.mock.calls.length\n expect(firstCallCount).toBeGreaterThanOrEqual(1)\n\n // Clear the cache - this is OUR logic\n clearJWKSCache()\n\n // Second validation after clearing cache - should create new resolver\n try {\n await validateProjectToken(token, 'staging')\n } catch (_error) {\n // Expected to fail on signature\n }\n\n // Verify fetch was called again after cache clear\n expect(fetchMock.mock.calls.length).toBeGreaterThan(firstCallCount)\n })\n })\n\n describe('Error Code Mapping', () => {\n it('should map network errors to JWKS_FETCH_FAILED code', async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error('ENOTFOUND'))\n\n const token = createTestJWT({ exp: Math.floor(Date.now() / 1000) + 3600 })\n\n try {\n await validateProjectToken(token, 'staging')\n expect.fail('Should have thrown an error')\n } catch (error) {\n expect(error).toBeInstanceOf(JWTValidationError)\n if (error instanceof JWTValidationError) {\n // Verify our error mapping logic\n expect(error.code).toBe('JWKS_FETCH_FAILED')\n expect(error.message).toContain('Failed to fetch JWKS')\n }\n }\n })\n\n it('should map jose signature errors to SIGNATURE_INVALID code', async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: () => Promise.resolve(mockJWKS),\n ok: true,\n status: 200,\n })\n\n const badToken = 'eyJhbGciOiJSUzI1NiIsImtpZCI6InRlc3Qta2V5LWlkIn0.e30.bad_signature'\n\n try {\n await validateProjectToken(badToken, 'staging')\n expect.fail('Should have thrown an error')\n } catch (error) {\n expect(error).toBeInstanceOf(JWTValidationError)\n if (error instanceof JWTValidationError) {\n // Verify our error mapping logic - invalid tokens may fail at different stages\n // The important thing is that signature-related errors map to either SIGNATURE_INVALID or MISSING_KID\n expect(['SIGNATURE_INVALID', 'MISSING_KID']).toContain(error.code)\n }\n }\n })\n\n it('should map expired token errors to EXPIRED code', async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: () => Promise.resolve(mockJWKS),\n ok: true,\n status: 200,\n })\n\n // Create token that expired 1 hour ago\n const expiredToken = createTestJWT({\n exp: Math.floor(Date.now() / 1000) - 3600,\n iat: Math.floor(Date.now() / 1000) - 7200,\n })\n\n try {\n await validateProjectToken(expiredToken, 'staging')\n expect.fail('Should have thrown an error')\n } catch (error) {\n expect(error).toBeInstanceOf(JWTValidationError)\n if (error instanceof JWTValidationError) {\n // Verify our error mapping logic\n // Note: Mock tokens with bad signatures may fail signature validation before expiry check\n // In real scenarios with valid signatures, EXPIRED would be returned\n expect(['EXPIRED', 'SIGNATURE_INVALID', 'MISSING_KID']).toContain(error.code)\n }\n }\n })\n\n it('should map missing kid errors to MISSING_KID code', async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: () => Promise.resolve(mockJWKS),\n ok: true,\n status: 200,\n })\n\n // Create token without kid in header\n const header = Buffer.from(JSON.stringify({ alg: 'RS256', typ: 'JWT' })).toString('base64url')\n const payload = Buffer.from(\n JSON.stringify({ exp: Math.floor(Date.now() / 1000) + 3600 }),\n ).toString('base64url')\n const tokenWithoutKid = `${header}.${payload}.fake_signature`\n\n try {\n await validateProjectToken(tokenWithoutKid, 'staging')\n expect.fail('Should have thrown an error')\n } catch (error) {\n expect(error).toBeInstanceOf(JWTValidationError)\n if (error instanceof JWTValidationError) {\n // Verify our error mapping logic - tokens without kid may fail at various stages\n expect(['MISSING_KID', 'SIGNATURE_INVALID']).toContain(error.code)\n }\n }\n })\n\n it('should map no matching key errors to SIGNATURE_INVALID code', async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: () => Promise.resolve(mockJWKS),\n ok: true,\n status: 200,\n })\n\n // Create token with a kid that doesn't exist in JWKS\n const tokenWithWrongKid = createTestJWT(\n { exp: Math.floor(Date.now() / 1000) + 3600 },\n 'non-existent-key-id',\n )\n\n try {\n await validateProjectToken(tokenWithWrongKid, 'staging')\n expect.fail('Should have thrown an error')\n } catch (error) {\n expect(error).toBeInstanceOf(JWTValidationError)\n if (error instanceof JWTValidationError) {\n // Verify our error mapping logic\n expect(error.code).toBe('SIGNATURE_INVALID')\n expect(error.message).toContain('Key not found in JWKS')\n }\n }\n })\n\n it('should handle multiple network error formats', async () => {\n const networkErrors = [\n new Error('fetch failed'),\n new Error('network error'),\n new Error('ECONNREFUSED'),\n ]\n\n for (const networkError of networkErrors) {\n clearJWKSCache()\n global.fetch = vi.fn().mockRejectedValue(networkError)\n\n const token = createTestJWT({ exp: Math.floor(Date.now() / 1000) + 3600 })\n\n try {\n await validateProjectToken(token, 'staging')\n expect.fail('Should have thrown an error')\n } catch (error) {\n expect(error).toBeInstanceOf(JWTValidationError)\n if (error instanceof JWTValidationError) {\n expect(error.code).toBe('JWKS_FETCH_FAILED')\n }\n }\n }\n })\n\n it('should handle generic errors with fallback', async () => {\n // Mock an unexpected error type\n global.fetch = vi.fn().mockRejectedValue('string error')\n\n const token = createTestJWT({ exp: Math.floor(Date.now() / 1000) + 3600 })\n\n try {\n await validateProjectToken(token, 'staging')\n expect.fail('Should have thrown an error')\n } catch (error) {\n expect(error).toBeInstanceOf(JWTValidationError)\n if (error instanceof JWTValidationError) {\n // Generic errors fall back to SIGNATURE_INVALID\n expect(error.code).toBe('SIGNATURE_INVALID')\n expect(error.message).toContain('JWT validation failed')\n }\n }\n })\n })\n})\n"],"names":["afterEach","beforeEach","describe","expect","it","vi","clearJWKSCache","JWTValidationError","validateProjectToken","createTestJWT","payload","kid","header","Buffer","from","JSON","stringify","alg","typ","toString","payloadStr","signature","mockJWKS","keys","e","kty","n","use","restoreAllMocks","fetchMock","fn","mockResolvedValue","json","Promise","resolve","ok","status","global","fetch","token","exp","Math","floor","Date","now","_error","firstCallCount","mock","calls","length","toBeGreaterThanOrEqual","toBeGreaterThan","mockRejectedValue","Error","fail","error","toBeInstanceOf","code","toBe","message","toContain","badToken","expiredToken","iat","tokenWithoutKid","tokenWithWrongKid","networkErrors","networkError"],"mappings":"AAAA;;;;;;;CAOC,GAED,SAASA,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAExE,SAASC,cAAc,EAA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J,OAAOoD,MAAME,IAAI,EAAEC,IAAI,CAAC;oBAC1B;gBACF;YACF;QACF;QAEAtD,GAAG,8CAA8C;YAC/C,gCAAgC;YAChCiC,OAAOC,KAAK,GAAGjC,GAAGyB,EAAE,GAAGsB,iBAAiB,CAAC;YAEzC,MAAMb,QAAQ9B,cAAc;gBAAE+B,KAAKC,KAAKC,KAAK,CAACC,KAAKC,GAAG,KAAK,QAAQ;YAAK;YAExE,IAAI;gBACF,MAAMpC,qBAAqB+B,OAAO;gBAClCpC,OAAOmD,IAAI,CAAC;YACd,EAAE,OAAOC,OAAO;gBACdpD,OAAOoD,OAAOC,cAAc,CAACjD;gBAC7B,IAAIgD,iBAAiBhD,oBAAoB;oBACvC,gDAAgD;oBAChDJ,OAAOoD,MAAME,IAAI,EAAEC,IAAI,CAAC;oBACxBvD,OAAOoD,MAAMI,OAAO,EAAEC,SAAS,CAAC;gBAClC;YACF;QACF;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-flow.spec.d.ts","sourceRoot":"","sources":["../../src/auth/oauth-flow.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { CallbackServer } from './callback-server.js';
|
|
3
|
-
import { executeOAuthFlow, getValidAccessToken, OAuthFlowError } from './oauth-flow.js';
|
|
4
|
-
import { refreshAccessToken } from './refresh.js';
|
|
5
|
-
import { TokenStore } from './token-store.js';
|
|
6
|
-
// Mock the refresh module
|
|
7
|
-
vi.mock('./refresh.js', ()=>({
|
|
8
|
-
exchangeCodeForTokens: vi.fn(),
|
|
9
|
-
refreshAccessToken: vi.fn()
|
|
10
|
-
}));
|
|
11
|
-
// Mock browser and callback server
|
|
12
|
-
vi.mock('./browser.js', ()=>({
|
|
13
|
-
buildAuthorizationUrl: vi.fn(()=>'https://www.figma.com/oauth?...'),
|
|
14
|
-
openBrowser: vi.fn()
|
|
15
|
-
}));
|
|
16
|
-
// Mock @clack/prompts
|
|
17
|
-
vi.mock('@clack/prompts', ()=>({
|
|
18
|
-
confirm: vi.fn().mockResolvedValue(true),
|
|
19
|
-
isCancel: vi.fn().mockReturnValue(false)
|
|
20
|
-
}));
|
|
21
|
-
// Create mock factory for CallbackServer
|
|
22
|
-
const createMockCallbackServer = ()=>{
|
|
23
|
-
const mock = {
|
|
24
|
-
getActualPort: vi.fn().mockReturnValue(3000),
|
|
25
|
-
stop: vi.fn(),
|
|
26
|
-
waitForCallback: vi.fn()
|
|
27
|
-
};
|
|
28
|
-
return mock;
|
|
29
|
-
};
|
|
30
|
-
vi.mock('./callback-server.js', ()=>({
|
|
31
|
-
CallbackServer: vi.fn()
|
|
32
|
-
}));
|
|
33
|
-
describe('oauth-flow', ()=>{
|
|
34
|
-
describe('getValidAccessToken', ()=>{
|
|
35
|
-
let tokenStore;
|
|
36
|
-
beforeEach(()=>{
|
|
37
|
-
tokenStore = new TokenStore({
|
|
38
|
-
configName: 'test-payloadcms-figma-oauth-flow'
|
|
39
|
-
});
|
|
40
|
-
tokenStore.clearTokens();
|
|
41
|
-
});
|
|
42
|
-
it('should return access token if valid tokens exist', async ()=>{
|
|
43
|
-
const mockTokens = {
|
|
44
|
-
accessToken: 'valid-token',
|
|
45
|
-
expiresAt: Date.now() + 3600000,
|
|
46
|
-
refreshToken: 'refresh-token'
|
|
47
|
-
};
|
|
48
|
-
tokenStore.setTokens(mockTokens);
|
|
49
|
-
const token = await getValidAccessToken(tokenStore);
|
|
50
|
-
expect(token).toBe('valid-token');
|
|
51
|
-
});
|
|
52
|
-
it('should refresh expired tokens', async ()=>{
|
|
53
|
-
const expiredTokens = {
|
|
54
|
-
accessToken: 'expired-token',
|
|
55
|
-
expiresAt: Date.now() - 1000,
|
|
56
|
-
refreshToken: 'refresh-token'
|
|
57
|
-
};
|
|
58
|
-
tokenStore.setTokens(expiredTokens);
|
|
59
|
-
const newTokens = {
|
|
60
|
-
accessToken: 'new-token',
|
|
61
|
-
expiresAt: Date.now() + 3600000,
|
|
62
|
-
refreshToken: 'new-refresh-token'
|
|
63
|
-
};
|
|
64
|
-
// Mock the refresh function
|
|
65
|
-
vi.mocked(refreshAccessToken).mockResolvedValueOnce(newTokens);
|
|
66
|
-
const token = await getValidAccessToken(tokenStore);
|
|
67
|
-
expect(token).toBe('new-token');
|
|
68
|
-
// Verify tokens were stored
|
|
69
|
-
const storedTokens = tokenStore.getTokens();
|
|
70
|
-
expect(storedTokens?.accessToken).toBe('new-token');
|
|
71
|
-
});
|
|
72
|
-
it('should clear tokens and throw on refresh failure', async ()=>{
|
|
73
|
-
const expiredTokens = {
|
|
74
|
-
accessToken: 'expired-token',
|
|
75
|
-
expiresAt: Date.now() - 1000,
|
|
76
|
-
refreshToken: 'refresh-token'
|
|
77
|
-
};
|
|
78
|
-
tokenStore.setTokens(expiredTokens);
|
|
79
|
-
// Mock refresh to fail
|
|
80
|
-
vi.mocked(refreshAccessToken).mockRejectedValueOnce(new Error('Refresh failed'));
|
|
81
|
-
await expect(getValidAccessToken(tokenStore)).rejects.toThrow(OAuthFlowError);
|
|
82
|
-
// Verify tokens were cleared
|
|
83
|
-
expect(tokenStore.getTokens()).toBeNull();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
describe('executeOAuthFlow', ()=>{
|
|
87
|
-
let tokenStore;
|
|
88
|
-
let mockServer;
|
|
89
|
-
beforeEach(()=>{
|
|
90
|
-
tokenStore = new TokenStore({
|
|
91
|
-
configName: 'test-payloadcms-figma-oauth-execute'
|
|
92
|
-
});
|
|
93
|
-
tokenStore.clearTokens();
|
|
94
|
-
vi.clearAllMocks();
|
|
95
|
-
// Setup mock server with default pending callback
|
|
96
|
-
mockServer = createMockCallbackServer();
|
|
97
|
-
mockServer.waitForCallback.mockReturnValue(new Promise(()=>{
|
|
98
|
-
/* pending forever by default */ }));
|
|
99
|
-
vi.mocked(CallbackServer).mockImplementation(()=>mockServer);
|
|
100
|
-
});
|
|
101
|
-
it('should execute mock OAuth flow successfully (default behavior)', async ()=>{
|
|
102
|
-
const result = await executeOAuthFlow(tokenStore);
|
|
103
|
-
// Verify mock tokens were generated and stored
|
|
104
|
-
const storedTokens = tokenStore.getTokens();
|
|
105
|
-
expect(storedTokens).toBeDefined();
|
|
106
|
-
expect(storedTokens?.accessToken).toMatch(/^figt_mock_access_token_/);
|
|
107
|
-
expect(storedTokens?.refreshToken).toMatch(/^figt_mock_refresh_token_/);
|
|
108
|
-
expect(storedTokens?.tokenType).toBe('Bearer');
|
|
109
|
-
expect(storedTokens?.expiresAt).toBeGreaterThan(Date.now());
|
|
110
|
-
// Verify result
|
|
111
|
-
expect(result.tokens).toEqual(storedTokens);
|
|
112
|
-
expect(result.userId).toBe('mock_user_123');
|
|
113
|
-
// Verify callback server was NOT started (mock flow skips it)
|
|
114
|
-
expect(mockServer.waitForCallback).not.toHaveBeenCalled();
|
|
115
|
-
});
|
|
116
|
-
it('should handle callback timeout (real OAuth flow)', async ()=>{
|
|
117
|
-
// Temporarily disable mocking to test real OAuth flow error handling
|
|
118
|
-
const originalEnv = process.env.FIGMA_MOCK_OAUTH;
|
|
119
|
-
process.env.FIGMA_MOCK_OAUTH = 'false';
|
|
120
|
-
mockServer.waitForCallback.mockRejectedValueOnce(new Error('Callback timed out'));
|
|
121
|
-
await expect(executeOAuthFlow(tokenStore)).rejects.toThrow(OAuthFlowError);
|
|
122
|
-
// Server should be stopped
|
|
123
|
-
expect(mockServer.stop).toHaveBeenCalled();
|
|
124
|
-
// Restore original environment
|
|
125
|
-
if (originalEnv === undefined) {
|
|
126
|
-
delete process.env.FIGMA_MOCK_OAUTH;
|
|
127
|
-
} else {
|
|
128
|
-
process.env.FIGMA_MOCK_OAUTH = originalEnv;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
//# sourceMappingURL=oauth-flow.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/oauth-flow.spec.ts"],"sourcesContent":["import { beforeEach, describe, expect, it, vi } from 'vitest'\n\nimport type { FigmaTokens } from './types.js'\n\nimport { CallbackServer } from './callback-server.js'\nimport { executeOAuthFlow, getValidAccessToken, OAuthFlowError } from './oauth-flow.js'\nimport { refreshAccessToken } from './refresh.js'\nimport { TokenStore } from './token-store.js'\n\n// Mock the refresh module\nvi.mock('./refresh.js', () => ({\n exchangeCodeForTokens: vi.fn(),\n refreshAccessToken: vi.fn(),\n}))\n\n// Mock browser and callback server\nvi.mock('./browser.js', () => ({\n buildAuthorizationUrl: vi.fn(() => 'https://www.figma.com/oauth?...'),\n openBrowser: vi.fn(),\n}))\n\n// Mock @clack/prompts\nvi.mock('@clack/prompts', () => ({\n confirm: vi.fn().mockResolvedValue(true),\n isCancel: vi.fn().mockReturnValue(false),\n}))\n\n// Create mock factory for CallbackServer\nconst createMockCallbackServer = () => {\n const mock = {\n getActualPort: vi.fn().mockReturnValue(3000),\n stop: vi.fn(),\n waitForCallback: vi.fn(),\n }\n return mock\n}\n\nvi.mock('./callback-server.js', () => ({\n CallbackServer: vi.fn(),\n}))\n\ndescribe('oauth-flow', () => {\n describe('getValidAccessToken', () => {\n let tokenStore: TokenStore\n\n beforeEach(() => {\n tokenStore = new TokenStore({ configName: 'test-payloadcms-figma-oauth-flow' })\n tokenStore.clearTokens()\n })\n\n it('should return access token if valid tokens exist', async () => {\n const mockTokens: FigmaTokens = {\n accessToken: 'valid-token',\n expiresAt: Date.now() + 3600000, // 1 hour from now\n refreshToken: 'refresh-token',\n }\n\n tokenStore.setTokens(mockTokens)\n\n const token = await getValidAccessToken(tokenStore)\n expect(token).toBe('valid-token')\n })\n\n it('should refresh expired tokens', async () => {\n const expiredTokens: FigmaTokens = {\n accessToken: 'expired-token',\n expiresAt: Date.now() - 1000, // Expired\n refreshToken: 'refresh-token',\n }\n\n tokenStore.setTokens(expiredTokens)\n\n const newTokens: FigmaTokens = {\n accessToken: 'new-token',\n expiresAt: Date.now() + 3600000,\n refreshToken: 'new-refresh-token',\n }\n\n // Mock the refresh function\n vi.mocked(refreshAccessToken).mockResolvedValueOnce(newTokens)\n\n const token = await getValidAccessToken(tokenStore)\n expect(token).toBe('new-token')\n\n // Verify tokens were stored\n const storedTokens = tokenStore.getTokens()\n expect(storedTokens?.accessToken).toBe('new-token')\n })\n\n it('should clear tokens and throw on refresh failure', async () => {\n const expiredTokens: FigmaTokens = {\n accessToken: 'expired-token',\n expiresAt: Date.now() - 1000,\n refreshToken: 'refresh-token',\n }\n\n tokenStore.setTokens(expiredTokens)\n\n // Mock refresh to fail\n vi.mocked(refreshAccessToken).mockRejectedValueOnce(new Error('Refresh failed'))\n\n await expect(getValidAccessToken(tokenStore)).rejects.toThrow(OAuthFlowError)\n\n // Verify tokens were cleared\n expect(tokenStore.getTokens()).toBeNull()\n })\n })\n\n describe('executeOAuthFlow', () => {\n let tokenStore: TokenStore\n let mockServer: ReturnType<typeof createMockCallbackServer>\n\n beforeEach(() => {\n tokenStore = new TokenStore({ configName: 'test-payloadcms-figma-oauth-execute' })\n tokenStore.clearTokens()\n vi.clearAllMocks()\n\n // Setup mock server with default pending callback\n mockServer = createMockCallbackServer()\n mockServer.waitForCallback.mockReturnValue(\n new Promise(() => {\n /* pending forever by default */\n }),\n )\n vi.mocked(CallbackServer).mockImplementation(() => mockServer as unknown as CallbackServer)\n })\n\n it('should execute mock OAuth flow successfully (default behavior)', async () => {\n const result = await executeOAuthFlow(tokenStore)\n\n // Verify mock tokens were generated and stored\n const storedTokens = tokenStore.getTokens()\n expect(storedTokens).toBeDefined()\n expect(storedTokens?.accessToken).toMatch(/^figt_mock_access_token_/)\n expect(storedTokens?.refreshToken).toMatch(/^figt_mock_refresh_token_/)\n expect(storedTokens?.tokenType).toBe('Bearer')\n expect(storedTokens?.expiresAt).toBeGreaterThan(Date.now())\n\n // Verify result\n expect(result.tokens).toEqual(storedTokens)\n expect(result.userId).toBe('mock_user_123')\n\n // Verify callback server was NOT started (mock flow skips it)\n expect(mockServer.waitForCallback).not.toHaveBeenCalled()\n })\n\n it('should handle callback timeout (real OAuth flow)', async () => {\n // Temporarily disable mocking to test real OAuth flow error handling\n const originalEnv = process.env.FIGMA_MOCK_OAUTH\n process.env.FIGMA_MOCK_OAUTH = 'false'\n\n mockServer.waitForCallback.mockRejectedValueOnce(new Error('Callback timed out'))\n\n await expect(executeOAuthFlow(tokenStore)).rejects.toThrow(OAuthFlowError)\n\n // Server should be stopped\n expect(mockServer.stop).toHaveBeenCalled()\n\n // Restore original environment\n if (originalEnv === undefined) {\n delete process.env.FIGMA_MOCK_OAUTH\n } else {\n process.env.FIGMA_MOCK_OAUTH = originalEnv\n }\n })\n })\n})\n"],"names":["beforeEach","describe","expect","it","vi","CallbackServer","executeOAuthFlow","getValidAccessToken","OAuthFlowError","refreshAccessToken","TokenStore","mock","exchangeCodeForTokens","fn","buildAuthorizationUrl","openBrowser","confirm","mockResolvedValue","isCancel","mockReturnValue","createMockCallbackServer","getActualPort","stop","waitForCallback","tokenStore","configName","clearTokens","mockTokens","accessToken","expiresAt","Date","now","refreshToken","setTokens","token","toBe","expiredTokens","newTokens","mocked","mockResolvedValueOnce","storedTokens","getTokens","mockRejectedValueOnce","Error","rejects","toThrow","toBeNull","mockServer","clearAllMocks","Promise","mockImplementation","result","toBeDefined","toMatch","tokenType","toBeGreaterThan","tokens","toEqual","userId","not","toHaveBeenCalled","originalEnv","process","env","FIGMA_MOCK_OAUTH","undefined"],"mappings":"AAAA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAI7D,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,gBAAgB,EAAEC,mBAAmB,EAAEC,cAAc,QAAQ,kBAAiB;AACvF,SAASC,kBAAkB,QAAQ,eAAc;AACjD,SAASC,UAAU,QAAQ,mBAAkB;AAE7C,0BAA0B;AAC1BN,GAAGO,IAAI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B,OAAO,CAAC;YAC3CnD,OAAOsC,cAAcc,WAAWnB,IAAI,CAAC;YACrCjC,OAAOsC,cAAcX,WAAW0B,eAAe,CAACzB,KAAKC,GAAG;YAExD,gBAAgB;YAChB7B,OAAOiD,OAAOK,MAAM,EAAEC,OAAO,CAACjB;YAC9BtC,OAAOiD,OAAOO,MAAM,EAAEvB,IAAI,CAAC;YAE3B,8DAA8D;YAC9DjC,OAAO6C,WAAWxB,eAAe,EAAEoC,GAAG,CAACC,gBAAgB;QACzD;QAEAzD,GAAG,oDAAoD;YACrD,qEAAqE;YACrE,MAAM0D,cAAcC,QAAQC,GAAG,CAACC,gBAAgB;YAChDF,QAAQC,GAAG,CAACC,gBAAgB,GAAG;YAE/BjB,WAAWxB,eAAe,CAACmB,qBAAqB,CAAC,IAAIC,MAAM;YAE3D,MAAMzC,OAAOI,iBAAiBkB,aAAaoB,OAAO,CAACC,OAAO,CAACrC;YAE3D,2BAA2B;YAC3BN,OAAO6C,WAAWzB,IAAI,EAAEsC,gBAAgB;YAExC,+BAA+B;YAC/B,IAAIC,gBAAgBI,WAAW;gBAC7B,OAAOH,QAAQC,GAAG,CAACC,gBAAgB;YACrC,OAAO;gBACLF,QAAQC,GAAG,CAACC,gBAAgB,GAAGH;YACjC;QACF;IACF;AACF"}
|
package/dist/auth/pkce.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pkce.spec.d.ts","sourceRoot":"","sources":["../../src/auth/pkce.spec.ts"],"names":[],"mappings":""}
|
package/dist/auth/pkce.spec.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { generateCodeChallenge, generatePKCEPair } from './pkce.js';
|
|
3
|
-
describe('generateCodeChallenge', ()=>{
|
|
4
|
-
it('should generate consistent challenge for same verifier', ()=>{
|
|
5
|
-
const verifier = 'test-verifier-123456789012345678901234567890';
|
|
6
|
-
const challenge1 = generateCodeChallenge(verifier);
|
|
7
|
-
const challenge2 = generateCodeChallenge(verifier);
|
|
8
|
-
expect(challenge1).toBe(challenge2);
|
|
9
|
-
});
|
|
10
|
-
it('should generate different challenges for different verifiers', ()=>{
|
|
11
|
-
const verifier1 = 'test-verifier-1';
|
|
12
|
-
const verifier2 = 'test-verifier-2';
|
|
13
|
-
const challenge1 = generateCodeChallenge(verifier1);
|
|
14
|
-
const challenge2 = generateCodeChallenge(verifier2);
|
|
15
|
-
expect(challenge1).not.toBe(challenge2);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('generatePKCEPair', ()=>{
|
|
19
|
-
it('should generate a complete PKCE pair', ()=>{
|
|
20
|
-
const pair = generatePKCEPair();
|
|
21
|
-
expect(pair).toHaveProperty('codeVerifier');
|
|
22
|
-
expect(pair).toHaveProperty('codeChallenge');
|
|
23
|
-
expect(pair).toHaveProperty('codeChallengeMethod');
|
|
24
|
-
});
|
|
25
|
-
it('should generate challenge derived from verifier', ()=>{
|
|
26
|
-
const pair = generatePKCEPair();
|
|
27
|
-
const derivedChallenge = generateCodeChallenge(pair.codeVerifier);
|
|
28
|
-
expect(pair.codeChallenge).toBe(derivedChallenge);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
//# sourceMappingURL=pkce.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/pkce.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { generateCodeChallenge, generatePKCEPair } from './pkce.js'\n\ndescribe('generateCodeChallenge', () => {\n it('should generate consistent challenge for same verifier', () => {\n const verifier = 'test-verifier-123456789012345678901234567890'\n const challenge1 = generateCodeChallenge(verifier)\n const challenge2 = generateCodeChallenge(verifier)\n expect(challenge1).toBe(challenge2)\n })\n\n it('should generate different challenges for different verifiers', () => {\n const verifier1 = 'test-verifier-1'\n const verifier2 = 'test-verifier-2'\n const challenge1 = generateCodeChallenge(verifier1)\n const challenge2 = generateCodeChallenge(verifier2)\n expect(challenge1).not.toBe(challenge2)\n })\n})\n\ndescribe('generatePKCEPair', () => {\n it('should generate a complete PKCE pair', () => {\n const pair = generatePKCEPair()\n\n expect(pair).toHaveProperty('codeVerifier')\n expect(pair).toHaveProperty('codeChallenge')\n expect(pair).toHaveProperty('codeChallengeMethod')\n })\n\n it('should generate challenge derived from verifier', () => {\n const pair = generatePKCEPair()\n const derivedChallenge = generateCodeChallenge(pair.codeVerifier)\n expect(pair.codeChallenge).toBe(derivedChallenge)\n })\n})\n"],"names":["describe","expect","it","generateCodeChallenge","generatePKCEPair","verifier","challenge1","challenge2","toBe","verifier1","verifier2","not","pair","toHaveProperty","derivedChallenge","codeVerifier","codeChallenge"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,qBAAqB,EAAEC,gBAAgB,QAAQ,YAAW;AAEnEJ,SAAS,yBAAyB;IAChCE,GAAG,0DAA0D;QAC3D,MAAMG,WAAW;QACjB,MAAMC,aAAaH,sBAAsBE;QACzC,MAAME,aAAaJ,sBAAsBE;QACzCJ,OAAOK,YAAYE,IAAI,CAACD;IAC1B;IAEAL,GAAG,gEAAgE;QACjE,MAAMO,YAAY;QAClB,MAAMC,YAAY;QAClB,MAAMJ,aAAaH,sBAAsBM;QACzC,MAAMF,aAAaJ,sBAAsBO;QACzCT,OAAOK,YAAYK,GAAG,CAACH,IAAI,CAACD;IAC9B;AACF;AAEAP,SAAS,oBAAoB;IAC3BE,GAAG,wCAAwC;QACzC,MAAMU,OAAOR;QAEbH,OAAOW,MAAMC,cAAc,CAAC;QAC5BZ,OAAOW,MAAMC,cAAc,CAAC;QAC5BZ,OAAOW,MAAMC,cAAc,CAAC;IAC9B;IAEAX,GAAG,mDAAmD;QACpD,MAAMU,OAAOR;QACb,MAAMU,mBAAmBX,sBAAsBS,KAAKG,YAAY;QAChEd,OAAOW,KAAKI,aAAa,EAAER,IAAI,CAACM;IAClC;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"project-token.spec.d.ts","sourceRoot":"","sources":["../../src/auth/project-token.spec.ts"],"names":[],"mappings":""}
|