Path: blob/main/extensions/github-authentication/src/test/flows.test.ts
3321 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as assert from 'assert';6import { ExtensionHost, GitHubTarget, IFlowQuery, getFlows } from '../flows';7import { Config } from '../config';89const enum Flows {10UrlHandlerFlow = 'url handler',11LocalServerFlow = 'local server',12DeviceCodeFlow = 'device code',13PatFlow = 'personal access token'14}1516suite('getFlows', () => {17let lastClientSecret: string | undefined = undefined;18suiteSetup(() => {19lastClientSecret = Config.gitHubClientSecret;20Config.gitHubClientSecret = 'asdf';21});2223suiteTeardown(() => {24Config.gitHubClientSecret = lastClientSecret;25});2627const testCases: Array<{ label: string; query: IFlowQuery; expectedFlows: Flows[] }> = [28{29label: 'VS Code Desktop. Local filesystem. GitHub.com',30query: {31extensionHost: ExtensionHost.Local,32isSupportedClient: true,33target: GitHubTarget.DotCom34},35expectedFlows: [36Flows.LocalServerFlow,37Flows.UrlHandlerFlow,38Flows.DeviceCodeFlow39]40},41{42label: 'VS Code Desktop. Local filesystem. GitHub Hosted Enterprise',43query: {44extensionHost: ExtensionHost.Local,45isSupportedClient: true,46target: GitHubTarget.HostedEnterprise47},48expectedFlows: [49Flows.LocalServerFlow,50Flows.UrlHandlerFlow,51Flows.DeviceCodeFlow,52Flows.PatFlow53]54},55{56label: 'VS Code Desktop. Local filesystem. GitHub Enterprise Server',57query: {58extensionHost: ExtensionHost.Local,59isSupportedClient: true,60target: GitHubTarget.Enterprise61},62expectedFlows: [63Flows.DeviceCodeFlow,64Flows.PatFlow65]66},67{68label: 'vscode.dev. serverful. GitHub.com',69query: {70extensionHost: ExtensionHost.Remote,71isSupportedClient: true,72target: GitHubTarget.DotCom73},74expectedFlows: [75Flows.UrlHandlerFlow,76Flows.DeviceCodeFlow77]78},79{80label: 'vscode.dev. serverful. GitHub Hosted Enterprise',81query: {82extensionHost: ExtensionHost.Remote,83isSupportedClient: true,84target: GitHubTarget.HostedEnterprise85},86expectedFlows: [87Flows.UrlHandlerFlow,88Flows.DeviceCodeFlow,89Flows.PatFlow90]91},92{93label: 'vscode.dev. serverful. GitHub Enterprise',94query: {95extensionHost: ExtensionHost.Remote,96isSupportedClient: true,97target: GitHubTarget.Enterprise98},99expectedFlows: [100Flows.DeviceCodeFlow,101Flows.PatFlow102]103},104{105label: 'vscode.dev. serverless. GitHub.com',106query: {107extensionHost: ExtensionHost.WebWorker,108isSupportedClient: true,109target: GitHubTarget.DotCom110},111expectedFlows: [112Flows.UrlHandlerFlow113]114},115{116label: 'vscode.dev. serverless. GitHub Hosted Enterprise',117query: {118extensionHost: ExtensionHost.WebWorker,119isSupportedClient: true,120target: GitHubTarget.HostedEnterprise121},122expectedFlows: [123Flows.UrlHandlerFlow,124Flows.PatFlow125]126},127{128label: 'vscode.dev. serverless. GitHub Enterprise Server',129query: {130extensionHost: ExtensionHost.WebWorker,131isSupportedClient: true,132target: GitHubTarget.Enterprise133},134expectedFlows: [135Flows.PatFlow136]137},138{139label: 'Code - OSS. Local filesystem. GitHub.com',140query: {141extensionHost: ExtensionHost.Local,142isSupportedClient: false,143target: GitHubTarget.DotCom144},145expectedFlows: [146Flows.LocalServerFlow,147Flows.DeviceCodeFlow,148Flows.PatFlow149]150},151{152label: 'Code - OSS. Local filesystem. GitHub Hosted Enterprise',153query: {154extensionHost: ExtensionHost.Local,155isSupportedClient: false,156target: GitHubTarget.HostedEnterprise157},158expectedFlows: [159Flows.LocalServerFlow,160Flows.DeviceCodeFlow,161Flows.PatFlow162]163},164{165label: 'Code - OSS. Local filesystem. GitHub Enterprise Server',166query: {167extensionHost: ExtensionHost.Local,168isSupportedClient: false,169target: GitHubTarget.Enterprise170},171expectedFlows: [172Flows.DeviceCodeFlow,173Flows.PatFlow174]175},176];177178for (const testCase of testCases) {179test(`gives the correct flows - ${testCase.label}`, () => {180const flows = getFlows(testCase.query);181182assert.strictEqual(183flows.length,184testCase.expectedFlows.length,185`Unexpected number of flows: ${flows.map(f => f.label).join(',')}`186);187188for (let i = 0; i < flows.length; i++) {189const flow = flows[i];190191assert.strictEqual(flow.label, testCase.expectedFlows[i]);192}193});194}195});196197198