fix: национальные домены

This commit is contained in:
2025-07-23 14:48:57 +03:00
parent 22b4846ef9
commit 009d5fff10
6 changed files with 37 additions and 14 deletions

View File

@@ -32,7 +32,6 @@ dependencies {
compileOnly("org.projectlombok:lombok:$lombokVersion")
implementation("org.apache.httpcomponents.client5:httpclient5:5.5")
implementation("org.apache.commons:commons-lang3:3.18.0")
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation("org.jsoup:jsoup:1.21.1")

View File

@@ -0,0 +1,8 @@
package ru.di9.ihc;
public record Domain(
int id,
String name,
String punycode
) {
}

View File

@@ -1,7 +1,6 @@
package ru.di9.ihc;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
@@ -16,7 +15,10 @@ import org.jsoup.select.Elements;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class IhcClient {
private final String baseUrl;
@@ -59,7 +61,7 @@ public class IhcClient {
return isAuth;
}
public List<Pair<String, Integer>> getDomains() {
public List<Domain> getDomains() {
if (!isAuth) {
throw new RuntimeException("IS NOT AUTH");
}
@@ -73,13 +75,19 @@ public class IhcClient {
return Collections.emptyList();
}
List<Pair<String, Integer>> list = new ArrayList<>();
List<Domain> list = new ArrayList<>();
Document document = Jsoup.parse(resp.getEntity().getContent(), StandardCharsets.UTF_8.name(), baseUrl);
Elements elements = document.select("li[class='zoneList__zone'] a");
for (Element element : elements) {
Integer id = Integer.valueOf(element.attr("href").substring(1).split("/")[2]);
String domain = element.text();
list.add(Pair.of(domain, id));
int id = Integer.parseInt(element.attr("href").substring(1).split("/")[2]);
String name = element.text();
String punycode = null;
if (name.contains(" (")) {
String[] split = name.split(" \\(", 2);
name = split[0];
punycode = split[1].substring(0, split[1].length() - 1);
}
list.add(new Domain(id, name, punycode));
}
return list;

View File

@@ -51,7 +51,7 @@ class GetDomainRecordsTest {
var ihc = new IhcClient("http://localhost:%d".formatted(port));
ihc.auth("user1", "passwd1");
Integer domainId = ihc.getDomains().getFirst().getValue();
int domainId = ihc.getDomains().getFirst().id();
List<DomainRecord> domainRecords = ihc.getDomainRecords(domainId);
assertEquals(7, domainRecords.size());

View File

@@ -4,7 +4,6 @@ import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -50,10 +49,11 @@ class GetDomainsTest {
var ihc = new IhcClient("http://localhost:%d".formatted(port));
ihc.auth("user1", "passwd1");
List<Pair<String, Integer>> domains = ihc.getDomains();
List<Domain> domains = ihc.getDomains();
assertEquals(2, domains.size());
assertEquals(Pair.of("example-1.ru", 111111), domains.get(0));
assertEquals(Pair.of("example-2.ru", 222222), domains.get(1));
assertEquals(3, domains.size());
assertEquals(new Domain(111111, "example-1.ru", null), domains.get(0));
assertEquals(new Domain(222222, "example-2.ru", null), domains.get(1));
assertEquals(new Domain(333333, "пример-3.рф", "xn---3-mlcluqhd.xn--p1ai"), domains.get(2));
}
}

View File

@@ -570,6 +570,14 @@
<a href="/dnsZone/index/222222">example-2.ru</a>
</label>
</li>
<li class="zoneList__zone ">
<label for="zoneId333333" class="checkbox zoneList__zoneName">
<input type="checkbox" name="ids" id="zoneId333333" value="333333" style="margin-top: 1px"
class="checkbox zoneList__checkBox" />
<a href="/dnsZone/index/333333">пример-3.рф (xn---3-mlcluqhd.xn--p1ai)</a>
</label>
</li>
</form>