Skip to content

Commit 709c585

Browse files
amp-powellAbby Powell
andauthored
Updating MavenAuthenticateV0 to allow new service connection type (#20229)
* Updating MavenAuthenticateV0 to allow new service connection type * Updated task.loc.json to not use str literals * Updated L0 tests to be compatible with mockery and generated wif version * Updated username for service connection and task version * Wrapping wif code * Reorganized code to authenticate federated connection first and then other connections if there is none * Specifying os type even for empty input test * Using additional feedName input for auth id and checked task works with new service connection * Parsing url for feed name * Added example feed url and check for both feed url and entra connection * Matching task.loc.json files * Updated task str's * Updated maven auth for cfs compliance * Updated other task components since removing feedUrl * task.loc.json needs full string * Updated task version for BuildConfigGen * Trying to match task.loc.json files for WIF * Updated str's * Matched task.loc.json strings * Using dependency range and sp guid for wif username * Reusing utils method for wif registries * Going back one commit --------- Co-authored-by: Abby Powell <[email protected]>
1 parent 5db26b2 commit 709c585

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6431
-1420
lines changed

Tasks/MavenAuthenticateV0/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
"loc.helpMarkDown": "[Learn more about this task](https://docs.microsoft.com/azure/devops/pipelines/tasks/package/maven-authenticate)",
44
"loc.description": "Provides credentials for Azure Artifacts feeds and external maven repositories",
55
"loc.instanceNameFormat": "Maven Authenticate",
6+
"loc.input.label.workloadIdentityServiceConnection": "'Entra Workload ID-backed Azure DevOps user' Service Connection",
7+
"loc.input.help.workloadIdentityServiceConnection": "This is an Entra Workload ID-backed Azure DevOps user Service Connection. If this is set, the input mavenServiceConnections will be ignored.",
68
"loc.input.label.artifactsFeeds": "Feeds",
79
"loc.input.label.mavenServiceConnections": "Credentials for repositories outside this organization/collection",
810
"loc.input.help.mavenServiceConnections": "Credentials to use for external repositories located in the project's pom.xml.",
911
"loc.messages.Warning_FeedEntryAlreadyExists": "The settings for the feed or repository '%s' already exists in the users settings.xml file.",
1012
"loc.messages.Warning_NoEndpointsToAuth": "No repositories were selected to authenticate, please check your task configuration.",
13+
"loc.messages.Warning_TokenNotGenerated": "Unable to use a federated token",
1114
"loc.messages.Info_GeneratingExternalRepositories": "Generating configs for %s external repositories.",
1215
"loc.messages.Info_GeneratingInternalFeeds": "Generating configs for %s internal feeds.",
1316
"loc.messages.Info_M2FolderDoesntExist": ".m2 folder not found at location %s, creating new folder.",
1417
"loc.messages.Info_SettingsXmlRead": "Adding authentication to settings file %s.",
1518
"loc.messages.Info_CreatingSettingsXml": "Creating new settings.xml at path %s.",
1619
"loc.messages.Info_WritingToSettingsXml": "Writing new settings.xml with added authentication.",
20+
"loc.messages.Info_AddingFederatedFeedAuth": "Adding auth information from federated service connection %s for feed %s",
21+
"loc.messages.Info_SuccessAddingFederatedFeedAuth": "Successfully added auth for feed %s with federated credentials.",
1722
"loc.messages.Error_InvalidServiceConnection": "The service connection for %s is invalid.",
18-
"loc.messages.Error_FailedCleanupM2": "Failed to delete credentials from the user settings.xml file: %s"
23+
"loc.messages.Error_FailedCleanupM2": "Failed to delete credentials from the user settings.xml file: %s",
24+
"loc.messages.Error_FailedToGetServiceConnectionAuth": "Unable to get federated credentials from service connection: %s."
1925
}

Tasks/MavenAuthenticateV0/Tests/L0.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ describe("authenticate azure artifacts feeds for maven", function() {
1919
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT) || 20000);
2020
var env;
2121

22-
this.beforeAll(() => {
22+
this.beforeAll(async () => {
2323
env = Object.assign({}, process.env);
2424
process.env["USERPROFILE"] = testUserHomeDir;
2525
process.env["HOME"] = testUserHomeDir;
2626
});
2727

28-
beforeEach(() => {
28+
beforeEach(async () => {
2929
tl.mkdirP(m2DirPath);
3030
})
3131

32-
this.afterAll(() => {
32+
this.afterAll(async () => {
3333
process.env = env;
3434
})
3535

36-
afterEach(() => {
36+
afterEach(async () => {
3737
tl.rmRF(m2DirPath);
3838
});
3939

40-
it("it should create a new settings.xml in the .m2 folder and add auth for 1 feed.", (done: MochaDone) => {
40+
it("it should create a new settings.xml in the .m2 folder and add auth for 1 feed.", async () => {
4141
this.timeout(1000);
4242

4343
let tp: string = path.join(__dirname, "L0AuthSettingsXml.js");
4444

4545
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
4646

47-
tr.run();
47+
await tr.runAsync();
4848

4949
assert.equal(tl.ls(null, [m2DirPath]).length, 1, "Should have one file.");
5050
const settingsXmlStats = tl.stats(settingsXmlPath);
@@ -58,11 +58,9 @@ describe("authenticate azure artifacts feeds for maven", function() {
5858

5959
assert(tr.stderr.length === 0, "should not have written to stderr");
6060
assert(tr.succeeded, "task should have succeeded");
61-
62-
done();
6361
});
6462

65-
it("it should read the existing settings.xml and add auth for 1 new feed", (done: Mocha.Done) => {
63+
it("it should read the existing settings.xml and add auth for 1 new feed", async () => {
6664
this.timeout(1000);
6765

6866
let tp: string = path.join(__dirname, "L0AuthSettingsXmlExists.js");
@@ -71,7 +69,7 @@ describe("authenticate azure artifacts feeds for maven", function() {
7169

7270
tl.cp(settingsOtherFeedName, settingsXmlPath);
7371

74-
tr.run();
72+
await tr.runAsync();
7573

7674
assert.equal(tl.ls(null, [m2DirPath]).length, 1, "Should have one file.");
7775
const settingsXmlStats = tl.stats(settingsXmlPath);
@@ -86,11 +84,9 @@ describe("authenticate azure artifacts feeds for maven", function() {
8684

8785
assert(tr.stderr.length === 0, "should not have written to stderr");
8886
assert(tr.succeeded, "task should have succeeded");
89-
90-
done();
9187
});
9288

93-
it("it should read the existing settings.xml and not add any new entries.", (done: Mocha.Done) => {
89+
it("it should read the existing settings.xml and not add any new entries.", async () => {
9490
this.timeout(1000);
9591

9692
let tp: string = path.join(__dirname, "L0AuthSettingsXmlExists.js");
@@ -99,7 +95,7 @@ describe("authenticate azure artifacts feeds for maven", function() {
9995

10096
tl.cp(settingsFeedName1, settingsXmlPath);
10197

102-
tr.run();
98+
await tr.runAsync();
10399

104100
assert.equal(tl.ls(null, [m2DirPath]).length, 1, "Should have one file.");
105101
const settingsXmlStats = tl.stats(settingsXmlPath);
@@ -112,20 +108,18 @@ describe("authenticate azure artifacts feeds for maven", function() {
112108
assert.equal(data.match(/<id>feedName1<\/id>/gi).length, 1, "Only one id entry should be present.");
113109

114110
assert(tr.stderr.length === 0, "should not have written to stderr");
115-
assert(tr.stdOutContained("vso[task.issue type=warning;]loc_mock_Warning_FeedEntryAlreadyExists"), "Entry already exists warning should be displayed");
111+
assert(tr.stdOutContained("vso[task.issue type=warning;source=TaskInternal;]loc_mock_Warning_FeedEntryAlreadyExists"), "Entry already exists warning should be displayed");
116112
assert(tr.succeeded, "task should have succeeded");
117-
118-
done();
119113
});
120114

121-
it("it should create a new settings.xml in the .m2 folder and add auth for 3 different types of service connections.", (done: Mocha.Done) => {
115+
it("it should create a new settings.xml in the .m2 folder and add auth for 3 different types of service connections.", async () => {
122116
this.timeout(1000);
123117

124118
let tp: string = path.join(__dirname, "L0ServiceConnections.js");
125119

126120
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
127121

128-
tr.run();
122+
await tr.runAsync();
129123

130124
assert.equal(tl.ls(null, [m2DirPath]).length, 1, "Should have one file.");
131125
const settingsXmlStats = tl.stats(settingsXmlPath);
@@ -151,25 +145,21 @@ describe("authenticate azure artifacts feeds for maven", function() {
151145

152146
assert(tr.stderr.length === 0, "should not have written to stderr");
153147
assert(tr.succeeded, "task should have succeeded");
154-
155-
done();
156148
});
157149

158-
it("it should warn if no inputs are provided.", (done: Mocha.Done) => {
150+
it("it should warn if no inputs are provided.", async () => {
159151
this.timeout(1000);
160152

161153
let tp: string = path.join(__dirname, "L0EmptyInput.js");
162154

163155
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
164156

165-
tr.run();
157+
await tr.runAsync();
166158

167159
assert.equal(tl.ls(null, [m2DirPath]).length, 0, "Settings.xml file should not be created.");
168160

169161
assert(tr.stderr.length === 0, "should not have written to stderr");
170162
assert(tr.succeeded, "task should have succeeded");
171-
assert(tr.stdOutContained("vso[task.issue type=warning;]loc_mock_Warning_NoEndpointsToAuth"), "No endpoints warning should be displayed");
172-
173-
done();
163+
assert(tr.stdOutContained("vso[task.issue type=warning;source=TaskInternal;]loc_mock_Warning_NoEndpointsToAuth"), "The no endpoints warning should be displayed");
174164
});
175165
});

Tasks/MavenAuthenticateV0/Tests/L0EmptyInput.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ let mockApi = {
1616
};
1717
tr.registerMock('azure-pipelines-tasks-artifacts-common/webapi', mockApi);
1818

19+
tr.setAnswers({
20+
osType: {
21+
"osType": "Windows NT"
22+
}
23+
});
24+
1925
tr.run();

0 commit comments

Comments
 (0)