Skip to content

Commit

Permalink
Changes to allow the FlintStonesIT to be able to run without special
Browse files Browse the repository at this point in the history
setup

Separates the Windows ITs from the others as these need a specific
windows machine (snowflake)
  • Loading branch information
jtnord committed Aug 6, 2024
1 parent 0116b82 commit 25b72aa
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 35 deletions.
18 changes: 1 addition & 17 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
/*buildPlugin(useContainerAgent: false, configurations: [
buildPlugin(useContainerAgent: false, configurations: [
[platform: 'linux', jdk: 21],
[platform: 'linux', jdk: 11],
[platform: 'windows', jdk: 17],
])
*/

node('docker') {
stage('checkout') {
checkout scm
}

stage('maven') {
sh 'sudo ./hack_systemd_resolve.sh'
sh 'mvn -B clean install -P onlyITs -Dtest=TheFlintstonesIT'
}

stage('surefire-report') {
junit 'target/surefire-reports/*.xml'
}
}
50 changes: 50 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,19 @@
<includes>
<include>**/*IT.java</include>
</includes>
<excludes>
<exclude>**/Windows*IT.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>ITs</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
Expand All @@ -194,13 +200,57 @@
<includes>
<include>**/*IT.java</include>
</includes>
<excludes>
<exclude>**/Windows*IT.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>onlyWindowsITs</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount> <!-- using static ports can not be parallized -->
<includes>
<include>**/Windows*IT.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>WindowsITs</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>WindowsITs</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<forkCount>1</forkCount> <!-- using static ports can not be parallized -->
<includes>
<include>**/Windows*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* This tests requires a very specific windows environment to run, the windows machine
* needs to be joined to a function domain that has the user fred with the password ia4uV1EeKait.
* It is enabled in the ITs profile, but will skip on I as that profile is enabled only on the special Linux environment.
* It is enabled in the WindowsITs profile, but will skip on I as that profile is enabled only on the special Linux environment.
*/
public class WindowsAdsiModeUserCacheDisabledIT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* This tests requires a very specific windows environment to run, the windows machine
* needs to be joined to a function domain that has the user fred with the password ia4uV1EeKait.
* It is enabled in the ITs profile, but will skip on I as that profile is enabled only on the special Linux environment.
* It is enabled in the windowsITs profile, but will skip on I as that profile is enabled only on the special Linux environment.
*/
public class WindowsAdsiModeUserCacheEnabledIT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@
package hudson.plugins.active_directory.docker;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand All @@ -47,10 +43,9 @@
import org.burningwave.tools.net.DNSClientHostResolver;
import org.burningwave.tools.net.DefaultHostResolver;
import org.burningwave.tools.net.HostResolutionRequestInterceptor;
import org.burningwave.tools.net.HostResolver;
import org.burningwave.tools.net.MappedHostResolver;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
Expand All @@ -62,10 +57,7 @@
import hudson.plugins.active_directory.GroupLookupStrategy;

/**
* Integration tests with Docker and requiring custom DNS in the target env with fixed ports.
* NOTE: these tests will fail if you have port53 (or any other port required by Samba bound locally)
* for DNS (port53 issues on linux see hack_systemd_resolve.sh or
* <a href="https://www.linuxuprising.com/2020/07/ubuntu-how-to-free-up-port-53-used-by.html">Ubuntu: How To Free Up Port 53, Used By systemd-resolved</a>}
* Integration tests with Docker and using samba as a DNS server
*/
public class TheFlintstonesIT {

Expand All @@ -78,7 +70,7 @@ public class TheFlintstonesIT {
@Rule(order = 1)
public ActiveDirectoryGenericContainer<?> docker = new ActiveDirectoryGenericContainer<>().withStaticPorts();

@Rule(order = 4) // start Jenkins after the container so that timeouts do not apply to container building.
@Rule(order = 2) // start Jenkins after the container so that timeouts do not apply to container building.
public JenkinsRule j = new JenkinsRule();

@Rule
Expand All @@ -91,27 +83,30 @@ public void overrideDNSServers() throws UnknownHostException {

// whilst the `getHost()` is supposed to return an IPAddress in some cases it will return "localhost"
// we need a resolved address to configure the resolver do a lookup before we change the DNS.

InetAddress hostInetAddr = InetAddress.getByName(docker.getHost());
String hostIP = hostInetAddr.getHostAddress();

// but additionally we need to use the locally bound ports and not what AD returns for name resolution
// but additionally we need to use the locally bound ports for the catalog and not what AD returns for name resolution
Map<String, String> hostAliases = new LinkedHashMap<>();
hostAliases.put("dc1.samdom.example.com", hostIP);
hostAliases.put("samdom.example.com", hostIP);
// this adds the A entry for the PDC, but will leave the discovery of this to the SRV lookup

HostResolutionRequestInterceptor.INSTANCE.install(
new MappedHostResolver(hostAliases),
new DNSClientHostResolver(hostIP, 553),
DefaultHostResolver.INSTANCE);

// we also need to set the JNDI default
// see hudson.plugins.active_directory.ActiveDirectoryDomain.createDNSLookupContext()
// getHost returns a hostname not IPaddress...
// use our DNS to resolve that to an IP address.
System.setProperty(DNSUtils.OVERRIDE_DNS_PROPERTY, "dns://"+hostIP+":553");
}

@After
public void restoreDNS() {
HostResolutionRequestInterceptor.INSTANCE.install(DefaultHostResolver.INSTANCE);
System.clearProperty(DNSUtils.OVERRIDE_DNS_PROPERTY);
}

public final static String AD_DOMAIN = "samdom.example.com";
Expand All @@ -128,7 +123,6 @@ public void dynamicSetUp() throws Exception {
}

public void dynamicSetUp(boolean requireTLS) throws Exception {
//dockerIp = requireTLS ? docker.getHost() : "dc1.samdom.example.com";
dockerIp = "dc1.samdom.example.com";
dockerPort = docker.getMappedPort(requireTLS ? GLOBAL_CATALOG_TLS : GLOBAL_CATALOG_PLAIN_TEXT);
ActiveDirectoryDomain activeDirectoryDomain = new ActiveDirectoryDomain(AD_DOMAIN, dockerIp + ":" + dockerPort , null, AD_MANAGER_DN, AD_MANAGER_DN_PASSWORD);
Expand Down

0 comments on commit 25b72aa

Please sign in to comment.