forked from mosip/mosip-functional-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminTestUtil.java
More file actions
7249 lines (6308 loc) · 290 KB
/
Copy pathAdminTestUtil.java
File metadata and controls
7249 lines (6308 loc) · 290 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package io.mosip.testrig.apirig.utils;
import static io.restassured.RestAssured.given;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore.PrivateKeyEntry;
import java.security.KeyStoreException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.UnrecoverableEntryException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPublicKey;
import java.text.SimpleDateFormat;
import java.time.Clock;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Base64.Encoder;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
//import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Random;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.ws.rs.core.MediaType;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemReader;
import org.jose4j.jws.JsonWebSignature;
import org.jose4j.lang.JoseException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.SkipException;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import com.auth0.jwt.JWT;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.jknack.handlebars.Context;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.itextpdf.text.pdf.PdfReader;
import com.mifmif.common.regex.Generex;
import com.nimbusds.jose.jwk.KeyUse;
import com.nimbusds.jose.jwk.RSAKey;
import com.nimbusds.jose.util.StandardCharset;
import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;
import io.jsonwebtoken.JwtException;
import io.mosip.kernel.core.util.HMACUtils2;
import io.mosip.testrig.apirig.dataprovider.BiometricDataProvider;
import io.mosip.testrig.apirig.dbaccess.DBManager;
import io.mosip.testrig.apirig.dto.OutputValidationDto;
import io.mosip.testrig.apirig.dto.TestCaseDTO;
import io.mosip.testrig.apirig.testrunner.BaseTestCase;
import io.mosip.testrig.apirig.testrunner.JsonPrecondtion;
import io.mosip.testrig.apirig.testrunner.MessagePrecondtion;
import io.mosip.testrig.apirig.testrunner.OTPListener;
//import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
/**
* @author Ravi Kant
* @author Sohan
*
*/
public class AdminTestUtil extends BaseTestCase {
private static final Logger logger = Logger.getLogger(AdminTestUtil.class);
protected static Properties properties = null;
protected static Properties propsMap = null;
protected static Properties propsBio = null;
public static String propsHealthCheckURL = getGlobalResourcePath() + "/" + "config/healthCheckEndpoint.properties";
private static String serverComponentsCommitDetails;
public static boolean foundHandlesInIdSchema = false;
public static JSONArray globalRequiredFields = null;
protected static String token = null;
String idToken = null;
public static String PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION = null;
public static String PASSWORD_TO_RESET = null;
public static final String RESOURCE_FOLDER_NAME = "MosipTemporaryTestResource";
protected static String genertedUIN = null;
protected static String generatedRid = null;
protected static String policygroupId = null;
protected static String mispPolicyGroupId = null;
protected static String policyId = null;
protected static String mispPolicyId = null;
protected static String regDeviceResponse = null;
protected static String generatedVID = null;
public String RANDOM_ID = "mosip" + generateRandomNumberString(2) + Calendar.getInstance().getTimeInMillis();
public final String RANDOM_ID_2 = "mosip" + generateRandomNumberString(2)
+ Calendar.getInstance().getTimeInMillis();
public static final String RANDOM_ID_V2 = "mosip" + generateRandomNumberString(2)
+ Calendar.getInstance().getTimeInMillis();
public static final String RANDOM_ID_V2_S2 = "mosip" + generateRandomNumberString(2)
+ Calendar.getInstance().getTimeInMillis();
public static final String RANDOM_ID_V2_S3 = "mosip" + generateRandomNumberString(2)
+ Calendar.getInstance().getTimeInMillis();
public static final String TRANSACTION_ID = generateRandomNumberString(10);
public static final String AUTHORIZATHION_HEADERNAME = GlobalConstants.AUTHORIZATION;
public static final String AUTH_HEADER_VALUE = "Some String";
public static final String SIGNATURE_HEADERNAME = GlobalConstants.SIGNATURE;
public static String updatedPolicyId = "";
public static String currentLanguage;
protected static String idField = null;
protected static String identityHbs = null;
protected static String updateIdentityHbs = null;
protected static String draftHbs = null;
protected static String preregHbsForCreate = null;
protected static String preregHbsForUpdate = null;
protected static String timeStamp = String.valueOf(Calendar.getInstance().getTimeInMillis());
protected static String policyGroup = "mosip auth policy group " + BaseTestCase.runContext + timeStamp;
protected static String mispPolicyGroup = "mosip misp policy group " + timeStamp;
protected static String policyGroupForUpdate = "mosip auth policy group update " + timeStamp;
protected static String policyGroup2 = "mosip auth policy group2 " + timeStamp;
protected static String policyName = "mosip auth policy " + timeStamp;
protected static String mispPolicyName = "mosip misp policy " + timeStamp;
protected static String policyName2 = "mosip auth policy2 " + timeStamp;
protected static String policyNameForUpdate = "mosip auth policy for update " + timeStamp;
protected static final String preRegUser = "Prereg_" + BaseTestCase.runContext +"@mosip.net";
protected static final String UPDATE_UIN_REQUEST = "config/Authorization/requestIdentity.json";
protected static final String AUTH_INTERNAL_REQUEST = "config/Authorization/internalAuthRequest.json";
protected static final String AUTH_POLICY_BODY = "config/AuthPolicy.json";
protected static final String AUTH_POLICY_REQUEST = "config/AuthPolicy3.json";
protected static final String AUTH_POLICY_REQUEST_ATTR = "config/AuthPolicy2.json";
protected static final String MISP_POLICY_REQUEST_ATTR = "config/mispPolicy.json";
protected static final String AUTH_POLICY_BODY1 = "config/AuthPolicy4.json";
protected static final String AUTH_POLICY_REQUEST1 = "config/AuthPolicy5.json";
protected static final String AUTH_POLICY_REQUEST_ATTR1 = "config/AuthPolicy6.json";
protected static final String POLICY_GROUP_REQUEST = "config/policyGroup.json";
protected static Map<String, String> keycloakRolesMap = new HashMap<>();
protected static Map<String, String> keycloakUsersMap = new HashMap<>();
public static final String XSRF_HEADERNAME = "X-XSRF-TOKEN";
public static final String OAUTH_HASH_HEADERNAME = "oauth-details-hash";
public static final String OAUTH_TRANSID_HEADERNAME = "oauth-details-key";
protected static String encryptedSessionKeyString;
protected static final String ESIGNETUINCOOKIESRESPONSE = "ESignetUINCookiesResponse";
protected static final String ESIGNETVIDCOOKIESRESPONSE = "ESignetVIDCookiesResponse";
private static final String UIN_CODE_VERIFIER_POS_1 = generateRandomAlphaNumericString(GlobalConstants.INTEGER_36);
/** The Constant SIGN_ALGO. */
private static final String SIGN_ALGO = "RS256";
public static final int OTP_CHECK_INTERVAL = 10000;
protected static final Map<String, String> actuatorValueCache = new HashMap<>();
public static final Map<String, String> autoGeneratedIDValueCache = new HashMap<>();
public static Map<String, List<String>> generators = new HashMap<>();
public static Map<String, List<String>> consumers = new HashMap<>();
public static Map<String, List<String>> globalConsumersList = new HashMap<>();
public static String currentTestCaseName = null;
public static boolean generateDependency = true;
public static void init() {
properties = getproperty(getGlobalResourcePath() + "/" + "config/application.properties");
propsMap = getproperty(getGlobalResourcePath() + "/" + "config/valueMapping.properties");
propsBio = getproperty(getGlobalResourcePath() + "/" + "config/bioValue.properties");
PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION = properties.getProperty("passwordForAddIdentity");
PASSWORD_TO_RESET = properties.getProperty("passwordToReset");
BaseTestCase.init();
}
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
}
public static boolean isCaptchaEnabled() {
String temp = getValueFromEsignetActuator(GlobalConstants.CLASS_PATH_APPLICATION_PROPERTIES,
GlobalConstants.MOSIP_ESIGNET_CAPTCHA_REQUIRED);
// Throw NPE if temp is null
if (temp == null) {
throw new NullPointerException("Captcha property value is null");
} else if(temp.isEmpty()) {
return false;
} else {
return true;
}
}
/**
* This method will hit post request and return the response
*
* @param url
* @param jsonInput
* @param cookieName
* @param role
* @return Response
*/
protected Response postWithBodyAndCookie(String url, String jsonInput, String cookieName, String role,
String testCaseName) throws SecurityXSSException {
return postWithBodyAndCookie(url, jsonInput, false, cookieName, role, testCaseName, false);
}
protected Response postWithBodyAndCookie(String url, String jsonInput, String cookieName, String role,
String testCaseName, boolean bothAccessAndIdToken) throws SecurityXSSException {
return postWithBodyAndCookie(url, jsonInput, false, cookieName, role, testCaseName, bothAccessAndIdToken);
}
protected Response postWithBodyAndCookie(String url, String jsonInput, boolean auditLogCheck, String cookieName,
String role, String testCaseName) throws SecurityXSSException {
return postWithBodyAndCookie(url, jsonInput, auditLogCheck, cookieName, role, testCaseName, false);
}
protected Response postWithBodyAndCookie(String url, String jsonInput, boolean auditLogCheck, String cookieName,
String role, String testCaseName, boolean bothAccessAndIdToken) throws SecurityXSSException {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = uriKeyWordHandelerUri(url, testCaseName);
if (BaseTestCase.currentModule.contains(GlobalConstants.PREREG) || BaseTestCase.currentModule.contains("auth")
|| BaseTestCase.currentModule.contains(GlobalConstants.RESIDENT)
|| BaseTestCase.currentModule.contains(GlobalConstants.MASTERDATA)
|| BaseTestCase.currentModule.contains(GlobalConstants.DSL)) {
inputJson = smtpOtpHandler(inputJson, testCaseName);
}
if (bothAccessAndIdToken) {
token = kernelAuthLib.getTokenByRole(role, ACCESSTOKENCOOKIENAME);
idToken = kernelAuthLib.getTokenByRole(role, IDTOKENCOOKIENAME);
} else if (testCaseName.contains("NOAUTH")) {
token = "";
} else if (role.equals("userDefinedCookie")) {
JSONObject req = new JSONObject(inputJson);
if (req.has(GlobalConstants.COOKIE)) {
token = req.get(GlobalConstants.COOKIE).toString();
req.remove(GlobalConstants.COOKIE);
if (req.has(GlobalConstants.COOKIE_NAME)) {
cookieName = req.get(GlobalConstants.COOKIE_NAME).toString();
req.remove(GlobalConstants.COOKIE_NAME);
}
}
inputJson = req.toString();
} else {
token = kernelAuthLib.getTokenByRole(role);
}
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, inputJson, url);
try {
if (bothAccessAndIdToken) {
response = RestClient.postRequestWithCookie(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, IDTOKENCOOKIENAME, idToken);
} else {
response = RestClient.postRequestWithCookie(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token);
}
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (auditLogCheck) {
JSONObject jsonObject = new JSONObject(inputJson);
String timeStamp1 = jsonObject.getString(GlobalConstants.REQUESTTIME);
String dbChecker = GlobalConstants.TEST_FULLNAME + BaseTestCase.getLanguageList().get(0);
checkDbAndValidate(timeStamp1, dbChecker);
}
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
}
return response;
}
protected Response deleteWithBodyAndCookie(String url, String jsonInput, String cookieName, String role,
String testCaseName) throws SecurityXSSException {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = uriKeyWordHandelerUri(url, testCaseName);
token = kernelAuthLib.getTokenByRole(role);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, inputJson, url);
try {
response = RestClient.deleteRequestWithCookie(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
}
return response;
}
protected Response postWithBodyAndCookieWithText(String url, String jsonInput, String cookieName, String role,
String testCaseName) throws SecurityXSSException {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = uriKeyWordHandelerUri(url, testCaseName);
token = kernelAuthLib.getTokenByRole(role);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, inputJson, url);
try {
response = RestClient.postRequestWithCookie(url, inputJson, MediaType.APPLICATION_JSON, "*/*", cookieName,
token);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response postWithBodyAndCookieWithoutBody(String url, String jsonInput, String cookieName, String role,
String testCaseName) throws SecurityXSSException {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = uriKeyWordHandelerUri(url, testCaseName);
token = kernelAuthLib.getTokenByRole(role);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, inputJson, url);
try {
response = RestClient.postRequestWithCookie(url, inputJson, MediaType.APPLICATION_JSON, "*/*", cookieName,
token);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, String jsonInput, String cookieName,
String testCaseName) throws SecurityXSSException {
Response response = null;
HashMap<String, String> headers = new HashMap<>();
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
JSONObject request = new JSONObject(inputJson);
String encodedResp = null;
String transactionId = null;
String headerTransactionID = "";
String headerVerifedTransactionID = "";
Map<String, String> cookiesMap = new HashMap<>();
if (request.has(GlobalConstants.REQUEST)
&& request.getJSONObject(GlobalConstants.REQUEST).has(GlobalConstants.TRANSACTIONID)) {
transactionId = request.getJSONObject(GlobalConstants.REQUEST).get(GlobalConstants.TRANSACTIONID)
.toString();
headers.put(OAUTH_TRANSID_HEADERNAME, transactionId);
}
token = properties.getProperty(GlobalConstants.XSRFTOKEN);
if (request.has(GlobalConstants.HEADERTRANSACTIONID)) {
headerTransactionID = request.get(GlobalConstants.HEADERTRANSACTIONID).toString();
cookiesMap.put(GlobalConstants.TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
request.remove(GlobalConstants.HEADERTRANSACTIONID);
}
if (request.has(GlobalConstants.VERIFIEDTRANSACTIONID)) {
headerVerifedTransactionID = request.get(GlobalConstants.VERIFIEDTRANSACTIONID).toString();
cookiesMap.put(GlobalConstants.VERIFIED_TRANSACTION_ID_KEY, headerVerifedTransactionID);
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
request.remove(GlobalConstants.VERIFIEDTRANSACTIONID);
}
if (request.has(GlobalConstants.ENCODEDHASH)) {
encodedResp = request.get(GlobalConstants.ENCODEDHASH).toString();
logger.info("encodedhash = " + encodedResp);
headers.put(OAUTH_HASH_HEADERNAME, encodedResp);
request.remove(GlobalConstants.ENCODEDHASH);
}
if (request.has(GlobalConstants.IDV_TRANSACTION_ID)) {
headerTransactionID = request.get(GlobalConstants.IDV_TRANSACTION_ID).toString();
headers.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
request.remove(GlobalConstants.IDV_TRANSACTION_ID);
}
inputJson = request.toString();
if (BaseTestCase.currentModule.contains(GlobalConstants.MASTERDATA)
|| BaseTestCase.currentModule.equals(GlobalConstants.DSL)) {
inputJson = smtpOtpHandler(inputJson, testCaseName);
}
headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN));
if (testCaseName.contains("_IdpAccessToken_")) {
JSONObject requestInput = new JSONObject(inputJson);
headers.put(cookieName, "Bearer " + requestInput.get(GlobalConstants.IDP_ACCESS_TOKEN).toString());
requestInput.remove(GlobalConstants.IDP_ACCESS_TOKEN);
if (requestInput.has("client_id"))
requestInput.remove("client_id");
inputJson = requestInput.toString();
}
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
if (cookiesMap.containsKey(GlobalConstants.TRANSACTION_ID_KEY)
|| cookiesMap.containsKey(GlobalConstants.VERIFIED_TRANSACTION_ID_KEY)
|| cookiesMap.containsKey(GlobalConstants.IDV_TRANSACTION_ID_KEY)) {
if (testCaseName.contains("_Missing_CSRF_"))
headers.remove(XSRF_HEADERNAME);
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookiesMap, headers);
} else {
if (testCaseName.contains("_GenerateChallengeNegTC_Missing_CSRF_"))
headers.remove(XSRF_HEADERNAME);
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookieName, token, headers);
}
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (testCaseName.contains("_STransId"))
getvalueFromResponseHeader(response, testCaseName);
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
public void getvalueFromResponseHeader(Response response, String testCaseName) {
if (response.getHeaders().hasHeaderWithName("set-cookie")) {
List<String> ListOfSetCookieValues = response.getHeaders().getValues("set-cookie");
for (String eachSetCookieValues : ListOfSetCookieValues) {
String[] setCookieValues = eachSetCookieValues.split(";");
for (String eachSetCookieValue : setCookieValues) {
if (eachSetCookieValue.trim().startsWith("VERIFIED_TRANSACTION_ID=")) {
getCookieAndWriteAutoGenId(eachSetCookieValue, "VTransactionID", testCaseName);
}
if (eachSetCookieValue.trim().startsWith("TRANSACTION_ID=")) {
getCookieAndWriteAutoGenId(eachSetCookieValue, "TransactionID", testCaseName);
}
if (eachSetCookieValue.trim().endsWith("~path-fragment")) {
getCookieAndWriteAutoGenId(eachSetCookieValue, "pathFragmentCookie", testCaseName);
}
if (eachSetCookieValue.trim().startsWith("IDV_TRANSACTION_ID")) {
getCookieAndWriteAutoGenId(eachSetCookieValue, "idvTransactionID", testCaseName);
}
if (eachSetCookieValue.trim().startsWith("IDV_SLOT_ALLOTTED")) {
getCookieAndWriteAutoGenId(eachSetCookieValue, "idvSlotAllotted", testCaseName);
}
if (eachSetCookieValue.trim().startsWith("SESSION=")) {
getCookieAndWriteAutoGenId(eachSetCookieValue, "sessionCookie", testCaseName);
}
}
}
}
}
protected void getCookieAndWriteAutoGenId(String cookieValue, String key, String testCaseName) {
if (cookieValue.split("=").length > 1 && !cookieValue.split("=")[1].isBlank()) {
String value = cookieValue.split("=")[1];
writeAutoGeneratedId(testCaseName, key, value);
}
}
protected Response postWithBodyAndCookieAuthHeaderAndXsrfTokenForAutoGeneratedId(String url, String jsonInput,
String cookieName, String testCaseName, String idKeyName) throws SecurityXSSException {
Response response = null;
HashMap<String, String> headers = new HashMap<>();
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = inputJsonKeyWordHandeler(url, testCaseName);
if (BaseTestCase.currentModule.contains(GlobalConstants.MIMOTO) || BaseTestCase.currentModule.contains("auth")
|| BaseTestCase.currentModule.contains(GlobalConstants.ESIGNET)
|| BaseTestCase.currentModule.contains(GlobalConstants.RESIDENT)
|| BaseTestCase.currentModule.contains(GlobalConstants.MASTERDATA)
|| BaseTestCase.currentModule.contains(GlobalConstants.DSL)) {
inputJson = smtpOtpHandler(inputJson, testCaseName);
}
headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN));
token = properties.getProperty(GlobalConstants.XSRFTOKEN);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (testCaseName.toLowerCase().contains("_sid")) {
writeAutoGeneratedId(response, idKeyName, testCaseName);
}
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(String url, String jsonInput,
String cookieName, String testCaseName, String idKeyName) throws SecurityXSSException {
Response response = null;
HashMap<String, String> headers = new HashMap<>();
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
JSONObject request = new JSONObject(inputJson);
String encodedResp = null;
String transactionId = null;
String headerTransactionID = "";
String pathFragmentCookie = null;
String pathFragmentCookieTransactionId = null;
Map<String, String> cookiesMap = new HashMap<>();
if (request.has(GlobalConstants.ENCODEDHASH)) {
encodedResp = request.get(GlobalConstants.ENCODEDHASH).toString();
request.remove(GlobalConstants.ENCODEDHASH);
}
if (request.has(GlobalConstants.REQUEST) && request.get(GlobalConstants.REQUEST) instanceof JSONObject
&& request.getJSONObject(GlobalConstants.REQUEST).has(GlobalConstants.TRANSACTIONID)) {
transactionId = request.getJSONObject(GlobalConstants.REQUEST).get(GlobalConstants.TRANSACTIONID)
.toString();
}
headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN));
headers.put(OAUTH_HASH_HEADERNAME, encodedResp);
headers.put(OAUTH_TRANSID_HEADERNAME, transactionId);
if (request.has(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID)
&& request.has(GlobalConstants.PATH_FRAGMENT_COOKIE)) {
pathFragmentCookieTransactionId = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID)
.toString();
pathFragmentCookie = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE).toString();
request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID);
request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE);
}
inputJson = request.toString();
if (BaseTestCase.currentModule.contains(GlobalConstants.MIMOTO) || BaseTestCase.currentModule.contains("auth")
|| BaseTestCase.currentModule.contains(GlobalConstants.ESIGNET)
|| BaseTestCase.currentModule.contains(GlobalConstants.RESIDENT)) {
inputJson = smtpOtpHandler(inputJson, testCaseName);
}
token = properties.getProperty(GlobalConstants.XSRFTOKEN);
if (request.has(GlobalConstants.IDV_TRANSACTION_ID)) {
headerTransactionID = request.get(GlobalConstants.IDV_TRANSACTION_ID).toString();
headers.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
request.remove(GlobalConstants.IDV_TRANSACTION_ID);
}
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
if (pathFragmentCookie != null) {
response = RestClient.postRequestWithMultipleHeadersAndMultipleCookies(url, inputJson,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, pathFragmentCookieTransactionId,
pathFragmentCookie, headers);
} else if (cookiesMap.containsKey(GlobalConstants.IDV_TRANSACTION_ID_KEY)) {
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookiesMap, headers);
} else {
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookieName, token, headers);
}
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (testCaseName.toLowerCase().contains("_sid")) {
writeAutoGeneratedId(response, idKeyName, testCaseName);
}
if (testCaseName.contains("_STransId")) {
getvalueFromResponseHeader(response, testCaseName);
}
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response getRequestWithCookieAuthHeaderAndXsrfToken(String url, String jsonInput, String cookieName,
String role, String testCaseName) throws SecurityXSSException {
Response response = null;
HashMap<String, String> headers = new HashMap<>();
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
JSONObject request = new JSONObject(inputJson);
String encodedResp = null;
String transactionId = null;
if (request.has(GlobalConstants.ENCODEDHASH)) {
encodedResp = request.get(GlobalConstants.ENCODEDHASH).toString();
request.remove(GlobalConstants.ENCODEDHASH);
}
if (request.has(GlobalConstants.TRANSACTIONID)) {
transactionId = request.get(GlobalConstants.TRANSACTIONID).toString();
request.remove(GlobalConstants.ENCODEDHASH);
}
headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN));
headers.put(OAUTH_HASH_HEADERNAME, encodedResp);
headers.put(OAUTH_TRANSID_HEADERNAME, transactionId);
token = null;
if (request.has(GlobalConstants.IDV_SLOT_ALLOTED)) {
token = request.get(GlobalConstants.IDV_SLOT_ALLOTED).toString();
cookieName = "IDV_SLOT_ALLOTTED";
request.remove(GlobalConstants.IDV_SLOT_ALLOTED);
}
logger.info(GlobalConstants.GET_REQ_STRING + url);
GlobalMethods.reportRequest(headers.toString(), null, url);
try {
response = RestClient.getRequestWithMultipleHeadersAndCookies(url, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response postRequestWithCookieAuthHeader(String url, String jsonInput, String cookieName, String role,
String testCaseName) throws SecurityXSSException {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
token = kernelAuthLib.getTokenByRole(role);
String apiKey = null;
String partnerId = null;
JSONObject req = new JSONObject(inputJson);
apiKey = req.getString(GlobalConstants.APIKEY);
req.remove(GlobalConstants.APIKEY);
partnerId = req.getString(GlobalConstants.PARTNERID);
req.remove(GlobalConstants.PARTNERID);
HashMap<String, String> headers = new HashMap<>();
headers.put("PARTNER-API-KEY", apiKey);
headers.put("PARTNER-ID", partnerId);
headers.put(cookieName, "Bearer " + token);
inputJson = req.toString();
if (BaseTestCase.currentModule.contains(GlobalConstants.ESIGNET)) {
inputJson = smtpOtpHandler(inputJson, testCaseName);
}
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
response = RestClient.postRequestWithMultipleHeadersWithoutCookie(url, inputJson,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, headers);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response postWithBodyAndCookieForKeyCloak(String url, String jsonInput, String cookieName, String role,
String testCaseName) throws SecurityXSSException {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = uriKeyWordHandelerUri(url, testCaseName);
token = kernelAuthLib.getTokenByRole(role);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, inputJson, url);
try {
response = RestClient.postRequestWithBearerToken(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response postWithBodyAcceptTextPlainAndCookie(String url, String jsonInput, String cookieName,
String role, String testCaseName) throws SecurityXSSException {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
token = kernelAuthLib.getTokenByRole(role);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, inputJson, url);
try {
response = RestClient.postRequestWithCookie(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.TEXT_PLAIN, cookieName, token);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response postRequestWithCookieAuthHeaderAndSignature(String url, String jsonInput, String cookieName,
String role, String testCaseName) throws SecurityXSSException {
Response response = null;
String[] uriParts = url.split("/");
String partnerId = uriParts[uriParts.length - 2];
HashMap<String, String> headers = new HashMap<>();
headers.put(AUTHORIZATHION_HEADERNAME, AUTH_HEADER_VALUE);
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
headers.put(SIGNATURE_HEADERNAME, generateSignatureWithRequest(inputJson, partnerId));
if (testCaseName.contains("NOAUTH")) {
token = "";
} else {
token = kernelAuthLib.getTokenByRole(role);
}
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
response = RestClient.postRequestWithMultipleHeaders(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response postRequestWithAuthHeaderAndSignatureForOtp(String url, String jsonInput, String cookieName,
String token, Map<String, String> headers, String testCaseName) throws SecurityXSSException {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = uriKeyWordHandelerUri(url, testCaseName);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
response = RestClient.postRequestWithMultipleHeaders(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
}
return response;
}
protected Response postRequestWithAuthHeaderAndSignatureForOtpAutoGenId(String url, String jsonInput,
String cookieName, String token, Map<String, String> headers, String testCaseName, String idKeyName)
throws SecurityXSSException {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = uriKeyWordHandelerUri(url, testCaseName);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
response = RestClient.postRequestWithMultipleHeaders(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (testCaseName.toLowerCase().contains("_sid")) {
writeAutoGeneratedId(response, idKeyName, testCaseName);
}
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
}
return response;
}
protected Response patchRequestWithCookieAuthHeaderAndSignature(String url, String jsonInput, String cookieName,
String role, String testCaseName) throws SecurityXSSException {
Response response = null;
HashMap<String, String> headers = new HashMap<>();
headers.put(AUTHORIZATHION_HEADERNAME, AUTH_HEADER_VALUE);
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
headers.put(SIGNATURE_HEADERNAME, generateSignatureWithRequest(inputJson, null));
token = kernelAuthLib.getTokenByRole(role);
logger.info("******Patch request Json to EndPointUrl: " + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
response = RestClient.patchRequestWithMultipleHeaders(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
// check if X-XSS-Protection is enabled or not
GlobalMethods.checkXSSProtectionHeader(response, url);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (SecurityXSSException se) {
String responseHeadersString = (response == null) ? "No response"
: response.getHeaders().asList().toString();
String errorMessageString = "XSS check failed for URL: " + url + "\nHeaders: " + responseHeadersString
+ "\nError: " + se.getMessage();
logger.error(errorMessageString, se);
throw se;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
protected Response postRequestWithAuthHeaderAndSignature(String url, String jsonInput, String testCaseName)
throws SecurityXSSException {
Response response = null;
String[] uriParts = url.split("/");
String partnerId = uriParts[uriParts.length - 2];
HashMap<String, String> headers = new HashMap<>();
headers.put(AUTHORIZATHION_HEADERNAME, AUTH_HEADER_VALUE);
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
if (testCaseName.contains("NOAUTH")) {
headers.put(SIGNATURE_HEADERNAME, "");
} else {
headers.put(SIGNATURE_HEADERNAME, generateSignatureWithRequest(inputJson, partnerId));
}
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {