Skip to content

Commit 3a28ca8

Browse files
Merge pull request #4607 from aldoms/users/aldoms/dotNetPreviewM119
Users/aldoms/dot net preview m119
2 parents 3ea0b84 + b99964e commit 3a28ca8

File tree

7 files changed

+102
-6
lines changed

7 files changed

+102
-6
lines changed

Tasks/DotNetCoreCLI/Tests/DotnetMockHelper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export class DotnetMockHelper {
4646
})
4747
}
4848

49+
public setOnPremServerUris() {
50+
process.env['SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'] = "https://example.privatedomain.com/defaultcollection";
51+
process.env['ENDPOINT_URL_SYSTEMVSSCONNECTION'] = "https://example.privatedomain.com/defaultcollection";
52+
}
53+
4954
private registerNugetVersionMockInternal(productVersion: string, versionInfoVersion: number[]) {
5055
this.registerMockWithMultiplePaths(['nuget-task-common/pe-parser/index', './pe-parser/index'], {
5156
getFileVersionInfoAsync: function(nuGetExePath) {

Tasks/DotNetCoreCLI/Tests/L0.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ describe('DotNetCoreExe Suite', function () {
292292
done();
293293
});
294294

295-
it('pushes successfully to internal feed using NuGet.exe', (done: MochaDone) => {
295+
it('pushes successfully to internal hosted feed', (done: MochaDone) => {
296296
this.timeout(1000);
297297

298298
let tp = path.join(__dirname, './PushTests/internalFeed.js')
@@ -306,4 +306,21 @@ describe('DotNetCoreExe Suite', function () {
306306
assert.equal(tr.errorIssues.length, 0, "should have no errors");
307307
done();
308308
});
309+
310+
it('pushes successfully to internal onprem feed, does not set auth in config', (done: MochaDone) => {
311+
this.timeout(1000);
312+
313+
let tp = path.join(__dirname, './PushTests/internalFeedOnPrem.js')
314+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
315+
316+
tr.run()
317+
assert(tr.invokedToolCount == 1, 'should have run dotnet once');
318+
assert(tr.ran('c:\\path\\dotnet.exe nuget push c:\\agent\\home\\directory\\foo.nupkg --source https://vsts/packagesource --api-key VSTS'), 'it should have run dotnet');
319+
assert(tr.stdOutContained('Push to internal OnPrem server detected. Credential configuration will be skipped.'), "should detect internal onprem push");
320+
assert(tr.stdOutContained('dotnet output'), "should have dotnet output");
321+
assert(tr.succeeded, 'should have succeeded');
322+
assert.equal(tr.errorIssues.length, 0, "should have no errors");
323+
done();
324+
});
325+
309326
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import ma = require('vsts-task-lib/mock-answer');
2+
import tmrm = require('vsts-task-lib/mock-run');
3+
import path = require('path');
4+
import util = require('../DotnetMockHelper');
5+
6+
let taskPath = path.join(__dirname, '../..', 'dotnetcore.js');
7+
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
8+
let nmh: util.DotnetMockHelper = new util.DotnetMockHelper(tmr);
9+
10+
nmh.setNugetVersionInputDefault();
11+
nmh.setOnPremServerUris();
12+
tmr.setInput('command', 'push');
13+
tmr.setInput('searchPatternPush', 'foo.nupkg');
14+
tmr.setInput('nuGetFeedType', 'internal');
15+
tmr.setInput('feedPublish', 'FeedFooId');
16+
17+
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
18+
"osType": {},
19+
"checkPath": {
20+
"c:\\agent\\home\\directory\\foo.nupkg": true,
21+
"c:\\path\\dotnet.exe": true
22+
},
23+
"which": {
24+
"dotnet": "c:\\path\\dotnet.exe"
25+
},
26+
"exec": {
27+
"c:\\path\\dotnet.exe nuget push c:\\agent\\home\\directory\\foo.nupkg --source https://vsts/packagesource --api-key VSTS": {
28+
"code": 0,
29+
"stdout": "dotnet output",
30+
"stderr": ""
31+
}
32+
},
33+
"exist": {},
34+
"stats": {
35+
"c:\\agent\\home\\directory\\foo.nupkg": {
36+
"isFile": true
37+
}
38+
},
39+
"rmRF": {
40+
"c:\\agent\\home\\directory\\NuGet_1": {
41+
"success": true
42+
},
43+
"c:\\agent\\home\\directory/NuGet_1": {
44+
"success": true
45+
}
46+
},
47+
"findMatch": {
48+
"foo.nupkg" : ["c:\\agent\\home\\directory\\foo.nupkg"]
49+
}
50+
};
51+
nmh.setAnswers(a);
52+
53+
nmh.registerNugetUtilityMock(["c:\\agent\\home\\directory\\foo.nupkg"]);
54+
nmh.registerDefaultNugetVersionMock();
55+
nmh.registerToolRunnerMock();
56+
nmh.registerNugetConfigMock();
57+
nmh.RegisterLocationServiceMocks();
58+
59+
tmr.run();

Tasks/DotNetCoreCLI/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vsts-tasks-dotnetcoreexe",
3-
"version": "0.1.0",
3+
"version": "2.0.2",
44
"description": "Dotnet core exe",
55
"main": "dotnetcore.js",
66
"scripts": {

Tasks/DotNetCoreCLI/pushcommand.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ export async function run(): Promise<void> {
6161

6262
// Setting up auth info
6363
let externalAuthArr = commandHelper.GetExternalAuthInfoArray("externalEndpoint");
64+
6465
let accessToken = auth.getSystemAccessToken();
66+
const isInternalFeed: boolean = nugetFeedType === "internal";
67+
let useCredConfig = useCredentialConfiguration(isInternalFeed);
68+
let internalAuthInfo = new auth.InternalAuthInfo(urlPrefixes, accessToken, /*useCredProvider*/ null, useCredConfig);
6569

66-
let authInfo = new auth.NuGetExtendedAuthInfo(new auth.InternalAuthInfo(urlPrefixes, accessToken, /*useCredProvider*/ null, /*useCredConfig*/ true), externalAuthArr);
70+
let authInfo = new auth.NuGetExtendedAuthInfo(internalAuthInfo, externalAuthArr);
6771

6872
let configFile = null;
6973
let apiKey: string;
@@ -80,7 +84,6 @@ export async function run(): Promise<void> {
8084

8185
const nuGetConfigHelper = new NuGetConfigHelper2(nuGetPath, null, authInfo, {credProviderFolder: null, extensionsDisabled: true}, tempNuGetPath);
8286
let feedUri: string = undefined;
83-
const isInternalFeed: boolean = nugetFeedType === "internal";
8487

8588
if (isInternalFeed)
8689
{
@@ -168,3 +171,13 @@ function dotNetNuGetPushAsync(dotnetPath: string, packageFile: string, feedUri:
168171

169172
return dotnet.exec({ cwd: workingDirectory } as IExecOptions);
170173
}
174+
175+
function useCredentialConfiguration(isInternalFeed: boolean): boolean {
176+
// if we are pushing to an internal on-premises server, then credential configuration is not possible
177+
// and integrated authentication must be used
178+
let useCredConfig = !(isInternalFeed && commandHelper.isOnPremisesTfs());
179+
if (!useCredConfig) {
180+
tl.debug("Push to internal OnPrem server detected. Credential configuration will be skipped.")
181+
}
182+
return useCredConfig;
183+
}

Tasks/DotNetCoreCLI/task.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
"Agent"
1515
],
1616
"demands": [],
17+
"preview": true,
1718
"version": {
1819
"Major": 2,
1920
"Minor": 0,
20-
"Patch": 0
21+
"Patch": 2
2122
},
2223
"minimumAgentVersion": "2.0.0",
2324
"instanceNameFormat": "dotnet $(command)",

Tasks/DotNetCoreCLI/task.loc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
"Agent"
1515
],
1616
"demands": [],
17+
"preview": true,
1718
"version": {
1819
"Major": 2,
1920
"Minor": 0,
20-
"Patch": 0
21+
"Patch": 2
2122
},
2223
"minimumAgentVersion": "2.0.0",
2324
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",

0 commit comments

Comments
 (0)