-
Notifications
You must be signed in to change notification settings - Fork 103
fix(vscode): Fix Workflow save, token persistence #9406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bjbennet
wants to merge
6
commits into
Azure:main
Choose a base branch
from
bjbennet:dev/brbenn/workflow_save_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82d35d3
initial checkin
bjbennet c8ba0ed
Potential fix for pull request finding
bjbennet ac4eacd
addressing pr comments
bjbennet 78afe97
Merge branch 'dev/brbenn/workflow_save_fix' of https://github.com/bjb…
bjbennet bc2ecf3
merge: Resolve merge conflict with upstream/main refactor
bjbennet 9b394cf
Merge branch 'main' into dev/brbenn/workflow_save_fix
bjbennet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
apps/vs-code-designer/src/app/utils/codeless/__test__/getAuthorizationToken.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import { getAuthorizationToken, getAuthorizationTokenFromNode, getCloudHost } from '../getAuthorizationToken'; | ||
|
|
||
| // The module-level mock for '@microsoft/vscode-azext-azureauth/out/src/getSessionFromVSCode' | ||
| // is aliased via vitest.config.ts to '__mocks__/vscode-azext-azureauth.ts'. | ||
| // We import and spy on it to control return values per test. | ||
| import * as azureAuth from '@microsoft/vscode-azext-azureauth/out/src/getSessionFromVSCode'; | ||
| import * as vscode from 'vscode'; | ||
|
|
||
| vi.mock('@microsoft/vscode-azext-azureauth', () => ({ | ||
| getConfiguredAzureEnv: vi.fn(() => ({ | ||
| managementEndpointUrl: 'https://management.azure.com', | ||
| })), | ||
| })); | ||
|
|
||
| describe('getAuthorizationToken', () => { | ||
| beforeEach(() => { | ||
| vi.restoreAllMocks(); | ||
| // Mock vscode.workspace.getConfiguration to return a config with get() | ||
| vi.mocked(vscode.workspace.getConfiguration).mockReturnValue({ | ||
| get: vi.fn(() => false), | ||
| } as any); | ||
| }); | ||
|
|
||
| it('should return a Bearer token when session has an accessToken', async () => { | ||
| vi.spyOn(azureAuth, 'getSessionFromVSCode').mockResolvedValue({ | ||
| accessToken: 'test-token-123', | ||
| id: 'session-1', | ||
| account: { id: 'account-1', label: 'Test' }, | ||
| scopes: [], | ||
| } as any); | ||
|
|
||
| const token = await getAuthorizationToken('test-tenant'); | ||
| expect(token).toBe('Bearer test-token-123'); | ||
| }); | ||
|
|
||
| it('should return "Bearer undefined" when session returns no accessToken', async () => { | ||
| // Note: getAuthorizationToken does not guard against undefined accessToken. | ||
| // The token refresh interval in openDesignerForLocalProject guards against this | ||
| // by checking for "undefined" in the returned string before propagating it. | ||
| vi.spyOn(azureAuth, 'getSessionFromVSCode').mockResolvedValue({ | ||
| id: 'session-1', | ||
| account: { id: 'account-1', label: 'Test' }, | ||
| scopes: [], | ||
| } as any); | ||
|
|
||
| const token = await getAuthorizationToken(); | ||
| expect(token).toBe('Bearer undefined'); | ||
| }); | ||
|
|
||
| it('should propagate errors when session acquisition fails', async () => { | ||
| vi.spyOn(azureAuth, 'getSessionFromVSCode').mockRejectedValue(new Error('Auth session expired')); | ||
|
|
||
| await expect(getAuthorizationToken()).rejects.toThrow('Auth session expired'); | ||
| }); | ||
|
|
||
| it('should pass tenantId to getSessionFromVSCode', async () => { | ||
| const spy = vi.spyOn(azureAuth, 'getSessionFromVSCode').mockResolvedValue({ | ||
| accessToken: 'tenant-token', | ||
| id: 'session-1', | ||
| account: { id: 'account-1', label: 'Test' }, | ||
| scopes: [], | ||
| } as any); | ||
|
|
||
| await getAuthorizationToken('specific-tenant-id'); | ||
| expect(spy).toHaveBeenCalledWith(undefined, 'specific-tenant-id', expect.any(Object)); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getAuthorizationTokenFromNode', () => { | ||
| beforeEach(() => { | ||
| vi.restoreAllMocks(); | ||
| vi.mocked(vscode.workspace.getConfiguration).mockReturnValue({ | ||
| get: vi.fn(() => false), | ||
| } as any); | ||
| }); | ||
|
|
||
| it('should throw when node is null/undefined', async () => { | ||
| await expect(getAuthorizationTokenFromNode(null as any)).rejects.toThrow(); | ||
| }); | ||
|
|
||
| it('should throw when node has no subscription', async () => { | ||
| const node = {} as any; | ||
| await expect(getAuthorizationTokenFromNode(node)).rejects.toThrow(); | ||
| }); | ||
|
|
||
| it('should return Bearer token from node subscription credentials', async () => { | ||
| const node = { | ||
| subscription: { | ||
| tenantId: 'tenant-1', | ||
| credentials: { | ||
| getToken: vi.fn().mockResolvedValue({ token: 'node-token-abc' }), | ||
| }, | ||
| }, | ||
| } as any; | ||
|
|
||
| const token = await getAuthorizationTokenFromNode(node); | ||
| expect(token).toBe('Bearer node-token-abc'); | ||
| }); | ||
|
|
||
| it('should fall back to getAuthorizationToken when credentials.getToken returns null', async () => { | ||
| vi.spyOn(azureAuth, 'getSessionFromVSCode').mockResolvedValue({ | ||
| accessToken: 'fallback-token', | ||
| id: 'session-1', | ||
| account: { id: 'account-1', label: 'Test' }, | ||
| scopes: [], | ||
| } as any); | ||
|
|
||
| const node = { | ||
| subscription: { | ||
| tenantId: 'tenant-1', | ||
| credentials: { | ||
| getToken: vi.fn().mockResolvedValue(null), | ||
| }, | ||
| }, | ||
| } as any; | ||
|
|
||
| const token = await getAuthorizationTokenFromNode(node); | ||
| expect(token).toBe('Bearer fallback-token'); | ||
| }); | ||
|
|
||
| it('should fall back to getAuthorizationToken when no credentials exist', async () => { | ||
| vi.spyOn(azureAuth, 'getSessionFromVSCode').mockResolvedValue({ | ||
| accessToken: 'fallback-token-2', | ||
| id: 'session-1', | ||
| account: { id: 'account-1', label: 'Test' }, | ||
| scopes: [], | ||
| } as any); | ||
|
|
||
| const node = { | ||
| subscription: { | ||
| tenantId: 'tenant-2', | ||
| credentials: undefined, | ||
| }, | ||
| } as any; | ||
|
|
||
| const token = await getAuthorizationTokenFromNode(node); | ||
| expect(token).toBe('Bearer fallback-token-2'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getCloudHost', () => { | ||
| it('should return the managementEndpointUrl from configured environment', async () => { | ||
| const host = await getCloudHost(); | ||
| expect(host).toBe('https://management.azure.com'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.