Skip to content

Commit bfa2ffe

Browse files
committed
feat(net): add unit test for url checking
1 parent 02d2e9f commit bfa2ffe

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

framework/src/test/java/org/tron/core/services/filter/HttpApiAccessFilterTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import java.io.File;
55
import java.io.IOException;
66
import java.io.InputStreamReader;
7+
import java.lang.reflect.Method;
78
import java.util.ArrayList;
9+
import java.util.Collection;
810
import java.util.Collections;
911
import java.util.List;
1012
import org.apache.http.HttpResponse;
@@ -21,10 +23,13 @@
2123
import org.tron.common.application.Application;
2224
import org.tron.common.application.ApplicationFactory;
2325
import org.tron.common.application.TronApplicationContext;
26+
import org.tron.common.parameter.CommonParameter;
2427
import org.tron.common.utils.FileUtil;
28+
import org.tron.common.utils.ReflectUtils;
2529
import org.tron.core.Constant;
2630
import org.tron.core.config.DefaultConfig;
2731
import org.tron.core.config.args.Args;
32+
import org.tron.core.net.peer.PeerConnection;
2833
import org.tron.core.services.http.FullNodeHttpApiService;
2934
import org.tron.core.services.interfaceOnPBFT.http.PBFT.HttpApiOnPBFTService;
3035
import org.tron.core.services.interfaceOnSolidity.http.solidity.HttpApiOnSolidityService;
@@ -37,6 +42,7 @@ public class HttpApiAccessFilterTest {
3742
private static Application appTest;
3843
private static CloseableHttpClient httpClient = HttpClients.createDefault();
3944
private static String dbPath = "output_http_api_access_filter_test";
45+
private static HttpApiAccessFilter httpApiAccessFilter;
4046

4147
/**
4248
* init dependencies.
@@ -47,7 +53,7 @@ public static void init() {
4753
Args.getInstance().setFullNodeAllowShieldedTransactionArgs(false);
4854
context = new TronApplicationContext(DefaultConfig.class);
4955
appTest = ApplicationFactory.create(context);
50-
56+
httpApiAccessFilter = context.getBean(HttpApiAccessFilter.class);
5157
FullNodeHttpApiService httpApiService = context
5258
.getBean(FullNodeHttpApiService.class);
5359
HttpApiOnSolidityService httpApiOnSolidityService = context
@@ -153,4 +159,31 @@ private int getReuqestCode(String url) {
153159

154160
return 0;
155161
}
162+
163+
@Test
164+
public void testIsDisabled() throws Exception {
165+
List<String> list = new ArrayList<>();
166+
list.add("getnowblock");
167+
CommonParameter.getInstance().setDisabledApiList(list);
168+
Method privateMethod = httpApiAccessFilter.getClass()
169+
.getDeclaredMethod("isDisabled", String.class);
170+
privateMethod.setAccessible(true);
171+
172+
String url = "/wallet/getnowblock";
173+
boolean f = (boolean) privateMethod.invoke(httpApiAccessFilter,url);
174+
Assert.assertTrue(f);
175+
176+
url = "/wallet/a/../b/../getnowblock";
177+
f = (boolean) privateMethod.invoke(httpApiAccessFilter,url);
178+
Assert.assertTrue(f);
179+
180+
url = "/wallet/a/b/../getnowblock";
181+
f = (boolean) privateMethod.invoke(httpApiAccessFilter,url);
182+
Assert.assertTrue(!f);
183+
184+
url = "/wallet/getblock";
185+
f = (boolean) privateMethod.invoke(httpApiAccessFilter,url);
186+
Assert.assertTrue(!f);
187+
}
188+
156189
}

0 commit comments

Comments
 (0)