diff --git a/test/auth/ask-pass.bat b/test/auth/ask-pass.bat deleted file mode 100644 index f167d6ea..00000000 --- a/test/auth/ask-pass.bat +++ /dev/null @@ -1,6 +0,0 @@ -@echo off -setlocal - -node "%ASKPASS_MAIN%" %* - -endlocal diff --git a/test/auth/ask-pass.sh b/test/auth/ask-pass.sh deleted file mode 100755 index 3ce73905..00000000 --- a/test/auth/ask-pass.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -node "$ASKPASS_MAIN" "$@" diff --git a/test/auth/main.ts b/test/auth/main.ts deleted file mode 100644 index c05b323b..00000000 --- a/test/auth/main.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** Parse the GIT_ASKPASS prompt and determine the appropriate response. */ -export function responseForPrompt(prompt: string): string | null { - const username: string | undefined = process.env.TEST_USERNAME - if (!username || !username.length) { - return null - } - - if (prompt.startsWith('Username')) { - return username - } - - const password: string | undefined = process.env.TEST_PASSWORD - if (!password || !password.length) { - return null - } - - if (prompt.startsWith('Password')) { - return password - } - - return null -} - -const prompt = process.argv[2] -const response = responseForPrompt(prompt) -if (response) { - process.stdout.write(response) -} diff --git a/test/fast/git-process-test.ts b/test/fast/git-process-test.ts index dcbaac99..522b0006 100644 --- a/test/fast/git-process-test.ts +++ b/test/fast/git-process-test.ts @@ -17,7 +17,6 @@ import { } from '../helpers' import { gitVersion } from '../helpers' -import { setupNoAuth } from '../slow/auth' import { pathToFileURL } from 'url' const temp = require('temp').track() @@ -26,9 +25,6 @@ describe('git-process', () => { it('can cancel in-progress git command', async () => { const sourceRepoPath = temp.mkdirSync('desktop-git-clone-source') const destinationRepoPath = temp.mkdirSync('desktop-git-clone-destination') - const options = { - env: setupNoAuth(), - } await GitProcess.exec(['init'], sourceRepoPath) await GitProcess.exec( @@ -38,8 +34,7 @@ describe('git-process', () => { const task = GitProcess.execTask( ['clone', '--', pathToFileURL(sourceRepoPath).toString(), '.'], - destinationRepoPath, - options + destinationRepoPath ) const cancelResult = await task.cancel() diff --git a/test/slow/auth.ts b/test/slow/auth.ts deleted file mode 100644 index dcd088bb..00000000 --- a/test/slow/auth.ts +++ /dev/null @@ -1,42 +0,0 @@ -import * as Path from 'path' - -function getAskPassScriptPath(): string { - const testRoot = Path.dirname(__dirname) - const projectRoot = Path.dirname(testRoot) - return Path.join(projectRoot, 'build', 'test', 'auth', `main.js`) -} - -function getAskPassTrampolinePath(): string { - const isWindows = process.platform === 'win32' - const extension = isWindows ? 'bat' : 'sh' - const testRoot = Path.dirname(__dirname) - const projectRoot = Path.dirname(testRoot) - return Path.join(projectRoot, 'test', 'auth', `ask-pass.${extension}`) -} - -const defaultEnv: Record = { - // supported since Git 2.3, this is used to ensure we never interactively prompt - // for credentials - even as a fallback - GIT_TERMINAL_PROMPT: '0', - // by setting HOME to an empty value Git won't look at ~ for any global - // configuration values. This means we won't accidentally use a - // credential.helper value if it's been set by the current user - HOME: '', -} - -export function setupAskPass( - username?: string, - password?: string -): Record { - return { - TEST_USERNAME: username, - TEST_PASSWORD: password, - ASKPASS_MAIN: getAskPassScriptPath(), - GIT_ASKPASS: getAskPassTrampolinePath(), - ...defaultEnv, - } -} - -export function setupNoAuth() { - return defaultEnv -} diff --git a/test/slow/git-process-test.ts b/test/slow/git-process-test.ts index a55182c5..5efe3075 100644 --- a/test/slow/git-process-test.ts +++ b/test/slow/git-process-test.ts @@ -3,7 +3,6 @@ import * as Path from 'path' import { GitProcess, GitError } from '../../lib' import { initialize, verify } from '../helpers' -import { setupAskPass, setupNoAuth } from './auth' import { pathToFileURL } from 'url' import { resolve } from 'path' import { createServer } from 'http' @@ -14,9 +13,6 @@ describe('git-process', () => { describe('clone', () => { it("returns exit code when repository doesn't exist", async () => { const testRepoPath = temp.mkdirSync('desktop-git-test-blank') - const options = { - env: setupNoAuth(), - } const result = await GitProcess.exec( [ @@ -25,8 +21,7 @@ describe('git-process', () => { pathToFileURL(resolve('i-for-sure-donut-exist')).toString(), '.', ], - testRepoPath, - options + testRepoPath ) verify(result, r => { @@ -37,7 +32,11 @@ describe('git-process', () => { it('returns exit code and error when repository requires credentials', async () => { const testRepoPath = temp.mkdirSync('desktop-git-test-blank') const options = { - env: setupAskPass('error', 'error'), + env: { + GIT_CONFIG_PARAMETERS: "'credential.helper='", + GIT_TERMINAL_PROMPT: '0', + GIT_ASKPASS: undefined, + }, } const server = createServer((req, res) => { @@ -61,13 +60,14 @@ describe('git-process', () => { try { const result = await GitProcess.exec( - ['clone', '--', `http://127.0.0.1:${port}/`, '.'], + ['clone', '--', `http://foo:bar@127.0.0.1:${port}/`, '.'], testRepoPath, options ) verify(result, r => { expect(r.exitCode).toBe(128) }) + const error = GitProcess.parseError(result.stderr) expect(error).toBe(GitError.HTTPSAuthenticationFailed) } finally { @@ -92,15 +92,7 @@ describe('git-process', () => { verify(addRemote, r => { expect(r.exitCode).toBe(0) }) - - const options = { - env: setupNoAuth(), - } - const result = await GitProcess.exec( - ['fetch', 'origin'], - testRepoPath, - options - ) + const result = await GitProcess.exec(['fetch', 'origin'], testRepoPath) verify(result, r => { expect(r.exitCode).toBe(128) })