Skip to content

Commit

Permalink
NuGetAuthenticate task
Browse files Browse the repository at this point in the history
  • Loading branch information
zarenner committed Jul 30, 2019
1 parent 5e27a19 commit 4bdb4ac
Show file tree
Hide file tree
Showing 29 changed files with 1,531 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ Tasks/CmdLineV2/* @bryanmacfarlane

Tasks/CocoaPodsV0/* @madhurig

Tasks/Common/artifacts-common/* @zjrunner @zarenner @shubham90

Tasks/Common/AzureRmDeploy-common/* @vincentdass @SumiranAgg

Tasks/Common/Deployment/* @bishal-pdMSFT @chshrikh
Expand Down Expand Up @@ -247,6 +249,8 @@ Tasks/NuGetV0/* @zjrunner

Tasks/NuGetCommandV2/* @zjrunner @jotaylo

Tasks/NuGetAuthenticateV0/* @zjrunner @zarenner

Tasks/NuGetPackagerV0/* @zjrunner

Tasks/NuGetPublisherV0/* @zjrunner
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"loc.messages.CredProvider_Error_FailedCopy": "Failed to copy from '%s' to '%s' while installing the credential provider. Ensure that the destination directory is not in use and that the agent account has permission to write to it.",
"loc.messages.CredProvider_Error_FailedRemoveDir": "Failed to remove the directory '%s' while installing the credential provider. Ensure that this directory is not in use and that the agent account has permission to delete this directory.",
"loc.messages.CredProvider_Error_InvalidServiceConnection": "The service connection for '%s' is not valid.",
"loc.messages.CredProvider_Error_InvalidServiceConnection_ApiKey": "The service connection for '%s' is not valid. ApiKey service connections are not supported in this task. Instead, use -ApiKey (NuGet) or --api-key (dotnet) when invoking the tool itself. See the task documentation for more details.",
"loc.messages.CredProvider_InstallingNetCoreTo": "Installing the Azure Artifacts Credential Provider (.NET Core) to '%s'. This credential provider is compatible with dotnet SDK 2.1.400 or later.",
"loc.messages.CredProvider_InstallingNetFxTo": "Installing the Azure Artifacts Credential Provider (.NET Framework) to '%s'. This credential provider is compatible with nuget.exe 4.8.0.5385 or later, and MSBuild 15.8.166.59604 or later.",
"loc.messages.CredProvider_SettingUpForOrgFeeds": "Setting up the credential provider to use the identity '%s' for feeds in your organization/collection starting with:",
"loc.messages.CredProvider_SettingUpForServiceConnections": "Setting up the credential provider for these service connections:",
"loc.messages.ServiceConnections_Error_FailedToParseServiceEndpoint_MissingParameter": "Failed to parse the service endpoint '%s' because it was missing the parameter '%s'",
"loc.messages.ServiceConnections_Error_FailedToParseServiceEndpoint_BadScheme": "Failed to parse the service endpoint '%s' because the auth scheme '%s' was invalid"
}
9 changes: 9 additions & 0 deletions Tasks/Common/artifacts-common/Tests/L0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { packagingAccessMappingUtilsTests } from "./packagingAccessMappingUtilsTests";
import { credentialProviderUtilsTests } from "./credentialProviderUtilsTests";
import { serviceConnectionUtilsTests } from "./serviceConnectionUtilsTests";

describe("artifacts-common suite", function() {
describe("packagingAccessMappingUtils", packagingAccessMappingUtilsTests);
describe("credentialProviderUtils", credentialProviderUtilsTests);
describe("serviceConnectionUtils", serviceConnectionUtilsTests);
});
110 changes: 110 additions & 0 deletions Tasks/Common/artifacts-common/Tests/credentialProviderUtilsTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import * as assert from "assert";
import { buildExternalFeedEndpointsJson } from "../credentialProviderUtils";
import { ServiceConnectionAuthType, TokenServiceConnection, ApiKeyServiceConnection, UsernamePasswordServiceConnection } from "../serviceConnectionUtils";

export function credentialProviderUtilsTests() {

beforeEach(() => {
});

afterEach(() => {
});

it("buildExternalFeedEndpointsJson null returns null", (done: MochaDone) => {
assert.equal(buildExternalFeedEndpointsJson(null), null);
done();
});

it("buildExternalFeedEndpointsJson empty returns null", (done: MochaDone) => {
assert.equal(buildExternalFeedEndpointsJson([]), null);
done();
});

it("buildExternalFeedEndpointsJson token", (done: MochaDone) => {
const json = buildExternalFeedEndpointsJson([
<TokenServiceConnection>{
packageSource: {
uri: "https://contoso.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.Token,
token: "sometoken"
}
])

assert.equal(json, "{\"endpointCredentials\":[{\"endpoint\":\"https://contoso.com/nuget/v3/index.json\",\"password\":\"sometoken\"}]}");

done();
});

it("buildExternalFeedEndpointsJson usernamepassword", (done: MochaDone) => {
const json = buildExternalFeedEndpointsJson([
<UsernamePasswordServiceConnection>{
packageSource: {
uri: "https://fabrikam.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.UsernamePassword,
username: "someusername",
password: "somepassword"
}
])

assert.equal(json, "{\"endpointCredentials\":[{\"endpoint\":\"https://fabrikam.com/nuget/v3/index.json\",\"username\":\"someusername\",\"password\":\"somepassword\"}]}");

done();
});

it("buildExternalFeedEndpointsJson token + usernamepassword", (done: MochaDone) => {
const json = buildExternalFeedEndpointsJson([
<TokenServiceConnection>{
packageSource: {
uri: "https://contoso.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.Token,
token: "sometoken"
},
<UsernamePasswordServiceConnection>{
packageSource: {
uri: "https://fabrikam.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.UsernamePassword,
username: "someusername",
password: "somepassword"
}
])

assert.equal(json, "{\"endpointCredentials\":[{\"endpoint\":\"https://contoso.com/nuget/v3/index.json\",\"password\":\"sometoken\"},{\"endpoint\":\"https://fabrikam.com/nuget/v3/index.json\",\"username\":\"someusername\",\"password\":\"somepassword\"}]}");

done();
});

it("buildExternalFeedEndpointsJson apikey throws", (done: MochaDone) => {
assert.throws(() => {
buildExternalFeedEndpointsJson([
<ApiKeyServiceConnection>{
packageSource: {
uri: "https://contoso.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.ApiKey,
apiKey: "someapikey"
}
])
});

done();
});

it("buildExternalFeedEndpointsJson otherauthtype throws", (done: MochaDone) => {
assert.throws(() => {
buildExternalFeedEndpointsJson([
{
packageSource: {
uri: "https://contoso.com/nuget/v3/index.json"
},
authType: <any>"unsupportedauthtype",
}
])
});

done();
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import * as assert from "assert";
import { getPackagingAccessMappings, PackagingAccessMapping } from "../packagingAccessMappingUtils";

export function packagingAccessMappingUtilsTests() {
const standardDefaultAccessMappingMoniker = "PublicAccessMapping";

function getAccessMappings(newDomain) {
let publicAccessPoint = "https://contoso.pkgs.visualstudio.com/"
if (newDomain) {
publicAccessPoint = "https://pkgs.dev.azure.com/contoso/";
}
return [
{
displayName: "Host Guid Access Mapping",
moniker: "HostGuidAccessMapping",
accessPoint: "https://pkgsprodscussu0.pkgs.visualstudio.com/",
serviceOwner: "00000000-0000-0000-0000-000000000000",
virtualDirectory: "Aa731d82f-a042-44ad-a928-61581ea38485"
},
{
displayName: "Public Access Mapping",
moniker: "PublicAccessMapping",
accessPoint: publicAccessPoint,
serviceOwner: "00000000-0000-0000-0000-000000000000",
virtualDirectory: ""
},
{
displayName: "VSTS Access Mapping",
moniker: "VstsAccessMapping",
accessPoint: "https://contoso.pkgs.visualstudio.com/",
serviceOwner: "00000000-0000-0000-0000-000000000000",
virtualDirectory: ""
},
{
displayName: "Codex Access Mapping",
moniker: "CodexAccessMapping",
accessPoint: "https://pkgs.dev.azure.com/contoso/",
serviceOwner: "00000000-0000-0000-0000-000000000000",
virtualDirectory: ""
}];
}


beforeEach(() => {
});

afterEach(() => {
});

it("getPackagingAccessMappings pkgs.visualstudio.com default", (done: MochaDone) => {
const mappings = getPackagingAccessMappings({
defaultAccessMappingMoniker: standardDefaultAccessMappingMoniker,
accessMappings: getAccessMappings(false)});

assert.deepEqual(mappings, <PackagingAccessMapping[]>[
{
uri: "https://pkgsprodscussu0.pkgs.visualstudio.com/Aa731d82f-a042-44ad-a928-61581ea38485/",
isPublic: false,
isDefault: false
},
{
uri: "https://contoso.pkgs.visualstudio.com/",
isPublic: true,
isDefault: true
},
{
uri: "https://contoso.pkgs.visualstudio.com/",
isPublic: true,
isDefault: false
},
{
uri: "https://pkgs.dev.azure.com/contoso/",
isPublic: true,
isDefault: false
}
]);

done();
});

it("getPackagingAccessMappings pkgs.dev.azure.com default", (done: MochaDone) => {
const mappings = getPackagingAccessMappings({
defaultAccessMappingMoniker: standardDefaultAccessMappingMoniker,
accessMappings: getAccessMappings(true)});

assert.deepEqual(mappings, <PackagingAccessMapping[]>[
{
uri: "https://pkgsprodscussu0.pkgs.visualstudio.com/Aa731d82f-a042-44ad-a928-61581ea38485/",
isPublic: false,
isDefault: false
},
{
uri: "https://pkgs.dev.azure.com/contoso/",
isPublic: true,
isDefault: true
},
{
uri: "https://contoso.pkgs.visualstudio.com/",
isPublic: true,
isDefault: false
},
{
uri: "https://pkgs.dev.azure.com/contoso/",
isPublic: true,
isDefault: false
}
]);

done();
});

it("getPackagingAccessMappings adds trailing slash if missing", (done: MochaDone) => {
const mappings = getPackagingAccessMappings({
defaultAccessMappingMoniker: standardDefaultAccessMappingMoniker,
accessMappings: [
{
moniker: "MissingSlashAccessMapping",
accessPoint: "http://pkgs.dev.azure.com/contoso"
}
]});

assert.deepEqual(mappings, [
{
uri: "http://pkgs.dev.azure.com/contoso/",
isPublic: false,
isDefault: false
}
]);

done();
});
}
Loading

0 comments on commit 4bdb4ac

Please sign in to comment.