#279 adding auth details for proxy

This commit is contained in:
Géza Molnár
2024-08-03 17:04:50 +02:00
committed by Slawomir Jaranowski
parent 45ea8e67c7
commit 06520eb502
3 changed files with 31 additions and 3 deletions

View File

@ -106,8 +106,9 @@ steps:
step:
- uses: s4u/maven-settings-action@v3.0.0
with:
proxies: '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost"}]'
proxies: '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost", "user": "proxUser", "password": "proxPassword"}]'
```
Note: Authentication details are optional.
## ```settings.xml``` with properties
```yml

View File

@ -213,10 +213,10 @@ function fillProxies(template) {
return;
}
JSON.parse(proxies).forEach((proxy) => fillProxy(template, proxy.id, proxy.active, proxy.protocol, proxy.host, proxy.port, proxy.nonProxyHosts));
JSON.parse(proxies).forEach((proxy) => fillProxy(template, proxy.id, proxy.active, proxy.protocol, proxy.host, proxy.port, proxy.nonProxyHosts, proxy.user, proxy.password));
}
function fillProxy(template, id, active, protocol, host, port, nonProxyHosts) {
function fillProxy(template, id, active, protocol, host, port, nonProxyHosts, proxyUser, proxyPassword) {
if(!id || !active || !protocol || !host || !port || !nonProxyHosts) {
core.setFailed('proxies must contain id, active, protocol, host, port and nonProxyHosts');
return;
@ -230,6 +230,13 @@ function fillProxy(template, id, active, protocol, host, port, nonProxyHosts) {
proxyXml.getElementsByTagName("port")[0].textContent = port;
proxyXml.getElementsByTagName("nonProxyHosts")[0].textContent = nonProxyHosts;
if(proxyUser) {
jsonToXml(proxyXml, proxyXml.documentElement, {username: proxyUser});
}
if(proxyPassword) {
jsonToXml(proxyXml, proxyXml.documentElement, {password: proxyPassword});
}
const proxiesXml = template.getElementsByTagName('proxies')[0];
proxiesXml.appendChild(proxyXml);
}

View File

@ -466,6 +466,26 @@ test("fillProxies one proxy", () => {
})
test("fillProxies one proxy with auth info", () => {
const xml = stringAsXml("<proxies/>");
process.env['INPUT_PROXIES'] = `[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol",
"host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost", "user": "proxyUser", "password": "somepassword"}]`;
settings.fillProxies(xml);
const xmlStr = new XMLSerializer().serializeToString(xml);
expect(xmlStr).toBe(`<proxies><proxy>
<id>proxyId</id>
<active>isActive</active>
<protocol>proxyProtocol</protocol>
<host>proxyHost</host>
<port>proxyPort</port>
<nonProxyHosts>nonProxyHost</nonProxyHosts>
<username>proxyUser</username><password>somepassword</password></proxy></proxies>`)
})
test("fillProxies two proxies", () => {
const xml = stringAsXml("<proxies/>");