44import java .io .File ;
55import java .io .IOException ;
66import java .io .InputStreamReader ;
7+ import java .lang .reflect .Method ;
78import java .util .ArrayList ;
9+ import java .util .Collection ;
810import java .util .Collections ;
911import java .util .List ;
1012import org .apache .http .HttpResponse ;
2123import org .tron .common .application .Application ;
2224import org .tron .common .application .ApplicationFactory ;
2325import org .tron .common .application .TronApplicationContext ;
26+ import org .tron .common .parameter .CommonParameter ;
2427import org .tron .common .utils .FileUtil ;
28+ import org .tron .common .utils .ReflectUtils ;
2529import org .tron .core .Constant ;
2630import org .tron .core .config .DefaultConfig ;
2731import org .tron .core .config .args .Args ;
32+ import org .tron .core .net .peer .PeerConnection ;
2833import org .tron .core .services .http .FullNodeHttpApiService ;
2934import org .tron .core .services .interfaceOnPBFT .http .PBFT .HttpApiOnPBFTService ;
3035import 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