forked from eclipse-hono/hono
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse-hono#3183] Only run SNI ITs if DNS rebinding for nip.io is s…
…upported The integration tests verifying SNI based client authentication are now run only if DNS rebinding for the nip.io domain works in the local environment. Fixes eclipse-hono#3183 Signed-off-by: Kai Hudalla <kai.hudalla@bosch.io>
- Loading branch information
1 parent
abbe56e
commit 8f3363f
Showing
7 changed files
with
137 additions
and
20 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
tests/src/test/java/org/eclipse/hono/tests/EnabledIfDnsRebindingIsSupported.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.hono.tests; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
/** | ||
* An annotation which configures a test to run only if DNS rebinding for the nip.io domain works in the | ||
* local environment. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ExtendWith(EnabledIfDnsRebindingIsSupportedCondition.class) | ||
public @interface EnabledIfDnsRebindingIsSupported { | ||
} |
65 changes: 65 additions & 0 deletions
65
tests/src/test/java/org/eclipse/hono/tests/EnabledIfDnsRebindingIsSupportedCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
|
||
package org.eclipse.hono.tests; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
import org.junit.jupiter.api.extension.ExecutionCondition; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
|
||
/** | ||
* A condition that checks if DNS rebinding works for the {@code .nip.io} domain on the local environment. | ||
* <p> | ||
* This makes sure that a look up of a host name like {@code 127.0.0.1.nip.io} is successfully resolved to IPv4 | ||
* address {@code 127.0.0.1}. | ||
*/ | ||
public class EnabledIfDnsRebindingIsSupportedCondition implements ExecutionCondition { | ||
|
||
private static final String MUTEX = "mutex"; | ||
private static ConditionEvaluationResult result; | ||
|
||
/** | ||
* Checks if {@code 127.0.0.1.nip.io} can be resolved to {@code 127.0.0.1}. | ||
* | ||
* @param context The context to evaluate in. | ||
*/ | ||
@Override | ||
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) { | ||
synchronized (MUTEX) { | ||
if (result == null) { | ||
performLookup(); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
private void performLookup() { | ||
try { | ||
final var address = InetAddress.getByName("127.0.0.1.nip.io"); | ||
if (address.isLoopbackAddress()) { | ||
result = ConditionEvaluationResult.enabled("lookup of 127.0.0.1.nip.io succeeded"); | ||
} else { | ||
result = ConditionEvaluationResult.disabled("lookup of 127.0.0.1.nip.io yielded non-loopback address: {}" | ||
.formatted(address.getHostAddress())); | ||
} | ||
} catch (final UnknownHostException e) { | ||
// DNS rebinding protection seems to be in place | ||
result = ConditionEvaluationResult.disabled("DNS rebinding protection prevents resolving 127.0.0.1.nip.io"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters