mirror of
https://github.com/actions/setup-java.git
synced 2025-06-29 12:34:14 +00:00
bugfix(auth): Update authentication logic in settings.xml, unit tests, and documentation examples
To resolve this, we've made significant updates to the logic within settings.xml for better handling of authentication information. Additionally, unit tests have been updated to reflect these changes and ensure robust verification. The documentation and examples have also been revised to provide clearer guidance on configuring and utilizing this updated process successfully.
This commit is contained in:
parent
9704b39bf2
commit
c6b8c532e9
5 changed files with 66 additions and 20 deletions
|
@ -1,8 +1,8 @@
|
|||
import * as io from '@actions/io';
|
||||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
import * as auth from '../src/auth';
|
||||
import {M2_DIR, MVN_SETTINGS_FILE} from '../src/constants';
|
||||
|
@ -10,6 +10,14 @@ import {M2_DIR, MVN_SETTINGS_FILE} from '../src/constants';
|
|||
const m2Dir = path.join(__dirname, M2_DIR);
|
||||
const settingsFile = path.join(m2Dir, MVN_SETTINGS_FILE);
|
||||
|
||||
// escape xml special characters
|
||||
function escapeXml(unsafeStr: string) {
|
||||
return unsafeStr
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
||||
|
||||
describe('auth tests', () => {
|
||||
let spyOSHomedir: jest.SpyInstance;
|
||||
let spyInfo: jest.SpyInstance;
|
||||
|
@ -157,14 +165,17 @@ describe('auth tests', () => {
|
|||
const username = 'USER';
|
||||
const password = '&<>"\'\'"><&';
|
||||
|
||||
process.env['username'] = username;
|
||||
process.env['password'] = 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>${id}</id>
|
||||
<username>\${env.${username}}</username>
|
||||
<password>\${env.&<>"''"><&}</password>
|
||||
<id>${escapeXml(id)}</id>
|
||||
<username>${escapeXml(username)}</username>
|
||||
<password>${escapeXml(password)}</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>`;
|
||||
|
@ -178,18 +189,22 @@ describe('auth tests', () => {
|
|||
const password = '&<>"\'\'"><&';
|
||||
const gpgPassphrase = 'PASSPHRASE';
|
||||
|
||||
process.env['username'] = username;
|
||||
process.env['password'] = password;
|
||||
process.env['gpgPassphrase'] = gpgPassphrase;
|
||||
|
||||
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>${id}</id>
|
||||
<username>\${env.${username}}</username>
|
||||
<password>\${env.&<>"''"><&}</password>
|
||||
<id>${escapeXml(id)}</id>
|
||||
<username>${escapeXml(username)}</username>
|
||||
<password>${escapeXml(password)}</password>
|
||||
</server>
|
||||
<server>
|
||||
<id>gpg.passphrase</id>
|
||||
<passphrase>\${env.${gpgPassphrase}}</passphrase>
|
||||
<passphrase>${escapeXml(gpgPassphrase)}</passphrase>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>`;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue