|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as assert from 'assert'; |
| 7 | +import { ExtensionHost, GitHubTarget, IFlowQuery, getFlows } from '../flows'; |
| 8 | +import { Config } from '../config'; |
| 9 | + |
| 10 | +const enum Flows { |
| 11 | + UrlHandlerFlow = 'url handler', |
| 12 | + LocalServerFlow = 'local server', |
| 13 | + DeviceCodeFlow = 'device code', |
| 14 | + PatFlow = 'personal access token' |
| 15 | +} |
| 16 | + |
| 17 | +suite('getFlows', () => { |
| 18 | + let lastClientSecret: string | undefined = undefined; |
| 19 | + suiteSetup(() => { |
| 20 | + lastClientSecret = Config.gitHubClientSecret; |
| 21 | + Config.gitHubClientSecret = 'asdf'; |
| 22 | + }); |
| 23 | + |
| 24 | + suiteTeardown(() => { |
| 25 | + Config.gitHubClientSecret = lastClientSecret; |
| 26 | + }); |
| 27 | + |
| 28 | + const testCases: Array<{ label: string; query: IFlowQuery; expectedFlows: Flows[] }> = [ |
| 29 | + { |
| 30 | + label: 'VS Code Desktop. Local filesystem. GitHub.com', |
| 31 | + query: { |
| 32 | + extensionHost: ExtensionHost.Local, |
| 33 | + isSupportedClient: true, |
| 34 | + target: GitHubTarget.DotCom |
| 35 | + }, |
| 36 | + expectedFlows: [ |
| 37 | + Flows.UrlHandlerFlow, |
| 38 | + Flows.LocalServerFlow, |
| 39 | + Flows.DeviceCodeFlow |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + label: 'VS Code Desktop. Local filesystem. GitHub Hosted Enterprise', |
| 44 | + query: { |
| 45 | + extensionHost: ExtensionHost.Local, |
| 46 | + isSupportedClient: true, |
| 47 | + target: GitHubTarget.HostedEnterprise |
| 48 | + }, |
| 49 | + expectedFlows: [ |
| 50 | + Flows.UrlHandlerFlow, |
| 51 | + Flows.LocalServerFlow, |
| 52 | + Flows.DeviceCodeFlow, |
| 53 | + Flows.PatFlow |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + label: 'VS Code Desktop. Local filesystem. GitHub Enterprise Server', |
| 58 | + query: { |
| 59 | + extensionHost: ExtensionHost.Local, |
| 60 | + isSupportedClient: true, |
| 61 | + target: GitHubTarget.Enterprise |
| 62 | + }, |
| 63 | + expectedFlows: [ |
| 64 | + Flows.DeviceCodeFlow, |
| 65 | + Flows.PatFlow |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + label: 'vscode.dev. serverful. GitHub.com', |
| 70 | + query: { |
| 71 | + extensionHost: ExtensionHost.Remote, |
| 72 | + isSupportedClient: true, |
| 73 | + target: GitHubTarget.DotCom |
| 74 | + }, |
| 75 | + expectedFlows: [ |
| 76 | + Flows.UrlHandlerFlow, |
| 77 | + Flows.DeviceCodeFlow |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + label: 'vscode.dev. serverful. GitHub Hosted Enterprise', |
| 82 | + query: { |
| 83 | + extensionHost: ExtensionHost.Remote, |
| 84 | + isSupportedClient: true, |
| 85 | + target: GitHubTarget.HostedEnterprise |
| 86 | + }, |
| 87 | + expectedFlows: [ |
| 88 | + Flows.UrlHandlerFlow, |
| 89 | + Flows.DeviceCodeFlow, |
| 90 | + Flows.PatFlow |
| 91 | + ] |
| 92 | + }, |
| 93 | + { |
| 94 | + label: 'vscode.dev. serverful. GitHub Enterprise', |
| 95 | + query: { |
| 96 | + extensionHost: ExtensionHost.Remote, |
| 97 | + isSupportedClient: true, |
| 98 | + target: GitHubTarget.Enterprise |
| 99 | + }, |
| 100 | + expectedFlows: [ |
| 101 | + Flows.DeviceCodeFlow, |
| 102 | + Flows.PatFlow |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + label: 'vscode.dev. serverless. GitHub.com', |
| 107 | + query: { |
| 108 | + extensionHost: ExtensionHost.WebWorker, |
| 109 | + isSupportedClient: true, |
| 110 | + target: GitHubTarget.DotCom |
| 111 | + }, |
| 112 | + expectedFlows: [ |
| 113 | + Flows.UrlHandlerFlow |
| 114 | + ] |
| 115 | + }, |
| 116 | + { |
| 117 | + label: 'vscode.dev. serverless. GitHub Hosted Enterprise', |
| 118 | + query: { |
| 119 | + extensionHost: ExtensionHost.WebWorker, |
| 120 | + isSupportedClient: true, |
| 121 | + target: GitHubTarget.HostedEnterprise |
| 122 | + }, |
| 123 | + expectedFlows: [ |
| 124 | + Flows.UrlHandlerFlow, |
| 125 | + Flows.PatFlow |
| 126 | + ] |
| 127 | + }, |
| 128 | + { |
| 129 | + label: 'vscode.dev. serverless. GitHub Enterprise Server', |
| 130 | + query: { |
| 131 | + extensionHost: ExtensionHost.WebWorker, |
| 132 | + isSupportedClient: true, |
| 133 | + target: GitHubTarget.Enterprise |
| 134 | + }, |
| 135 | + expectedFlows: [ |
| 136 | + Flows.PatFlow |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + label: 'Code - OSS. Local filesystem. GitHub.com', |
| 141 | + query: { |
| 142 | + extensionHost: ExtensionHost.Local, |
| 143 | + isSupportedClient: false, |
| 144 | + target: GitHubTarget.DotCom |
| 145 | + }, |
| 146 | + expectedFlows: [ |
| 147 | + Flows.LocalServerFlow, |
| 148 | + Flows.DeviceCodeFlow, |
| 149 | + Flows.PatFlow |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + label: 'Code - OSS. Local filesystem. GitHub Hosted Enterprise', |
| 154 | + query: { |
| 155 | + extensionHost: ExtensionHost.Local, |
| 156 | + isSupportedClient: false, |
| 157 | + target: GitHubTarget.HostedEnterprise |
| 158 | + }, |
| 159 | + expectedFlows: [ |
| 160 | + Flows.LocalServerFlow, |
| 161 | + Flows.DeviceCodeFlow, |
| 162 | + Flows.PatFlow |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | + label: 'Code - OSS. Local filesystem. GitHub Enterprise Server', |
| 167 | + query: { |
| 168 | + extensionHost: ExtensionHost.Local, |
| 169 | + isSupportedClient: false, |
| 170 | + target: GitHubTarget.Enterprise |
| 171 | + }, |
| 172 | + expectedFlows: [ |
| 173 | + Flows.DeviceCodeFlow, |
| 174 | + Flows.PatFlow |
| 175 | + ] |
| 176 | + }, |
| 177 | + ]; |
| 178 | + |
| 179 | + for (const testCase of testCases) { |
| 180 | + test(`gives the correct flows - ${testCase.label}`, () => { |
| 181 | + const flows = getFlows(testCase.query); |
| 182 | + |
| 183 | + assert.strictEqual( |
| 184 | + flows.length, |
| 185 | + testCase.expectedFlows.length, |
| 186 | + `Unexpected number of flows: ${flows.map(f => f.label).join(',')}` |
| 187 | + ); |
| 188 | + |
| 189 | + for (let i = 0; i < flows.length; i++) { |
| 190 | + const flow = flows[i]; |
| 191 | + |
| 192 | + assert.strictEqual(flow.label, testCase.expectedFlows[i]); |
| 193 | + } |
| 194 | + }); |
| 195 | + } |
| 196 | +}); |
0 commit comments