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:
Parry 2024-03-01 12:43:13 +08:00
parent 9704b39bf2
commit 0185e0f794
No known key found for this signature in database
GPG key ID: B9795B3F9F07BF96
5 changed files with 66 additions and 20 deletions

20
dist/setup/index.js vendored
View file

@ -122463,9 +122463,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.generate = exports.createAuthenticationSettings = exports.configureAuthentication = void 0;
const path = __importStar(__nccwpck_require__(71017));
const core = __importStar(__nccwpck_require__(42186));
const io = __importStar(__nccwpck_require__(47351));
const path = __importStar(__nccwpck_require__(71017));
const fs = __importStar(__nccwpck_require__(57147));
const os = __importStar(__nccwpck_require__(22037));
const xmlbuilder2_1 = __nccwpck_require__(70151);
@ -122507,7 +122507,19 @@ function createAuthenticationSettings(id, username, password, settingsDirectory,
}
exports.createAuthenticationSettings = createAuthenticationSettings;
// only exported for testing purposes
function escapeXml(unsafeStr) {
return unsafeStr
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
}
function generate(id, username, password, gpgPassphrase) {
const escapedUsername = escapeXml(username);
const escapedPassword = escapeXml(password);
let escapedGpgPassphrase = gpgPassphrase
? escapeXml(gpgPassphrase)
: undefined;
const xmlObj = {
settings: {
'@xmlns': 'http://maven.apache.org/SETTINGS/1.0.0',
@ -122517,8 +122529,8 @@ function generate(id, username, password, gpgPassphrase) {
server: [
{
id: id,
username: `\${env.${username}}`,
password: `\${env.${password}}`
username: escapedUsername,
password: escapedPassword
}
]
}
@ -122527,7 +122539,7 @@ function generate(id, username, password, gpgPassphrase) {
if (gpgPassphrase) {
const gpgServer = {
id: 'gpg.passphrase',
passphrase: `\${env.${gpgPassphrase}}`
passphrase: escapedGpgPassphrase
};
xmlObj.settings.servers.server.push(gpgServer);
}