4
4
import java .io .File ;
5
5
import java .io .IOException ;
6
6
import java .io .InputStreamReader ;
7
+ import java .lang .reflect .Method ;
7
8
import java .util .ArrayList ;
9
+ import java .util .Collection ;
8
10
import java .util .Collections ;
9
11
import java .util .List ;
10
12
import org .apache .http .HttpResponse ;
21
23
import org .tron .common .application .Application ;
22
24
import org .tron .common .application .ApplicationFactory ;
23
25
import org .tron .common .application .TronApplicationContext ;
26
+ import org .tron .common .parameter .CommonParameter ;
24
27
import org .tron .common .utils .FileUtil ;
28
+ import org .tron .common .utils .ReflectUtils ;
25
29
import org .tron .core .Constant ;
26
30
import org .tron .core .config .DefaultConfig ;
27
31
import org .tron .core .config .args .Args ;
32
+ import org .tron .core .net .peer .PeerConnection ;
28
33
import org .tron .core .services .http .FullNodeHttpApiService ;
29
34
import org .tron .core .services .interfaceOnPBFT .http .PBFT .HttpApiOnPBFTService ;
30
35
import org .tron .core .services .interfaceOnSolidity .http .solidity .HttpApiOnSolidityService ;
@@ -37,6 +42,7 @@ public class HttpApiAccessFilterTest {
37
42
private static Application appTest ;
38
43
private static CloseableHttpClient httpClient = HttpClients .createDefault ();
39
44
private static String dbPath = "output_http_api_access_filter_test" ;
45
+ private static HttpApiAccessFilter httpApiAccessFilter ;
40
46
41
47
/**
42
48
* init dependencies.
@@ -47,7 +53,7 @@ public static void init() {
47
53
Args .getInstance ().setFullNodeAllowShieldedTransactionArgs (false );
48
54
context = new TronApplicationContext (DefaultConfig .class );
49
55
appTest = ApplicationFactory .create (context );
50
-
56
+ httpApiAccessFilter = context . getBean ( HttpApiAccessFilter . class );
51
57
FullNodeHttpApiService httpApiService = context
52
58
.getBean (FullNodeHttpApiService .class );
53
59
HttpApiOnSolidityService httpApiOnSolidityService = context
@@ -153,4 +159,31 @@ private int getReuqestCode(String url) {
153
159
154
160
return 0 ;
155
161
}
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
+
156
189
}
0 commit comments