Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ataverascrespo authored Jun 24, 2024
2 parents 1e12255 + 874c4f0 commit 6033343
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ export function credentialProviderUtilsTests() {
afterEach(() => {
});

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

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

it("buildExternalFeedEndpointsJson token", (done: MochaDone) => {
it("buildExternalFeedEndpointsJson token", (done: Mocha.Done) => {
const json = buildExternalFeedEndpointsJson([
<TokenServiceConnection>{
packageSource: {
uri: "https://contoso.com/nuget/v3/index.json"
uri: "https://contoso.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.Token,
token: "sometoken"
Expand All @@ -36,11 +36,11 @@ export function credentialProviderUtilsTests() {
done();
});

it("buildExternalFeedEndpointsJson usernamepassword", (done: MochaDone) => {
it("buildExternalFeedEndpointsJson usernamepassword", (done: Mocha.Done) => {
const json = buildExternalFeedEndpointsJson([
<UsernamePasswordServiceConnection>{
packageSource: {
uri: "https://fabrikam.com/nuget/v3/index.json"
uri: "https://fabrikam.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.UsernamePassword,
username: "someusername",
Expand All @@ -53,18 +53,18 @@ export function credentialProviderUtilsTests() {
done();
});

it("buildExternalFeedEndpointsJson token + usernamepassword", (done: MochaDone) => {
it("buildExternalFeedEndpointsJson token + usernamepassword", (done: Mocha.Done) => {
const json = buildExternalFeedEndpointsJson([
<TokenServiceConnection>{
packageSource: {
uri: "https://contoso.com/nuget/v3/index.json"
uri: "https://contoso.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.Token,
token: "sometoken"
},
<UsernamePasswordServiceConnection>{
packageSource: {
uri: "https://fabrikam.com/nuget/v3/index.json"
uri: "https://fabrikam.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.UsernamePassword,
username: "someusername",
Expand All @@ -77,12 +77,12 @@ export function credentialProviderUtilsTests() {
done();
});

it("buildExternalFeedEndpointsJson apikey throws", (done: MochaDone) => {
it("buildExternalFeedEndpointsJson apikey throws", (done: Mocha.Done) => {
assert.throws(() => {
buildExternalFeedEndpointsJson([
<ApiKeyServiceConnection>{
packageSource: {
uri: "https://contoso.com/nuget/v3/index.json"
uri: "https://contoso.com/nuget/v3/index.json"
},
authType: ServiceConnectionAuthType.ApiKey,
apiKey: "someapikey"
Expand All @@ -93,14 +93,15 @@ export function credentialProviderUtilsTests() {
done();
});

it("buildExternalFeedEndpointsJson otherauthtype throws", (done: MochaDone) => {
it("buildExternalFeedEndpointsJson otherauthtype throws", (done: Mocha.Done) => {
assert.throws(() => {
buildExternalFeedEndpointsJson([
{
packageSource: {
uri: "https://contoso.com/nuget/v3/index.json"
uri: "https://contoso.com/nuget/v3/index.json"
},
authType: <any>"unsupportedauthtype",
maskSecret: () => void {}
}
])
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import * as assert from "assert";
import * as mockery from "mockery";
// import * as mockery from "mockery";
import { EndpointAuthorization } from "azure-pipelines-task-lib";
import { ServiceConnectionAuthType, TokenServiceConnection, UsernamePasswordServiceConnection, ApiKeyServiceConnection, IAdditionalData } from "../serviceConnectionUtils";
import * as mocker from "azure-pipelines-task-lib/lib-mocker";

export function serviceConnectionUtilsTests() {

const serviceConnectionsKey = "someProtocolServiceConnections";

before(() => {
mockery.disable(); // needed to ensure that we can mock vsts-task-lib/task
mockery.enable({
mocker.disable(); // needed to ensure that we can mock vsts-task-lib/task
mocker.enable({
useCleanCache: true,
warnOnUnregistered: true
} as mockery.MockeryEnableArgs);
} as mocker.MockOptions);
});

after(() => {
mockery.disable();
mocker.disable();
});

beforeEach(() => {
mockery.resetCache();
mockery.registerAllowable("../serviceConnectionUtils");
mocker.resetCache();
mocker.registerAllowable("../serviceConnectionUtils");
});

afterEach(() => {
mockery.deregisterAll();
mocker.deregisterAll();
});

it("getPackagingServiceConnections null returns empty", (done: MochaDone) => {
Expand All @@ -35,7 +36,7 @@ export function serviceConnectionUtilsTests() {
},
setResourcePath: (path) => {}
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.deepEqual(serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey), []);
Expand All @@ -49,7 +50,7 @@ export function serviceConnectionUtilsTests() {
},
setResourcePath: (path) => {}
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.deepEqual(serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey), []);
Expand All @@ -67,9 +68,10 @@ export function serviceConnectionUtilsTests() {
scheme: "token"
},
setResourcePath: (path) => {},
getEndpointAuthorizationScheme: (key, optional): string => "token"
getEndpointAuthorizationScheme: (key, optional): string => "token",
setSecret : msg => null
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.deepEqual(serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey), [<TokenServiceConnection>{
Expand All @@ -96,7 +98,7 @@ export function serviceConnectionUtilsTests() {
setResourcePath: (path) => {},
getEndpointAuthorizationScheme: (key, optional): string => "token"
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.throws(() => serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey));
Expand All @@ -114,9 +116,10 @@ export function serviceConnectionUtilsTests() {
scheme: "usernamepassword"
},
setResourcePath: (path) => {},
getEndpointAuthorizationScheme: (key, optional): string => "usernamepassword"
getEndpointAuthorizationScheme: (key, optional): string => "usernamepassword",
setSecret : msg => null
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.deepEqual(serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey), [<UsernamePasswordServiceConnection>{
Expand Down Expand Up @@ -144,7 +147,7 @@ export function serviceConnectionUtilsTests() {
setResourcePath: (path) => {},
getEndpointAuthorizationScheme: (key, optional): string => "usernamepassword"
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.throws(() => serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey));
Expand All @@ -163,7 +166,7 @@ export function serviceConnectionUtilsTests() {
setResourcePath: (path) => {},
getEndpointAuthorizationScheme: (key, optional): string => "usernamepassword"
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.throws(() => serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey));
Expand All @@ -181,9 +184,10 @@ export function serviceConnectionUtilsTests() {
scheme: "none"
},
setResourcePath: (path) => {},
getEndpointAuthorizationScheme: (key, optional): string => "none"
getEndpointAuthorizationScheme: (key, optional): string => "none",
setSecret : msg => null
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.deepEqual(serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey), [<ApiKeyServiceConnection>{
Expand All @@ -210,7 +214,7 @@ export function serviceConnectionUtilsTests() {
setResourcePath: (path) => {},
getEndpointAuthorizationScheme: (key, optional): string => "none"
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.throws(() => serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey));
Expand All @@ -235,9 +239,10 @@ export function serviceConnectionUtilsTests() {
}
return values[key];
},
setResourcePath: (path) => {}
setResourcePath: (path) => {},
setSecret : msg => null
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.deepEqual(serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey, ["key1", "key2"]), [<TokenServiceConnection>{
Expand Down Expand Up @@ -270,9 +275,10 @@ export function serviceConnectionUtilsTests() {
"key2" : "value2"
}
return values[key];
}
},
setSecret : msg => null
};
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);

let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
assert.deepEqual(serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey, ["key1", "key2"]), [<TokenServiceConnection>{
Expand Down
3 changes: 2 additions & 1 deletion common-npm-packages/artifacts-common/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"MSILoginFailed": "Azure login failed using Managed Service Identity",
"ServiceConnections_Error_FailedToParseServiceEndpoint_MissingParameter": "Failed to parse the service endpoint '%s' because it was missing the parameter '%s'",
"ServiceConnections_Error_FailedToParseServiceEndpoint_BadScheme": "Failed to parse the service endpoint '%s' because the auth scheme '%s' was invalid",
"SettingAzureCloud": "Setting active cloud to: %s"
"SettingAzureCloud": "Setting active cloud to: %s",
"Info_GotAndMaskAuth":"Got auth token, setting it as secret so it does not print in console log"
}
}
Loading

0 comments on commit 6033343

Please sign in to comment.