mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 09:08:53 +01:00
Ensure access token comes from correct provider (#150473)
This commit is contained in:
@@ -59,6 +59,7 @@ class TestAuthProvider implements AuthenticationProvider {
|
||||
private id = 1;
|
||||
private sessions = new Map<string, AuthenticationSession>();
|
||||
onDidChangeSessions = () => { return { dispose() { } }; };
|
||||
constructor(private readonly authProviderName: string) { }
|
||||
async getSessions(scopes?: readonly string[]): Promise<AuthenticationSession[]> {
|
||||
if (!scopes) {
|
||||
return [...this.sessions.values()];
|
||||
@@ -76,7 +77,7 @@ class TestAuthProvider implements AuthenticationProvider {
|
||||
scopes,
|
||||
id: `${this.id}`,
|
||||
account: {
|
||||
label: `${this.id}`,
|
||||
label: this.authProviderName,
|
||||
id: `${this.id}`,
|
||||
},
|
||||
accessToken: Math.random() + '',
|
||||
@@ -118,11 +119,11 @@ suite('ExtHostAuthentication', () => {
|
||||
|
||||
setup(async () => {
|
||||
disposables = new DisposableStore();
|
||||
disposables.add(extHostAuthentication.registerAuthenticationProvider('test', 'test provider', new TestAuthProvider()));
|
||||
disposables.add(extHostAuthentication.registerAuthenticationProvider('test', 'test provider', new TestAuthProvider('test')));
|
||||
disposables.add(extHostAuthentication.registerAuthenticationProvider(
|
||||
'test-multiple',
|
||||
'test multiple provider',
|
||||
new TestAuthProvider(),
|
||||
new TestAuthProvider('test-multiple'),
|
||||
{ supportsMultipleAccounts: true }));
|
||||
});
|
||||
|
||||
@@ -441,5 +442,63 @@ suite('ExtHostAuthentication', () => {
|
||||
assert.strictEqual(session?.scopes[0], 'foo');
|
||||
});
|
||||
|
||||
test('Can get multiple sessions (from different providers) in one extension', async () => {
|
||||
let session: AuthenticationSession | undefined = await extHostAuthentication.getSession(
|
||||
extensionDescription,
|
||||
'test-multiple',
|
||||
['foo'],
|
||||
{
|
||||
createIfNone: true
|
||||
});
|
||||
session = await extHostAuthentication.getSession(
|
||||
extensionDescription,
|
||||
'test',
|
||||
['foo'],
|
||||
{
|
||||
createIfNone: true
|
||||
});
|
||||
assert.strictEqual(session?.id, '1');
|
||||
assert.strictEqual(session?.scopes[0], 'foo');
|
||||
assert.strictEqual(session?.account.label, 'test');
|
||||
|
||||
const session2 = await extHostAuthentication.getSession(
|
||||
extensionDescription,
|
||||
'test-multiple',
|
||||
['foo'],
|
||||
{
|
||||
createIfNone: false
|
||||
});
|
||||
assert.strictEqual(session2?.id, '1');
|
||||
assert.strictEqual(session2?.scopes[0], 'foo');
|
||||
assert.strictEqual(session2?.account.label, 'test-multiple');
|
||||
});
|
||||
|
||||
test('Can get multiple sessions (from different providers) in one extension at the same time', async () => {
|
||||
let sessionP: Promise<AuthenticationSession | undefined> = extHostAuthentication.getSession(
|
||||
extensionDescription,
|
||||
'test',
|
||||
['foo'],
|
||||
{
|
||||
createIfNone: true
|
||||
});
|
||||
let session2P: Promise<AuthenticationSession | undefined> = extHostAuthentication.getSession(
|
||||
extensionDescription,
|
||||
'test-multiple',
|
||||
['foo'],
|
||||
{
|
||||
createIfNone: true
|
||||
});
|
||||
const session = await sessionP;
|
||||
assert.strictEqual(session?.id, '1');
|
||||
assert.strictEqual(session?.scopes[0], 'foo');
|
||||
assert.strictEqual(session?.account.label, 'test');
|
||||
|
||||
const session2 = await session2P;
|
||||
assert.strictEqual(session2?.id, '1');
|
||||
assert.strictEqual(session2?.scopes[0], 'foo');
|
||||
assert.strictEqual(session2?.account.label, 'test-multiple');
|
||||
});
|
||||
|
||||
|
||||
//#endregion
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user