From 1624ff934d691017813dd6790e43347f78a53a2c Mon Sep 17 00:00:00 2001 From: seran <7030273+seran@users.noreply.github.com> Date: Wed, 4 Oct 2023 14:07:23 +0200 Subject: [PATCH] hostname infos --- .../controller/api/dto/BootTimeInfoDto.java | 5 +++ .../controller/api/dto/HostnameInfoDto.java | 30 +++++++++++++++++ .../java/instrumentation/AdditionalInfo.java | 6 ++++ .../java/instrumentation/HostnameInfo.java | 25 ++++++++++++++ .../classes/InetAddressClassReplacement.java | 33 +++++++++++-------- .../staticstate/ExecutionTracer.java | 6 ++-- .../externalservice/DomainNameAction.kt | 20 +++++++++++ .../problem/externalservice/HostnameInfo.kt | 7 ++++ .../httpws/HttpExternalServiceInfo.kt | 2 +- .../service/HttpWsExternalServiceHandler.kt | 12 ++++++- 10 files changed, 128 insertions(+), 18 deletions(-) create mode 100644 client-java/controller-api/src/main/java/org/evomaster/client/java/controller/api/dto/HostnameInfoDto.java create mode 100644 client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/HostnameInfo.java create mode 100644 core/src/main/kotlin/org/evomaster/core/problem/externalservice/DomainNameAction.kt create mode 100644 core/src/main/kotlin/org/evomaster/core/problem/externalservice/HostnameInfo.kt diff --git a/client-java/controller-api/src/main/java/org/evomaster/client/java/controller/api/dto/BootTimeInfoDto.java b/client-java/controller-api/src/main/java/org/evomaster/client/java/controller/api/dto/BootTimeInfoDto.java index 3f07e906c8..20d2b6a30f 100644 --- a/client-java/controller-api/src/main/java/org/evomaster/client/java/controller/api/dto/BootTimeInfoDto.java +++ b/client-java/controller-api/src/main/java/org/evomaster/client/java/controller/api/dto/BootTimeInfoDto.java @@ -16,4 +16,9 @@ public class BootTimeInfoDto { * Information about the external services used inside the SUT */ public List externalServicesDto; + + /** + * Collections of hostnames collected through InetAddressReplacement + */ + public List hostnameInfoDtos; } diff --git a/client-java/controller-api/src/main/java/org/evomaster/client/java/controller/api/dto/HostnameInfoDto.java b/client-java/controller-api/src/main/java/org/evomaster/client/java/controller/api/dto/HostnameInfoDto.java new file mode 100644 index 0000000000..91e172c57a --- /dev/null +++ b/client-java/controller-api/src/main/java/org/evomaster/client/java/controller/api/dto/HostnameInfoDto.java @@ -0,0 +1,30 @@ +package org.evomaster.client.java.controller.api.dto; + +import java.util.Objects; + +public class HostnameInfoDto { + + public String remoteHostname; + + public Boolean resolved; + + public HostnameInfoDto(){}; + + public HostnameInfoDto(String remoteHostname, Boolean resolved) { + this.remoteHostname = remoteHostname; + this.resolved = resolved; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + HostnameInfoDto that = (HostnameInfoDto) o; + return Objects.equals(remoteHostname, that.remoteHostname) && Objects.equals(resolved, that.resolved); + } + + @Override + public int hashCode() { + return Objects.hash(remoteHostname, resolved); + } +} diff --git a/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/AdditionalInfo.java b/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/AdditionalInfo.java index 667a6d8028..a98644203d 100644 --- a/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/AdditionalInfo.java +++ b/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/AdditionalInfo.java @@ -72,6 +72,8 @@ public StatementDescription(String line, String method) { */ private final Set externalServices = new CopyOnWriteArraySet<>(); + private final Set hostnameInfos = new CopyOnWriteArraySet<>(); + /** * info for external services which have been referred to the default setup (eg, specified ip and port) */ @@ -265,6 +267,10 @@ public void addExternalService(ExternalServiceInfo hostInfo) { externalServices.add(hostInfo); } + public void addHostnameInfo(HostnameInfo hostnameInfo) { + hostnameInfos.add(hostnameInfo); + } + public Set getExternalServices() { return Collections.unmodifiableSet(externalServices); } diff --git a/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/HostnameInfo.java b/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/HostnameInfo.java new file mode 100644 index 0000000000..24fddf9ac0 --- /dev/null +++ b/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/HostnameInfo.java @@ -0,0 +1,25 @@ +package org.evomaster.client.java.instrumentation; + +import java.io.Serializable; + +public class HostnameInfo implements Serializable { + private final String remoteHostname; + + /** + * Will be true if the hostname resolved, otherwise false; + */ + private final Boolean resolved; + + public HostnameInfo(String remoteHostname, Boolean resolved) { + this.remoteHostname = remoteHostname; + this.resolved = resolved; + } + + public String getHostname() { + return remoteHostname; + } + + public Boolean getResolved() { + return resolved; + } +} diff --git a/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/coverage/methodreplacement/classes/InetAddressClassReplacement.java b/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/coverage/methodreplacement/classes/InetAddressClassReplacement.java index fa1fe2777b..8c6054d257 100644 --- a/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/coverage/methodreplacement/classes/InetAddressClassReplacement.java +++ b/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/coverage/methodreplacement/classes/InetAddressClassReplacement.java @@ -1,11 +1,10 @@ package org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes; -import org.evomaster.client.java.instrumentation.ExternalServiceInfo; +import org.evomaster.client.java.instrumentation.HostnameInfo; import org.evomaster.client.java.instrumentation.coverage.methodreplacement.ExternalServiceInfoUtils; import org.evomaster.client.java.instrumentation.coverage.methodreplacement.MethodReplacementClass; import org.evomaster.client.java.instrumentation.coverage.methodreplacement.Replacement; import org.evomaster.client.java.instrumentation.coverage.methodreplacement.UsageFilter; -import org.evomaster.client.java.instrumentation.shared.ExternalServiceSharedUtils; import org.evomaster.client.java.instrumentation.shared.ReplacementCategory; import org.evomaster.client.java.instrumentation.shared.ReplacementType; import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer; @@ -44,12 +43,15 @@ public static InetAddress getByName(String host) throws UnknownHostException { } return InetAddress.getByName(host); } catch (UnknownHostException e) { - ExternalServiceInfo remoteHostInfo = new ExternalServiceInfo( - ExternalServiceSharedUtils.DEFAULT_SOCKET_CONNECT_PROTOCOL, - host, - -1 - ); - ExecutionTracer.addExternalServiceHost(remoteHostInfo); +// ExternalServiceInfo remoteHostInfo = new ExternalServiceInfo( +// ExternalServiceSharedUtils.DEFAULT_SOCKET_CONNECT_PROTOCOL, +// host, +// -1, +// false +// ); + HostnameInfo hostnameInfo = new HostnameInfo(host, false); +// ExecutionTracer.addExternalServiceHost(remoteHostInfo); + ExecutionTracer.addHostnameInfo(hostnameInfo); throw e; } } @@ -71,12 +73,15 @@ public static InetAddress[] getAllByName(String host) throws UnknownHostExceptio } return InetAddress.getAllByName(host); } catch (UnknownHostException e) { - ExternalServiceInfo remoteHostInfo = new ExternalServiceInfo( - ExternalServiceSharedUtils.DEFAULT_SOCKET_CONNECT_PROTOCOL, - host, - -1 - ); - ExecutionTracer.addExternalServiceHost(remoteHostInfo); +// ExternalServiceInfo remoteHostInfo = new ExternalServiceInfo( +// ExternalServiceSharedUtils.DEFAULT_SOCKET_CONNECT_PROTOCOL, +// host, +// -1, +// false +// ); + HostnameInfo hostnameInfo = new HostnameInfo(host, false); +// ExecutionTracer.addExternalServiceHost(remoteHostInfo); + ExecutionTracer.addHostnameInfo(hostnameInfo); throw e; } } diff --git a/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/staticstate/ExecutionTracer.java b/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/staticstate/ExecutionTracer.java index c27c224350..23b5579b1d 100644 --- a/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/staticstate/ExecutionTracer.java +++ b/client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/staticstate/ExecutionTracer.java @@ -8,9 +8,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CopyOnWriteArraySet; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * Methods of this class will be injected in the SUT to @@ -674,6 +672,10 @@ public static void executingBranchJump( updateBranch(className, line, branchId, t); } + public static void addHostnameInfo(HostnameInfo hostnameInfo) { + getCurrentAdditionalInfo().addHostnameInfo(hostnameInfo); + } + /** * Add the external HTTP/S hostname to the additional info to keep track. */ diff --git a/core/src/main/kotlin/org/evomaster/core/problem/externalservice/DomainNameAction.kt b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/DomainNameAction.kt new file mode 100644 index 0000000000..6910e6affb --- /dev/null +++ b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/DomainNameAction.kt @@ -0,0 +1,20 @@ +package org.evomaster.core.problem.externalservice + +import org.evomaster.core.search.EnvironmentAction +import org.evomaster.core.search.StructuralElement +import org.evomaster.core.search.gene.Gene + +class DomainNameAction : EnvironmentAction(listOf()) { + override fun getName(): String { + return "" + } + + override fun seeTopGenes(): List { + return listOf() + } + + override fun copyContent(): StructuralElement { + return DomainNameAction() + } + +} diff --git a/core/src/main/kotlin/org/evomaster/core/problem/externalservice/HostnameInfo.kt b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/HostnameInfo.kt new file mode 100644 index 0000000000..58a586fea0 --- /dev/null +++ b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/HostnameInfo.kt @@ -0,0 +1,7 @@ +package org.evomaster.core.problem.externalservice + +open class HostnameInfo ( + val remoteHostName: String, + val resolved: Boolean +) { +} diff --git a/core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/HttpExternalServiceInfo.kt b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/HttpExternalServiceInfo.kt index 250a20f985..a784e9ff5c 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/HttpExternalServiceInfo.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/HttpExternalServiceInfo.kt @@ -77,4 +77,4 @@ open class HttpExternalServiceInfo( fun toExternalService() : ExternalService { return ExternalService(remoteHostname, remotePort) } -} \ No newline at end of file +} diff --git a/core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/service/HttpWsExternalServiceHandler.kt b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/service/HttpWsExternalServiceHandler.kt index 088abf9df9..f79d059983 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/service/HttpWsExternalServiceHandler.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/httpws/service/HttpWsExternalServiceHandler.kt @@ -6,6 +6,7 @@ import org.evomaster.client.java.instrumentation.shared.ExternalServiceSharedUti import org.evomaster.core.EMConfig import org.evomaster.core.Lazy import org.evomaster.core.problem.externalservice.ExternalService +import org.evomaster.core.problem.externalservice.HostnameInfo import org.evomaster.core.problem.externalservice.httpws.* import org.evomaster.core.problem.externalservice.httpws.HttpWsExternalServiceUtils.generateRandomIPAddress import org.evomaster.core.problem.externalservice.httpws.HttpWsExternalServiceUtils.isAddressAvailable @@ -64,6 +65,9 @@ class HttpWsExternalServiceHandler { */ private val skippedExternalServices: MutableList = mutableListOf() + + private val hostnames: MutableList = mutableListOf() + /** * Contains last used loopback address for reference when creating * a new address @@ -110,6 +114,12 @@ class HttpWsExternalServiceHandler { } } + fun addHostname(hostnameInfo: HostnameInfo) { + if (config.externalServiceIPSelectionStrategy != EMConfig.ExternalServiceIPSelectionStrategy.NONE) { + hostnames.add(hostnameInfo); + } + } + private fun registerHttpExternalServiceInfo(externalServiceInfo: HttpExternalServiceInfo) { if (skippedExternalServices.contains(externalServiceInfo.toExternalService())) { return @@ -321,4 +331,4 @@ class HttpWsExternalServiceHandler { return output } -} \ No newline at end of file +}