mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 18:06:45 +00:00
bugfix(auth): Update authentication logic in settings.xml, unit tests, and documentation examples
To address this issue, we've implemented substantial enhancements to the logic within settings.xml to improve the management of authentication data. Furthermore, we've updated the unit tests to align with these modifications, guaranteeing thorough validation. The documentation and examples have been meticulously revised to offer more straightforward instructions on how to effectively configure and employ this updated methodology.
This commit is contained in:
parent
9704b39bf2
commit
0185e0f794
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