Skip to content

Commit

Permalink
Fixes actions#85. Add support for multiple server ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
drewctaylorgtri committed Aug 1, 2020
1 parent 1253a7e commit 2a3b137
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 5,082 deletions.
161 changes: 151 additions & 10 deletions __tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ describe('auth tests', () => {
process.env[`INPUT_SETTINGS-PATH`] = altHome;
await io.rmRF(altHome); // ensure it doesn't already exist

await auth.configAuthentication(id, username, password);
await auth.configAuthentication([id], username, password);

expect(fs.existsSync(m2Dir)).toBe(false);
expect(fs.existsSync(settingsFile)).toBe(false);

expect(fs.existsSync(altHome)).toBe(true);
expect(fs.existsSync(altSettingsFile)).toBe(true);
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
auth.generate([id], username, password)
);

delete process.env[`INPUT_SETTINGS-PATH`];
Expand All @@ -58,12 +58,27 @@ describe('auth tests', () => {
const username = 'UNAME';
const password = 'TOKEN';

await auth.configAuthentication(id, username, password);
await auth.configAuthentication([id], username, password);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
auth.generate([id], username, password)
);
}, 100000);

it('creates settings.xml with minimal configuration and multiple servers', async () => {
const id1 = 'packages-1';
const id2 = 'packages-2';
const username = 'UNAME';
const password = 'TOKEN';

await auth.configAuthentication([id1, id2], username, password);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate([id1, id2], username, password)
);
}, 100000);

Expand All @@ -73,12 +88,33 @@ describe('auth tests', () => {
const password = 'TOKEN';
const gpgPassphrase = 'GPG';

await auth.configAuthentication(id, username, password, gpgPassphrase);
await auth.configAuthentication([id], username, password, gpgPassphrase);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password, gpgPassphrase)
auth.generate([id], username, password, gpgPassphrase)
);
}, 100000);

it('creates settings.xml with additional configuration and multiple servers', async () => {
const id1 = 'packages-1';
const id2 = 'packages-2';
const username = 'UNAME';
const password = 'TOKEN';
const gpgPassphrase = 'GPG';

await auth.configAuthentication(
[id1, id2],
username,
password,
gpgPassphrase
);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate([id1, id2], username, password, gpgPassphrase)
);
}, 100000);

Expand All @@ -92,12 +128,12 @@ describe('auth tests', () => {
expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);

await auth.configAuthentication(id, username, password);
await auth.configAuthentication([id], username, password);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
auth.generate([id], username, password)
);
}, 100000);

Expand All @@ -118,7 +154,35 @@ describe('auth tests', () => {
</servers>
</settings>`;

expect(auth.generate(id, username, password)).toEqual(expectedSettings);
expect(auth.generate([id], username, password)).toEqual(expectedSettings);
});

it('generates valid settings.xml with minimal configuration and multiple servers', () => {
const id1 = 'packages-1';
const id2 = 'packages-2';
const username = 'USER';
const password = '&<>"\'\'"><&';

const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>${id1}</id>
<username>\${env.${username}}</username>
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;}</password>
</server>
<server>
<id>${id2}</id>
<username>\${env.${username}}</username>
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;}</password>
</server>
</servers>
</settings>`;

expect(auth.generate([id1, id2], username, password)).toEqual(
expectedSettings
);
});

it('generates valid settings.xml with additional configuration', () => {
Expand All @@ -143,8 +207,85 @@ describe('auth tests', () => {
</servers>
</settings>`;

expect(auth.generate(id, username, password, gpgPassphrase)).toEqual(
expect(auth.generate([id], username, password, gpgPassphrase)).toEqual(
expectedSettings
);
});

it('generates valid settings.xml with additional configuration and multiple servers', () => {
const id1 = 'packages-1';
const id2 = 'packages-2';
const username = 'USER';
const password = '&<>"\'\'"><&';
const gpgPassphrase = 'PASSPHRASE';

const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>${id1}</id>
<username>\${env.${username}}</username>
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;}</password>
</server>
<server>
<id>${id2}</id>
<username>\${env.${username}}</username>
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;}</password>
</server>
<server>
<id>gpg.passphrase</id>
<passphrase>\${env.${gpgPassphrase}}</passphrase>
</server>
</servers>
</settings>`;

expect(
auth.generate([id1, id2], username, password, gpgPassphrase)
).toEqual(expectedSettings);
});

it('generates valid settings.xml with additional configuration and multiple servers, sorting alphabetically and removing duplicates', () => {
const id1 = 'packages-1';
const id2 = 'packages-2';
const id3 = 'packages-3';
const username = 'USER';
const password = '&<>"\'\'"><&';
const gpgPassphrase = 'PASSPHRASE';

const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>${id1}</id>
<username>\${env.${username}}</username>
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;}</password>
</server>
<server>
<id>${id2}</id>
<username>\${env.${username}}</username>
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;}</password>
</server>
<server>
<id>${id3}</id>
<username>\${env.${username}}</username>
<password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;}</password>
</server>
<server>
<id>gpg.passphrase</id>
<passphrase>\${env.${gpgPassphrase}}</passphrase>
</server>
</servers>
</settings>`;

expect(
auth.generate(
[id3, id3, id1, id2, id1, id2, id3],
username,
password,
gpgPassphrase
)
).toEqual(expectedSettings);
});
});
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
file. Default is `github`'
required: false
default: 'github'
server-id-list:
description: 'IDs of the repositories in the pom.xml file. Default is `github`'
required: false
default: 'github'
server-username:
description: 'Environment variable name for the username for authentication
to the Apache Maven repository. Default is $GITHUB_ACTOR'
Expand Down
1 change: 1 addition & 0 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ exports.INPUT_ARCHITECTURE = 'architecture';
exports.INPUT_JAVA_PACKAGE = 'java-package';
exports.INPUT_JDK_FILE = 'jdkFile';
exports.INPUT_SERVER_ID = 'server-id';
exports.INPUT_SERVER_ID_LIST = 'server-id-list';
exports.INPUT_SERVER_USERNAME = 'server-username';
exports.INPUT_SERVER_PASSWORD = 'server-password';
exports.INPUT_SETTINGS_PATH = 'settings-path';
Expand Down
Loading

0 comments on commit 2a3b137

Please sign in to comment.