允许内网回调
This commit is contained in:
1 parent
d910c1afe8
commit
cfb6a9e389
6 files changed
+173
-12
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package com.ruoyi.system.rental;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/** 诊断不能只留下笼统失败,也不得依赖可能包含凭证的异常原文。 */
|
||||
public class RentalWebhookDiagnosticsTest {
|
||||
@Test
|
||||
public void privateTargetIsRejectedBeforeConnectionAndClassified() throws Exception {
|
||||
try {
|
||||
RentalHttp.callbackClient().dns().lookup("192.168.3.103");
|
||||
fail("内网目标必须被现有回调策略拒绝");
|
||||
} catch (RentalHttp.CallbackTargetRejectedException ex) {
|
||||
assertEquals("TARGET_NOT_PUBLIC", RentalWorkers.callbackFailure(ex, "HTTP_EXECUTE"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledPrivateCallbacksAllowBusinessNetworksButKeepSpecialAddressesBlocked() throws Exception {
|
||||
okhttp3.OkHttpClient client = RentalHttp.callbackClient(true);
|
||||
for (String host : new String[] {"192.168.3.103", "10.0.0.1", "172.16.0.1", "fd00::1"}) {
|
||||
assertFalse(client.dns().lookup(host).isEmpty());
|
||||
}
|
||||
for (String host : new String[] {"127.0.0.1", "::1", "169.254.169.254", "0.0.0.0", "224.0.0.1"}) {
|
||||
try {
|
||||
client.dns().lookup(host);
|
||||
fail("特殊用途目标仍应拒绝:" + host);
|
||||
} catch (RentalHttp.CallbackTargetRejectedException expected) {
|
||||
// 开启内网只扩大业务私网范围,不关闭所有地址检查。
|
||||
}
|
||||
}
|
||||
assertFalse(client.followRedirects());
|
||||
assertFalse(client.followSslRedirects());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void networkAndCredentialErrorsHaveSafeDistinctReasons() {
|
||||
assertEquals("TLS_CERTIFICATE_OR_HANDSHAKE_FAILED", RentalWorkers.callbackFailure(
|
||||
new javax.net.ssl.SSLHandshakeException("secret must not appear"), "HTTP_EXECUTE"));
|
||||
assertEquals("DNS_RESOLUTION_FAILED", RentalWorkers.callbackFailure(
|
||||
new java.net.UnknownHostException("secret must not appear"), "HTTP_EXECUTE"));
|
||||
assertEquals("TIMEOUT_OR_INTERRUPTED", RentalWorkers.callbackFailure(
|
||||
new java.net.SocketTimeoutException("secret must not appear"), "HTTP_EXECUTE"));
|
||||
assertEquals("NO_VALID_CREDENTIAL_OR_LOOKUP_FAILED", RentalWorkers.callbackFailure(
|
||||
new IllegalArgumentException("secret must not appear"), "CREDENTIAL_LOOKUP"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user