Skip to content

Commit

Permalink
fix FQDN machine name mapping on proxy configuration
Browse files Browse the repository at this point in the history
fix proxy configuration error display
  • Loading branch information
rjpmestre committed Oct 11, 2023
1 parent 32465f6 commit d2ffa4a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 10 deletions.
6 changes: 4 additions & 2 deletions java/code/src/com/redhat/rhn/common/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package com.redhat.rhn.common.util;

import com.redhat.rhn.common.RhnRuntimeException;

import org.apache.commons.collections.buffer.CircularFifoBuffer;
import org.apache.commons.io.LineIterator;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -145,10 +147,10 @@ public static String readStringFromFile(String path, boolean noLog) {
return contents;
}
catch (FileNotFoundException e) {
throw new RuntimeException("File not found: " + path);
throw new RhnRuntimeException("File not found: " + path);
}
catch (IOException e) {
throw new RuntimeException(e);
throw new RhnRuntimeException(e);
}
}

Expand Down
15 changes: 7 additions & 8 deletions java/code/src/com/suse/manager/ssl/SSLCertData.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
*/
package com.suse.manager.ssl;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -139,12 +140,10 @@ public int hashCode() {
* @return machine name
*/
public String getMachineName() {
List<String> dataList = Arrays.asList(this.getCn().split("\\."));
if (dataList.size() > 2) {
return String.join(".", dataList.subList(0, dataList.size() - 2));
}
else {
return String.join(".");
}
String[] hostnameParts = this.getCn().replace("*", "_star_").split("\\.");

return hostnameParts.length > 2 ?
StringUtils.join(hostnameParts, ".", 0, hostnameParts.length - 2) :
this.getCn();
}
}
79 changes: 79 additions & 0 deletions java/code/src/com/suse/manager/ssl/test/SSLCertDataTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2023 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/

package com.suse.manager.ssl.test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.suse.manager.ssl.SSLCertData;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.stream.Stream;

public class SSLCertDataTest {
private SSLCertData sslCertData;

@BeforeEach
void setUp() {
sslCertData = new SSLCertData(null, null, null, null, null, null, null, null);
}



@ParameterizedTest
@MethodSource("machineNameTestData")
void testGetMachineNameWithCustomObject(SSLCertDataTestData sslCertDataTestDataIn) {
sslCertData = new SSLCertData(sslCertDataTestDataIn.getCn(), null, null, null, null, null, null, null);

String result = sslCertData.getMachineName();
assertEquals(sslCertDataTestDataIn.getExpectedMachineName(), result);
}


/**
* Test the getMachineName method.
* As cn is mandatory, it cannot be null nor empty.
*/
private static Stream<SSLCertDataTestData> machineNameTestData() {
return Stream.of(
new SSLCertDataTestData("xxx.yyy.zzz.com", "xxx.yyy"),
new SSLCertDataTestData("yyy.zzz.com", "yyy"),
new SSLCertDataTestData("zzz.com", "zzz.com"),
new SSLCertDataTestData("xxx", "xxx"),
new SSLCertDataTestData("*.yyy.zzz.com", "_star_.yyy")
);
}

static class SSLCertDataTestData {
private final String cn;
private final String expectedMachineName;

SSLCertDataTestData(String cnIn, String expectedMachineNameIn) {
this.cn = cnIn;
this.expectedMachineName = expectedMachineNameIn;
}

String getCn() {
return cn;
}

String getExpectedMachineName() {
return expectedMachineName;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- fix FQDN machine name mapping on proxy configuration
- fix proxy configuration error display

0 comments on commit d2ffa4a

Please sign in to comment.