Path: blob/main/src/vs/platform/extensionManagement/test/common/configRemotes.test.ts
3296 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 assert from 'assert';6import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';7import { getDomainsOfRemotes, getRemotes } from '../../common/configRemotes.js';89suite('Config Remotes', () => {1011ensureNoDisposablesAreLeakedInTestSuite();1213const allowedDomains = [14'github.com',15'github2.com',16'github3.com',17'example.com',18'example2.com',19'example3.com',20'server.org',21'server2.org',22];2324test('HTTPS remotes', function () {25assert.deepStrictEqual(getDomainsOfRemotes(remote('https://github.com/microsoft/vscode.git'), allowedDomains), ['github.com']);26assert.deepStrictEqual(getDomainsOfRemotes(remote('https://git.example.com/gitproject.git'), allowedDomains), ['example.com']);27assert.deepStrictEqual(getDomainsOfRemotes(remote('https://[email protected]/username/repository.git'), allowedDomains), ['github2.com']);28assert.deepStrictEqual(getDomainsOfRemotes(remote('https://username:[email protected]/username/repository.git'), allowedDomains), ['github3.com']);29assert.deepStrictEqual(getDomainsOfRemotes(remote('https://username:[email protected]:1234/username/repository.git'), allowedDomains), ['example2.com']);30assert.deepStrictEqual(getDomainsOfRemotes(remote('https://example3.com:1234/username/repository.git'), allowedDomains), ['example3.com']);31});3233test('SSH remotes', function () {34assert.deepStrictEqual(getDomainsOfRemotes(remote('ssh://[email protected]/project.git'), allowedDomains), ['server.org']);35});3637test('SCP-like remotes', function () {38assert.deepStrictEqual(getDomainsOfRemotes(remote('[email protected]:microsoft/vscode.git'), allowedDomains), ['github.com']);39assert.deepStrictEqual(getDomainsOfRemotes(remote('[email protected]:project.git'), allowedDomains), ['server.org']);40assert.deepStrictEqual(getDomainsOfRemotes(remote('git.server2.org:project.git'), allowedDomains), ['server2.org']);41});4243test('Local remotes', function () {44assert.deepStrictEqual(getDomainsOfRemotes(remote('/opt/git/project.git'), allowedDomains), []);45assert.deepStrictEqual(getDomainsOfRemotes(remote('file:///opt/git/project.git'), allowedDomains), []);46});4748test('Multiple remotes', function () {49const config = ['https://github.com/microsoft/vscode.git', 'https://git.example.com/gitproject.git'].map(remote).join('');50assert.deepStrictEqual(getDomainsOfRemotes(config, allowedDomains).sort(), ['example.com', 'github.com']);51});5253test('Non allowed domains are anonymized', () => {54const config = ['https://github.com/microsoft/vscode.git', 'https://git.foobar.com/gitproject.git'].map(remote).join('');55assert.deepStrictEqual(getDomainsOfRemotes(config, allowedDomains).sort(), ['aaaaaa.aaa', 'github.com']);56});5758test('HTTPS remotes to be hashed', function () {59assert.deepStrictEqual(getRemotes(remote('https://github.com/microsoft/vscode.git')), ['github.com/microsoft/vscode.git']);60assert.deepStrictEqual(getRemotes(remote('https://git.example.com/gitproject.git')), ['git.example.com/gitproject.git']);61assert.deepStrictEqual(getRemotes(remote('https://[email protected]/username/repository.git')), ['github2.com/username/repository.git']);62assert.deepStrictEqual(getRemotes(remote('https://username:[email protected]/username/repository.git')), ['github3.com/username/repository.git']);63assert.deepStrictEqual(getRemotes(remote('https://username:[email protected]:1234/username/repository.git')), ['example2.com/username/repository.git']);64assert.deepStrictEqual(getRemotes(remote('https://example3.com:1234/username/repository.git')), ['example3.com/username/repository.git']);6566// Strip .git67assert.deepStrictEqual(getRemotes(remote('https://github.com/microsoft/vscode.git'), true), ['github.com/microsoft/vscode']);68assert.deepStrictEqual(getRemotes(remote('https://git.example.com/gitproject.git'), true), ['git.example.com/gitproject']);69assert.deepStrictEqual(getRemotes(remote('https://[email protected]/username/repository.git'), true), ['github2.com/username/repository']);70assert.deepStrictEqual(getRemotes(remote('https://username:[email protected]/username/repository.git'), true), ['github3.com/username/repository']);71assert.deepStrictEqual(getRemotes(remote('https://username:[email protected]:1234/username/repository.git'), true), ['example2.com/username/repository']);72assert.deepStrictEqual(getRemotes(remote('https://example3.com:1234/username/repository.git'), true), ['example3.com/username/repository']);7374// Compare Striped .git with no .git75assert.deepStrictEqual(getRemotes(remote('https://github.com/microsoft/vscode.git'), true), getRemotes(remote('https://github.com/microsoft/vscode')));76assert.deepStrictEqual(getRemotes(remote('https://git.example.com/gitproject.git'), true), getRemotes(remote('https://git.example.com/gitproject')));77assert.deepStrictEqual(getRemotes(remote('https://[email protected]/username/repository.git'), true), getRemotes(remote('https://[email protected]/username/repository')));78assert.deepStrictEqual(getRemotes(remote('https://username:[email protected]/username/repository.git'), true), getRemotes(remote('https://username:[email protected]/username/repository')));79assert.deepStrictEqual(getRemotes(remote('https://username:[email protected]:1234/username/repository.git'), true), getRemotes(remote('https://username:[email protected]:1234/username/repository')));80assert.deepStrictEqual(getRemotes(remote('https://example3.com:1234/username/repository.git'), true), getRemotes(remote('https://example3.com:1234/username/repository')));81});8283test('SSH remotes to be hashed', function () {84assert.deepStrictEqual(getRemotes(remote('ssh://[email protected]/project.git')), ['git.server.org/project.git']);8586// Strip .git87assert.deepStrictEqual(getRemotes(remote('ssh://[email protected]/project.git'), true), ['git.server.org/project']);8889// Compare Striped .git with no .git90assert.deepStrictEqual(getRemotes(remote('ssh://[email protected]/project.git'), true), getRemotes(remote('ssh://[email protected]/project')));91});9293test('SCP-like remotes to be hashed', function () {94assert.deepStrictEqual(getRemotes(remote('[email protected]:microsoft/vscode.git')), ['github.com/microsoft/vscode.git']);95assert.deepStrictEqual(getRemotes(remote('[email protected]:project.git')), ['git.server.org/project.git']);96assert.deepStrictEqual(getRemotes(remote('git.server2.org:project.git')), ['git.server2.org/project.git']);9798// Strip .git99assert.deepStrictEqual(getRemotes(remote('[email protected]:microsoft/vscode.git'), true), ['github.com/microsoft/vscode']);100assert.deepStrictEqual(getRemotes(remote('[email protected]:project.git'), true), ['git.server.org/project']);101assert.deepStrictEqual(getRemotes(remote('git.server2.org:project.git'), true), ['git.server2.org/project']);102103// Compare Striped .git with no .git104assert.deepStrictEqual(getRemotes(remote('[email protected]:microsoft/vscode.git'), true), getRemotes(remote('[email protected]:microsoft/vscode')));105assert.deepStrictEqual(getRemotes(remote('[email protected]:project.git'), true), getRemotes(remote('[email protected]:project')));106assert.deepStrictEqual(getRemotes(remote('git.server2.org:project.git'), true), getRemotes(remote('git.server2.org:project')));107});108109test('Local remotes to be hashed', function () {110assert.deepStrictEqual(getRemotes(remote('/opt/git/project.git')), []);111assert.deepStrictEqual(getRemotes(remote('file:///opt/git/project.git')), []);112});113114test('Multiple remotes to be hashed', function () {115const config = ['https://github.com/microsoft/vscode.git', 'https://git.example.com/gitproject.git'].map(remote).join(' ');116assert.deepStrictEqual(getRemotes(config), ['github.com/microsoft/vscode.git', 'git.example.com/gitproject.git']);117118// Strip .git119assert.deepStrictEqual(getRemotes(config, true), ['github.com/microsoft/vscode', 'git.example.com/gitproject']);120121// Compare Striped .git with no .git122const noDotGitConfig = ['https://github.com/microsoft/vscode', 'https://git.example.com/gitproject'].map(remote).join(' ');123assert.deepStrictEqual(getRemotes(config, true), getRemotes(noDotGitConfig));124});125126function remote(url: string): string {127return `[remote "origin"]128url = ${url}129fetch = +refs/heads/*:refs/remotes/origin/*130`;131}132133});134135136