@@ -146,24 +146,31 @@ public void checkToleranceTest3() {
146146 public void verifyToleranceTest () {
147147 String requestBody = "{\" accountId\" :\" AC1334ffb694cd8d969f51cddf5f7c9b478546d50c\" ,\" callId\" :\" CAccb0b00506553cda09b51c5477f672a49e0b2213\" ,\" callStatus\" :\" ringing\" ,\" conferenceId\" :null,\" direction\" :\" inbound\" ,\" from\" :\" +13121000109\" ,\" parentCallId\" :null,\" queueId\" :null,\" requestType\" :\" inboundCall\" ,\" to\" :\" +13121000096\" }" ;
148148 String signingSecret = "sigsec_ead6d3b6904196c60835d039e91b3341c77a7793" ;
149- String requestHeader = "t=1900871395,v1=1d798c86e977ff734dec3a8b8d67fe8621dcc1df46ef4212e0bfe2e122b01bfd,v1=1ba18712726898fbbe48cd862dd096a709f7ad761a5bab14bda9ac24d963a6a8" ;
150- Integer tolerance = 5 * 60 ;
151149 Integer currentTime = (int ) (System .currentTimeMillis () / 1000L );
150+ Integer timeCalcuation = currentTime - (6 * 60 );
151+ String requestHeader = "t=" + timeCalcuation .toString ()
152+ + ",v1=1d798c86e977ff734dec3a8b8d67fe8621dcc1df46ef4212e0bfe2e122b01bfd,v1=1ba18712726898fbbe48cd862dd096a709f7ad761a5bab14bda9ac24d963a6a8" ;
153+ Integer tolerance = 5 * 60 ;
154+
152155 RuntimeException exception = assertThrows (
153156 RuntimeException .class ,
154157 () -> {
155158 RequestVerifier .verifyRequestSignature (requestBody , requestHeader , signingSecret , tolerance );
156159 });
157160
158- assertEquals ("Request time exceeded tolerance threshold. Request: 1900871395, CurrentTime: "
159- + Integer .toString (currentTime ) + ", tolerance: " + tolerance , exception .getMessage ());
161+ assertEquals (
162+ "Request time exceeded tolerance threshold. Request: " + timeCalcuation .toString () + ", CurrentTime: "
163+ + Integer .toString (currentTime ) + ", tolerance: " + tolerance ,
164+ exception .getMessage ());
160165 }
161166
162167 @ Test
163168 public void verifySignatureTest () {
164169 String requestBody = "{\" accountId\" :\" AC1334ffb694cd8d969f51cddf5f7c9b478546d50c\" ,\" callId\" :\" CAccb0b00506553cda09b51c5477f672a49e0b2213\" ,\" callStatus\" :\" ringing\" ,\" conferenceId\" :null,\" direction\" :\" inbound\" ,\" from\" :\" +13121000109\" ,\" parentCallId\" :null,\" queueId\" :null,\" requestType\" :\" inboundCall\" ,\" to\" :\" +13121000096\" }" ;
165170 String signingSecret = "sigsec_ead6d3b6904196c60835d039e91b3341c77a7794" ;
166- String requestHeader = "t=1679944186,v1=1d798c86e977ff734dec3a8b8d67fe8621dcc1df46ef4212e0bfe2e122b01bfd,v1=1ba18712726898fbbe48cd862dd096a709f7ad761a5bab14bda9ac24d963a6a8" ;
171+ Integer currentTime = (int ) (System .currentTimeMillis () / 1000L );
172+ String requestHeader = "t=" + currentTime .toString ()
173+ + ",v1=1d798c86e977ff734dec3a8b8d67fe8621dcc1df46ef4212e0bfe2e122b01bfd,v1=1ba18712726898fbbe48cd862dd096a709f7ad761a5bab14bda9ac24d963a6a8" ;
167174 Integer tolerance = 5 * 60 ;
168175 RuntimeException exception = assertThrows (
169176 RuntimeException .class ,
@@ -180,7 +187,7 @@ public void verifySignatureTest() {
180187 public void verifyRequestSignatureTest () throws NoSuchAlgorithmException , InvalidKeyException {
181188 String requestBody = "{\" accountId\" :\" AC1334ffb694cd8d969f51cddf5f7c9b478546d50c\" ,\" callId\" :\" CAccb0b00506553cda09b51c5477f672a49e0b2213\" ,\" callStatus\" :\" ringing\" ,\" conferenceId\" :null,\" direction\" :\" inbound\" ,\" from\" :\" +13121000109\" ,\" parentCallId\" :null,\" queueId\" :null,\" requestType\" :\" inboundCall\" ,\" to\" :\" +13121000096\" }" ;
182189 String signingSecret = "sigsec_ead6d3b6904196c60835d039e91b3341c77a7793" ;
183- String requestHeader = "t=1679944186 ,v1=c3957749baf61df4b1506802579cc69a74c77a1ae21447b930e5a704f9ec4120,v1=1ba18712726898fbbe48cd862dd096a709f7ad761a5bab14bda9ac24d963a6a8 " ;
190+ String requestHeader = "t=2130000000 ,v1=c3957749baf61df4b1506802579cc69a74c77a1ae21447b930e5a704f9ec4120,v1=6835006e70c9b9f610e8fb3a8b36b52b3f28c12d0a2dab75091c46ca7ec11b20 " ;
184191 Integer tolerance = 5 * 60 ;
185192 RequestVerifier .verifyRequestSignature (requestBody , requestHeader , signingSecret , tolerance );
186193 }
0 commit comments