Skip to content

Commit 5cc8d8b

Browse files
Artifacts-Common Added setseceret in constructor and abstract method in Service Connection (#330)
* added setseceret in constructor and abstract method. * removed mockery. used tasklib mock instead * test cases fix
1 parent 10397db commit 5cc8d8b

File tree

5 files changed

+152
-258
lines changed

5 files changed

+152
-258
lines changed

common-npm-packages/artifacts-common/Tests/credentialProviderUtilsTests.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ export function credentialProviderUtilsTests() {
1010
afterEach(() => {
1111
});
1212

13-
it("buildExternalFeedEndpointsJson null returns null", (done: MochaDone) => {
13+
it("buildExternalFeedEndpointsJson null returns null", (done: Mocha.Done) => {
1414
assert.equal(buildExternalFeedEndpointsJson(null), null);
1515
done();
1616
});
1717

18-
it("buildExternalFeedEndpointsJson empty returns null", (done: MochaDone) => {
18+
it("buildExternalFeedEndpointsJson empty returns null", (done: Mocha.Done) => {
1919
assert.equal(buildExternalFeedEndpointsJson([]), null);
2020
done();
2121
});
2222

23-
it("buildExternalFeedEndpointsJson token", (done: MochaDone) => {
23+
it("buildExternalFeedEndpointsJson token", (done: Mocha.Done) => {
2424
const json = buildExternalFeedEndpointsJson([
2525
<TokenServiceConnection>{
2626
packageSource: {
27-
uri: "https://contoso.com/nuget/v3/index.json"
27+
uri: "https://contoso.com/nuget/v3/index.json"
2828
},
2929
authType: ServiceConnectionAuthType.Token,
3030
token: "sometoken"
@@ -36,11 +36,11 @@ export function credentialProviderUtilsTests() {
3636
done();
3737
});
3838

39-
it("buildExternalFeedEndpointsJson usernamepassword", (done: MochaDone) => {
39+
it("buildExternalFeedEndpointsJson usernamepassword", (done: Mocha.Done) => {
4040
const json = buildExternalFeedEndpointsJson([
4141
<UsernamePasswordServiceConnection>{
4242
packageSource: {
43-
uri: "https://fabrikam.com/nuget/v3/index.json"
43+
uri: "https://fabrikam.com/nuget/v3/index.json"
4444
},
4545
authType: ServiceConnectionAuthType.UsernamePassword,
4646
username: "someusername",
@@ -53,18 +53,18 @@ export function credentialProviderUtilsTests() {
5353
done();
5454
});
5555

56-
it("buildExternalFeedEndpointsJson token + usernamepassword", (done: MochaDone) => {
56+
it("buildExternalFeedEndpointsJson token + usernamepassword", (done: Mocha.Done) => {
5757
const json = buildExternalFeedEndpointsJson([
5858
<TokenServiceConnection>{
5959
packageSource: {
60-
uri: "https://contoso.com/nuget/v3/index.json"
60+
uri: "https://contoso.com/nuget/v3/index.json"
6161
},
6262
authType: ServiceConnectionAuthType.Token,
6363
token: "sometoken"
6464
},
6565
<UsernamePasswordServiceConnection>{
6666
packageSource: {
67-
uri: "https://fabrikam.com/nuget/v3/index.json"
67+
uri: "https://fabrikam.com/nuget/v3/index.json"
6868
},
6969
authType: ServiceConnectionAuthType.UsernamePassword,
7070
username: "someusername",
@@ -77,12 +77,12 @@ export function credentialProviderUtilsTests() {
7777
done();
7878
});
7979

80-
it("buildExternalFeedEndpointsJson apikey throws", (done: MochaDone) => {
80+
it("buildExternalFeedEndpointsJson apikey throws", (done: Mocha.Done) => {
8181
assert.throws(() => {
8282
buildExternalFeedEndpointsJson([
8383
<ApiKeyServiceConnection>{
8484
packageSource: {
85-
uri: "https://contoso.com/nuget/v3/index.json"
85+
uri: "https://contoso.com/nuget/v3/index.json"
8686
},
8787
authType: ServiceConnectionAuthType.ApiKey,
8888
apiKey: "someapikey"
@@ -93,14 +93,15 @@ export function credentialProviderUtilsTests() {
9393
done();
9494
});
9595

96-
it("buildExternalFeedEndpointsJson otherauthtype throws", (done: MochaDone) => {
96+
it("buildExternalFeedEndpointsJson otherauthtype throws", (done: Mocha.Done) => {
9797
assert.throws(() => {
9898
buildExternalFeedEndpointsJson([
9999
{
100100
packageSource: {
101-
uri: "https://contoso.com/nuget/v3/index.json"
101+
uri: "https://contoso.com/nuget/v3/index.json"
102102
},
103103
authType: <any>"unsupportedauthtype",
104+
maskSecret: () => void {}
104105
}
105106
])
106107
});

common-npm-packages/artifacts-common/Tests/serviceConnectionUtilsTests.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import * as assert from "assert";
2-
import * as mockery from "mockery";
2+
// import * as mockery from "mockery";
33
import { EndpointAuthorization } from "azure-pipelines-task-lib";
44
import { ServiceConnectionAuthType, TokenServiceConnection, UsernamePasswordServiceConnection, ApiKeyServiceConnection, IAdditionalData } from "../serviceConnectionUtils";
5+
import * as mocker from "azure-pipelines-task-lib/lib-mocker";
56

67
export function serviceConnectionUtilsTests() {
78

89
const serviceConnectionsKey = "someProtocolServiceConnections";
910

1011
before(() => {
11-
mockery.disable(); // needed to ensure that we can mock vsts-task-lib/task
12-
mockery.enable({
12+
mocker.disable(); // needed to ensure that we can mock vsts-task-lib/task
13+
mocker.enable({
1314
useCleanCache: true,
1415
warnOnUnregistered: true
15-
} as mockery.MockeryEnableArgs);
16+
} as mocker.MockOptions);
1617
});
1718

1819
after(() => {
19-
mockery.disable();
20+
mocker.disable();
2021
});
2122

2223
beforeEach(() => {
23-
mockery.resetCache();
24-
mockery.registerAllowable("../serviceConnectionUtils");
24+
mocker.resetCache();
25+
mocker.registerAllowable("../serviceConnectionUtils");
2526
});
2627

2728
afterEach(() => {
28-
mockery.deregisterAll();
29+
mocker.deregisterAll();
2930
});
3031

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

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

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

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

101103
let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
102104
assert.throws(() => serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey));
@@ -114,9 +116,10 @@ export function serviceConnectionUtilsTests() {
114116
scheme: "usernamepassword"
115117
},
116118
setResourcePath: (path) => {},
117-
getEndpointAuthorizationScheme: (key, optional): string => "usernamepassword"
119+
getEndpointAuthorizationScheme: (key, optional): string => "usernamepassword",
120+
setSecret : msg => null
118121
};
119-
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
122+
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);
120123

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

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

168171
let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
169172
assert.throws(() => serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey));
@@ -181,9 +184,10 @@ export function serviceConnectionUtilsTests() {
181184
scheme: "none"
182185
},
183186
setResourcePath: (path) => {},
184-
getEndpointAuthorizationScheme: (key, optional): string => "none"
187+
getEndpointAuthorizationScheme: (key, optional): string => "none",
188+
setSecret : msg => null
185189
};
186-
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
190+
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);
187191

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

215219
let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
216220
assert.throws(() => serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey));
@@ -235,9 +239,10 @@ export function serviceConnectionUtilsTests() {
235239
}
236240
return values[key];
237241
},
238-
setResourcePath: (path) => {}
242+
setResourcePath: (path) => {},
243+
setSecret : msg => null
239244
};
240-
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
245+
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);
241246

242247
let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
243248
assert.deepEqual(serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey, ["key1", "key2"]), [<TokenServiceConnection>{
@@ -270,9 +275,10 @@ export function serviceConnectionUtilsTests() {
270275
"key2" : "value2"
271276
}
272277
return values[key];
273-
}
278+
},
279+
setSecret : msg => null
274280
};
275-
mockery.registerMock('azure-pipelines-task-lib/task', mockTask);
281+
mocker.registerMock('azure-pipelines-task-lib/task', mockTask);
276282

277283
let serviceConnectionUtilsWithMocks = require("../serviceConnectionUtils");
278284
assert.deepEqual(serviceConnectionUtilsWithMocks.getPackagingServiceConnections(serviceConnectionsKey, ["key1", "key2"]), [<TokenServiceConnection>{

0 commit comments

Comments
 (0)