From 707c8fe011024bc3b459d55a687b3a21c7831d05 Mon Sep 17 00:00:00 2001 From: Peter Spillman Date: Tue, 13 Jun 2017 12:27:07 -0400 Subject: [PATCH] NuGetCommand multipleServiceConnection L0 --- Tasks/NuGetCommand/Common/utilities.ts | 3 + Tasks/NuGetCommand/Tests/L0.ts | 18 ++++++ .../multipleServiceConnections.ts | 62 +++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 Tasks/NuGetCommand/Tests/RestoreTests/multipleServiceConnections.ts diff --git a/Tasks/NuGetCommand/Common/utilities.ts b/Tasks/NuGetCommand/Common/utilities.ts index 023ee10c86d8..f9d9f035e617 100644 --- a/Tasks/NuGetCommand/Common/utilities.ts +++ b/Tasks/NuGetCommand/Common/utilities.ts @@ -57,6 +57,7 @@ export function GetExternalAuthInfoArray(inputKey: string): auth.ExternalAuthInf switch(scheme) { case "token": let token = externalAuth.parameters["apitoken"]; + tl.debug("adding token auth entry for feed " + feedUri); externalAuthArray.push(new auth.TokenExternalAuthInfo( { feedName: feedName, @@ -67,6 +68,7 @@ export function GetExternalAuthInfoArray(inputKey: string): auth.ExternalAuthInf case "usernamepassword": let username = externalAuth.parameters["username"]; let password = externalAuth.parameters["password"]; + tl.debug("adding password auth entry for feed " + feedUri); externalAuthArray.push(new auth.UsernamePasswordExternalAuthInfo( { feedName: feedName, @@ -77,6 +79,7 @@ export function GetExternalAuthInfoArray(inputKey: string): auth.ExternalAuthInf break; case "none": let apiKey = externalAuth.parameters["nugetkey"]; + tl.debug("adding apikey auth entry for feed " + feedUri); externalAuthArray.push(new auth.ApiKeyExternalAuthInfo( { feedName: feedName, diff --git a/Tasks/NuGetCommand/Tests/L0.ts b/Tasks/NuGetCommand/Tests/L0.ts index c00965bc218f..f00265d817c7 100644 --- a/Tasks/NuGetCommand/Tests/L0.ts +++ b/Tasks/NuGetCommand/Tests/L0.ts @@ -295,4 +295,22 @@ describe('NuGetCommand Suite', function () { assert.equal(tr.errorIssues.length, 0, "should have no errors"); done(); }); + + it('restore single solution with nuget config and multiple service connections', (done: MochaDone) => { + this.timeout(1000); + + let tp = path.join(__dirname, './RestoreTests/multipleServiceConnections.js') + let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + tr.run() + assert(tr.invokedToolCount == 1, 'should have run NuGet once'); + assert(tr.ran('c:\\from\\tool\\installer\\nuget.exe restore c:\\agent\\home\\directory\\single.sln -NonInteractive -ConfigFile c:\\agent\\home\\directory\\tempNuGet_.config'), 'it should have run NuGet with ConfigFile specified'); + assert(tr.stdOutContained('setting console code page'), 'it should have run chcp'); + assert(tr.stdOutContained('adding token auth entry for feed https://endpoint1.visualstudio.com/path'), 'it should have added auth entry for endpoint 1'); + assert(tr.stdOutContained('adding token auth entry for feed https://endpoint2.visualstudio.com/path'), 'it should have added auth entry for endpoint 2'); + assert(tr.stdOutContained('NuGet output here'), "should have nuget output"); + assert(tr.succeeded, 'should have succeeded'); + assert.equal(tr.errorIssues.length, 0, "should have no errors"); + done(); + }); }); \ No newline at end of file diff --git a/Tasks/NuGetCommand/Tests/RestoreTests/multipleServiceConnections.ts b/Tasks/NuGetCommand/Tests/RestoreTests/multipleServiceConnections.ts new file mode 100644 index 000000000000..f5cfa6914e68 --- /dev/null +++ b/Tasks/NuGetCommand/Tests/RestoreTests/multipleServiceConnections.ts @@ -0,0 +1,62 @@ +import ma = require('vsts-task-lib/mock-answer'); +import tmrm = require('vsts-task-lib/mock-run'); +import path = require('path'); +import util = require('../NugetMockHelper'); + +let taskPath = path.join(__dirname, '../..', 'nugetcommandmain.js'); +let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath); +let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr); + +process.env['ENDPOINT_URL_ENDPOINT1'] = "https://endpoint1.visualstudio.com/path"; +process.env['ENDPOINT_AUTH_ENDPOINT1'] = "{\"parameters\":{\"apitoken\":\"mytoken123\"},\"scheme\":\"token\"}"; +process.env["ENDPOINT_AUTH_SCHEME_ENDPOINT1"] = "token"; +process.env['ENDPOINT_AUTH_PARAMETER_ENDPOINT1_APITOKEN'] = "mytoken123"; +process.env['ENDPOINT_URL_ENDPOINT2'] = "https://endpoint2.visualstudio.com/path"; +process.env['ENDPOINT_AUTH_ENDPOINT2'] = "{\"parameters\":{\"apitoken\":\"mytoken123\"},\"scheme\":\"token\"}"; +process.env["ENDPOINT_AUTH_SCHEME_ENDPOINT2"] = "token"; +process.env['ENDPOINT_AUTH_PARAMETER_ENDPOINT1_APITOKEN'] = "mytoken123"; + +nmh.setNugetVersionInputDefault(); +tmr.setInput('command', 'restore'); +tmr.setInput('solution', 'single.sln'); +tmr.setInput('selectOrConfig', 'config'); +tmr.setInput('nugetConfigPath', 'c:\\agent\\home\\directory\\nuget.config'); +tmr.setInput('externalEndpoints', "ENDPOINT1,ENDPOINT2"); + +let a: ma.TaskLibAnswers = { + "osType": {}, + "checkPath": { + "c:\\agent\\home\\directory\\nuget.config": true, + "c:\\agent\\home\\directory\\single.sln": true + }, + "which": {}, + "exec": { + "c:\\from\\tool\\installer\\nuget.exe restore c:\\agent\\home\\directory\\single.sln -NonInteractive -ConfigFile c:\\agent\\home\\directory\\tempNuGet_.config": { + "code": 0, + "stdout": "NuGet output here", + "stderr": "" + } + }, + "exist": {}, + "stats": { + "c:\\agent\\home\\directory\\single.sln": { + "isFile": true + } + }, + "rmRF": { + "c:\\agent\\home\\directory\\tempNuGet_.config": { + "success": true + } + }, + "findMatch": { + "single.sln" : ["c:\\agent\\home\\directory\\single.sln"] + } +}; +nmh.setAnswers(a); + +nmh.registerNugetUtilityMock(["c:\\agent\\home\\directory\\single.sln"]); +nmh.registerDefaultNugetVersionMock(); +nmh.registerNugetConfigMock(); +nmh.registerToolRunnerMock(); + +tmr.run();