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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
|
*** Settings ***
Library Collections
Library String
Library RequestsLibrary
Resource ${EXECDIR}/variable/common_variable.txt
Resource ${EXECDIR}/keyword/common/functional_keywords.robot
Resource process_object_body.robot
Library Collections
Resource ${EXECDIR}/keyword/common/common.robot
Library ${EXECDIR}/customlib/common/util.py
Library ${EXECDIR}/customlib/common/hex_convert.py
Library DatabaseLibrary
Library ${EXECDIR}/customlib/common/common.py
Library ${EXECDIR}/customlib/file_operations.py
*** Variables ***
${objectUrl} /policy/object
${categoryUrl} /category/dict
${applicationDictUrl} /application/update/dict
${fileUploaduRL} /system/feature/update/
*** Keywords ***
AddLocalIPObject
#创建对象IP
log to_AddLocalIPObject
Comment 创建IP
${testClentIP} Run Keyword If "${incomingGreClientInfo}"!="${EMPTY}" GetListClientIp ${incomingGreClientInfo} greInfo
... ELSE IF "${incomingClientInfo}"!="${EMPTY}" GetClientIp ${incomingClientInfo}
... ELSE IF "${incomingMobileClientInfo}"!="${EMPTY}" GetMobileClientIp ${incomingMobileClientInfo}
... ELSE IF "${incomingVoipClientInfo}"!="${EMPTY}" GetListClientIp ${incomingVoipClientInfo} voipInfo
... ELSE Set Variable ${testClentIP}
log ${testClentIP}
SET GLOBAL VARIABLE ${autoTestClientIp} ${testClentIP}
#object为IP→endpoint时的addItemList单个对象
${addItemList1} Create Dictionary isSession=endpoint ip=${testClentIP} port=0-65535 direction=0 protocol=-1 isInitialize=0
#可以添加多个
${addItemLists} Create list ${addItemList1}
#objectList对象
${objectDict} Create Dictionary objectType=ip objectSubType=ip isValid=${1} addItemList=${addItemLists} objectName=defaultClientIP
${rescode} ${objectId1} AddObjects ${1} ${objectDict}
SET GLOBAL VARIABLE ${testClentID} ${objectId1}
# Comment 创建mobile_identity-imsi
# ${addItemList1} Create Dictionary keywordArray=${imsi} isHexbin=${0}
# ${addItemLists} Create list ${addItemList1}
# ${objectDict} Create Dictionary objectType=mobile_identity objectSubType=imsi isValid=${1} addItemList=${addItemLists} objectName=defaultImsi
# ${rescode} ${imsi_id} AddObjects ${1} ${objectDict}
# InsertObjectIdToFile global_imsi_id ${imsi_id}
# SET GLOBAL VARIABLE ${testImsiId} ${imsi_id}
# Comment 创建mobile_identity-phone_number
# ${addItemList1} Create Dictionary keywordArray=${phone_number1} isHexbin=${0}
# ${addItemList2} Create Dictionary keywordArray=${phone_number2} isHexbin=${0}
# ${addItemList3} Create Dictionary keywordArray=${phone_number3} isHexbin=${0}
# ${addItemList4} Create Dictionary keywordArray=${phone_number4} isHexbin=${0}
# ${addItemLists} Create list ${addItemList1} ${addItemList2} ${addItemList3} ${addItemList4}
# ${objectDict} Create Dictionary objectType=mobile_identity objectSubType=phone_number isValid=${1} addItemList=${addItemLists} objectName=defaultPhnenumber
# ${rescode} ${phoneNum_id} AddObjects ${1} ${objectDict}
# InsertObjectIdToFile global_phoneNum_id ${phoneNum_id}
# SET GLOBAL VARIABLE ${testPhoneNumId} ${phoneNum_id}
# Comment 创建apn
# ${addItemList1} Create Dictionary keywordArray=${apn1} isHexbin=${0}
# ${addItemList2} Create Dictionary keywordArray=${apn2} isHexbin=${0}
# ${addItemLists} Create list ${addItemList1} ${addItemList2}
# ${objectDict} Create Dictionary objectType=apn objectSubType=apn isValid=${1} addItemList=${addItemLists} objectName=defaultAPN
# ${rescode} ${apn_id} AddObjects ${1} ${objectDict}
# InsertObjectIdToFile global_apn_id ${apn_id}
# SET GLOBAL VARIABLE ${testApnId} ${apn_id}
${objectId1} Evaluate int(${objectId1})
${objectId1} Convert To Integer ${objectId1}
${object_ids} Create List
${objects} Create List
Append To List ${object_ids} ${objectId1}
${object_ids} Create Dictionary object_ids=${object_ids}
Append To List ${objects} ${object_ids}
${sourceClientIP} Create Dictionary objects=${objects} attribute_name=ATTR_SOURCE_IP is_negate=${0}
# ${imsi_id} Evaluate int(${imsi_id})
# ${imsi_id} Convert To Integer ${imsi_id}
# ${object_ids} Create List
# ${objects} Create List
# Append To List ${object_ids} ${imsi_id}
# ${object_ids} Create Dictionary object_ids=${object_ids}
# Append To List ${objects} ${object_ids}
# ${sourceImsi} Create Dictionary objects=${objects} protocol_field=ATTR_GTP_IMSI not_flag=${0}
# ${phoneNum_id} Evaluate int(${phoneNum_id})
# ${phoneNum_id} Convert To Integer ${phoneNum_id}
# ${object_ids} Create List
# ${objects} Create List
# Append To List ${object_ids} ${phoneNum_id}
# ${object_ids} Create Dictionary object_ids=${object_ids}
# Append To List ${objects} ${object_ids}
# ${sourcePhoneNumber} Create Dictionary objects=${objects} protocol_field=ATTR_GTP_PHONE_NUMBER not_flag=${0}
# ${apn_id} Evaluate int(${apn_id})
# ${apn_id} Convert To Integer ${apn_id}
# ${object_ids} Create List
# ${objects} Create List
# Append To List ${object_ids} ${apn_id}
# ${object_ids} Create Dictionary object_ids=${object_ids}
# Append To List ${objects} ${object_ids}
# ${sourceApn} Create Dictionary objects=${objects} protocol_field=ATTR_GTP_APN not_flag=${0}
# ${sourceList} Create List ${sourceClientIP} ${sourceImsi} ${sourcePhoneNumber} ${sourceApn}
${sourceList} Create List ${sourceClientIP}
SET GLOBAL VARIABLE ${defaultClient} ${sourceList}
GetClientIp
[Arguments] ${clientInfo}
log ${clientInfo}
${clientInfo} Replace String ${clientInfo} ' "
${clientInfo} Replace String ${clientInfo} None ""
${clientInfo} json.loads ${clientInfo}
log ${clientInfo}
${testClentIP} Run Keyword If "${ipVersion}"=="4" Get From Dictionary ${clientInfo} operationIp
... ELSE Get From Dictionary ${clientInfo} ipv6OperationIp
[Return] ${testClentIP}
GetMobileClientIp
[Arguments] ${clientInfo}
log ${clientInfo}
${clientInfo} Replace String ${clientInfo} ' "
${clientInfo} Replace String ${clientInfo} None ""
${clientInfo} json.loads ${clientInfo}
${testClentIP} Run Keyword If "${isAirTest}"=="1" Get From Dictionary ${clientInfo} manageIp
... ELSE Get From Dictionary ${clientInfo} operationIp
[Return] ${testClentIP}
GetListClientIp
[Arguments] ${listClientInfo} ${key}
${listClientInfo} Replace String ${listClientInfo} exclam !
${listClientInfo} Replace String ${listClientInfo} ' "
${listClientInfo} Replace String ${listClientInfo} None ""
${listClientInfo} json.loads ${listClientInfo}
${listClientInfo} Get From Dictionary ${listClientInfo} ${key}
${clientInfo1} Set Variable ${listClientInfo}[0]
${clientInfo2} Set Variable ${listClientInfo}[1]
log ${clientInfo1}
log ${clientInfo2}
${clientModule1} Get From Dictionary ${clientInfo1} clientModule
${clientModule2} Get From Dictionary ${clientInfo2} clientModule
${clientIpInfo} Run Keyword If "${clientModule1}"=="sipCall" or "${clientModule1}"=="greClient" Set Variable ${clientInfo1}
... ELSE IF "${clientModule2}"=="sipCall" or "${clientModule2}"=="greClient" Set Variable ${clientInfo2}
${testClentIP} Get From Dictionary ${clientIpInfo} operationIp
[Return] ${testClentIP}
AddObjects
[Arguments] ${returnData} ${objectList}
[Documentation] 新增策略对象
... objectList,策略对象,可为list类型与dict类型
... addItemList自动过滤itemId
... updateItemList自动过滤isInitialize(update时该字段引发异常)
... ipItem格式为dict,自动过滤空的字段
... stringItem格式为dict,需要注意keywordArray字段应传入逗号分隔的字符串eg: keyword1,keyword2
... http_signature为代表的拓展关键字keywordArray字段也是以逗号分隔的
... returnData,是否返回数据,固定为1
${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
... ELSE Set Variable ${returnData}
#必选参数判定
Should Not Be Empty ${objectList}
${dictType} = Evaluate type(${objectList})
${body} Run Keyword If "${dictType}" == "<class 'list'>" ObjectListOperation ${returnData} ${objectList} add
... ELSE IF "${dictType}" == "<class 'dict'>" ObjectOperation ${returnData} ${objectList} add
... ELSE Set Variable ${EMPTY}
log ${body}
${response} BasePostRequestForV2 ${objectUrl} ${body} ${version}
${objectIds} Run Keyword If "${returnData}" == "1" GetObjectIds ${response}
... ELSE Create List
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode} ${objectIds}
UpdateObjects
[Arguments] ${returnData} ${objectList} ${opAction}
[Documentation] 更新策略对象
... objectList,策略对象,可为list类型与dict类型
... addItemList自动过滤itemId
... updateItemList自动过滤isInitialize(update时该字段引发异常)
... ipItem格式为dict,自动过滤空的字段
... stringItem格式为dict,需要注意keywordArray字段应传入逗号分隔的字符串eg: keyword1,keyword2
... http_signature为代表的拓展关键字keywordArray字段也是以逗号分隔的
... returnData,是否返回数据,固定为1
... opAction,可为update,enable,disable
${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
... ELSE Set Variable ${returnData}
#必选参数判定
Should Not Be Empty ${objectList}
${dictType} = Evaluate type(${objectList})
${body} Run Keyword If "${dictType}" == "<class 'list'>" ObjectListOperation ${returnData} ${objectList} ${opAction}
... ELSE IF "${dictType}" == "<class 'dict'>" ObjectOperation ${returnData} ${objectList} ${opAction}
... ELSE Set Variable ${EMPTY}
${response} BaseEditRequestForV2 ${objectUrl} ${body} ${version} 1
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
UpdateInstall
[Arguments] ${updateDict}
[Documentation] 更新策略对象
... objectList,策略对象,可为list类型与dict类型
... addItemList自动过滤itemId
... updateItemList自动过滤isInitialize(update时该字段引发异常)
... ipItem格式为dict,自动过滤空的字段
... stringItem格式为dict,需要注意keywordArray字段应传入逗号分隔的字符串eg: keyword1,keyword2
... http_signature为代表的拓展关键字keywordArray字段也是以逗号分隔的
... returnData,是否返回数据,固定为1
... opAction,可为update,enable,disable
#必选参数判定
Should Not Be Empty ${updateDict}
${bodyJson} json.Dumps ${updateDict} ensure_ascii=False
${response} BaseEditRequestForV2 ${fileUploaduRL} ${body} ${version} 1
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
GetObjectItems
[Arguments] ${params}
[Documentation] 获取策略对象中的item,策略对象单元
... 当updateItemList中有需要传入数据时
... 调用此关键字
#必选参数判定
Should Not Be Empty ${params}
${paramsStr} DictionaryToQueryParams ${params}
${response} BaseFormRequest /policy/items ${paramsStr} ${version}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
${data} Set Variable ${response['data']}
${itemIds} Create List
FOR ${item} IN @{data['list']}
Append To List ${itemIds} ${item['itemId']}
END
[Return] ${rescode} ${itemIds} ${data['list']}
GetObjectItems1
[Arguments] ${params}
[Documentation] 获取策略对象中的item,策略对象单元
... 当updateItemList中有需要传入数据时
... 调用此关键字
#必选参数判定
Should Not Be Empty ${params}
${paramsStr} DictionaryToQueryParams ${params}
${response} BaseFormRequest /policy/items ${paramsStr} ${version}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
${data} Set Variable ${response['data']}
[Return] ${rescode} ${data}
DeleteObjectByIds
[Arguments] ${objectIds}
[Documentation] 删除策略对象
... params,传入的删除字典
... 结构为[1,2,3]
${type} Evaluate isinstance(${objectIds},list)
log ${objectIds}
Should Be True ${type}
${dict} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary objectIds=${objectIds} vsysId=${vsysId}
... ELSE Create Dictionary objectIds=${objectIds}
${json} json.Dumps ${dict} ensure_ascii=False
${response} BaseDeleteRequestParams /${version}${objectUrl} ${json}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
DeleteIpByIds
[Arguments] ${objectIds}
[Documentation] 删除策略对象
... params,传入的删除字典
... 结构为[1,2,3]
log ${objectIds}
${objectIds}= Evaluate ','.join(map(str, @{objectIds}))
${dict} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary ids=${objectIds} vsys_id=${vsysId} type=ip
... ELSE Create Dictionary object_ids=${objectIds}
${response} BaseDeleteRequestParams /${version}${objectUrl} ${dict}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
DeleteFqdnByIds
[Arguments] ${objectIds}
[Documentation] 删除策略对象
... params,传入的删除字典
... 结构为[1,2,3]
log ${objectIds}
${objectIds}= Evaluate ','.join(map(str, @{objectIds}))
${dict} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary ids=${objectIds} vsys_id=${vsysId} type=fqdn
... ELSE Create Dictionary objectIds=${objectIds}
${response} BaseDeleteRequestParams /${version}${objectUrl} ${dict}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
DeleteHttpSignatureByIds
[Arguments] ${objectIds}
[Documentation] 删除策略对象
... params,传入的删除字典
... 结构为[1,2,3]
log ${objectIds}
${objectIds}= Evaluate ','.join(map(str, @{objectIds}))
${dict} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary ids=${objectIds} vsys_id=${vsysId} type=http_signature
... ELSE Create Dictionary objectIds=${objectIds}
${response} BaseDeleteRequestParams /${version}${objectUrl} ${dict}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
DeleteKeywordsByIds
[Arguments] ${objectIds}
[Documentation] 删除策略对象
... params,传入的删除字典
... 结构为[1,2,3]
log ${objectIds}
${objectIds}= Evaluate ','.join(map(str, @{objectIds}))
${dict} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary ids=${objectIds} vsys_id=${vsysId} type=keywords
... ELSE Create Dictionary objectIds=${objectIds}
${response} BaseDeleteRequestParams /${version}${objectUrl} ${dict}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
DeleteUrlByIds
[Arguments] ${objectIds}
[Documentation] 删除策略对象
... params,传入的删除字典
... 结构为[1,2,3]
log ${objectIds}
${objectIds}= Evaluate ','.join(map(str, @{objectIds}))
${dict} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary ids=${objectIds} vsys_id=${vsysId} type=url
... ELSE Create Dictionary objectIds=${objectIds}
${response} BaseDeleteRequestParams /${version}${objectUrl} ${dict}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
DeleteAccountByIds
[Arguments] ${objectIds}
[Documentation] 删除策略对象
... params,传入的删除字典
... 结构为[1,2,3]
log ${objectIds}
${objectIds}= Evaluate ','.join(map(str, @{objectIds}))
${dict} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary ids=${objectIds} vsys_id=${vsysId} type=account
... ELSE Create Dictionary objectIds=${objectIds}
${response} BaseDeleteRequestParams /${version}${objectUrl} ${dict}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
DeleteMobileIdentityByIds
[Arguments] ${objectIds}
[Documentation] 删除策略对象
... params,传入的删除字典
... 结构为[1,2,3]
log ${objectIds}
${objectIds}= Evaluate ','.join(map(str, @{objectIds}))
${dict} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary ids=${objectIds} vsys_id=${vsysId} type=mobile_identity
... ELSE Create Dictionary objectIds=${objectIds}
${response} BaseDeleteRequestParams /${version}${objectUrl} ${dict}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
DeleteApnByIds
[Arguments] ${objectIds}
[Documentation] 删除策略对象
... params,传入的删除字典
... 结构为[1,2,3]
log ${objectIds}
${objectIds}= Evaluate ','.join(map(str, @{objectIds}))
${dict} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary ids=${objectIds} vsys_id=${vsysId} type=apn
... ELSE Create Dictionary objectIds=${objectIds}
${response} BaseDeleteRequestParams /${version}${objectUrl} ${dict}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode}
ImportObject
[Arguments] ${filePath} ${fileName} ${objectType} ${objectSubType} ${objectName}
[Documentation] 策略对象导入
... filePath文件路径
... fileName文件名称
... objectType对象类型
... objectSubType对象子类型
... objectName对象名称
... jira CHON-12导入限制需求支持
OperatingSystem.Directory Should Exist ${path}
OperatingSystem.File Should Exist ${path}/${filePath}/${fileName}
OperatingSystem.File Should Not Be Empty ${path}/${filePath}/${fileName}
${size} OperatingSystem.Get File Size ${path}/${filePath}/${fileName}
Should Not Be Empty ${objectType}
#获取Item 的总数
${total} GetItemNum ${objectType} ${objectSubType}
#获取导入文件中的总行数
#${lines} CountLines ${path}/${filePath}/${fileName}
${lines} CountLines ${path}/${filePath}/${fileName}
${objectSubType} Run Keyword If "${objectType}"=="ip" and "${objectSubType}"=="${EMPTY}" Set Variable endpoint
... ELSE Set Variable ${objectSubType}
${subfix} Fetch From Right ${fileName} .
${binFile} Run Keyword If "${subfix}"=="txt" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'text/plain')
... ELSE IF "${subfix}"=="csv" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'application/vnd.ms-excel')
... ELSE ${EMPTY}
${data} Create Dictionary objectType=${objectType} objectName=${fileName}
Run Keyword If "${objectSubType}"!="${EMPTY}" Set To Dictionary ${data} objectSubType=${objectSubType}
Run Keyword If "${objectName}"!="${EMPTY}" Set To Dictionary ${data} objectName=${objectName}
${file} Create Dictionary file=${binFile}
${response} BaseMultipartPostRequest ${objectUrl}/batch ${data} ${file} ${version}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${rescode} ${objectType} ${response}
QueryObject
#hbn
[Arguments] ${body}
${response} BaseGetRequest /${version}/policy/object body=${body}
log ${response}
${rescode} Set Variable ${response['code']}
[Return] ${rescode} ${response}
ImportApplication
[Arguments] ${filePath} ${fileName} ${feature} ${code}
[Documentation] 策略对象导入
... filePath文件路径
... fileName文件名称
... feature是特征
Directory Should Exist ${path}
File Should Exist ${path}/${filePath}/${fileName}
File Should Not Be Empty ${path}/${filePath}/${fileName}
${size} Get File Size ${path}/${filePath}/${fileName}
${binFile} Run Keyword If "${feature}"=="${EMPTY}" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'application/xml')
... ELSE IF "${feature}"=="app_library" or "${feature}"=="app_signature" Evaluate (r'${fileName}',open(r"${path}/${filePath}/${fileName}",'rb'),'application/octet-stream')
... ELSE ${EMPTY}
${file} Create Dictionary file=${binFile}
# ${response} BaseMultipartPostRequest ${objectUrl}/batch ${EMPTY} ${file} ${version}
${response} Run Keyword If "${feature}"=="${EMPTY}" BaseMultipartPostRequest ${applicationDictUrl} ${EMPTY} ${file} ${version}
... ELSE IF "${feature}"=="app_library" or "${feature}"=="app_signature" BaseMultipartPostRequest ${fileUploaduRL} ${EMPTY} ${file} ${version}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} ${code}
ExportObject
[Arguments] ${objectType} ${objectSubType} ${objectIds} ${objectName}
[Documentation] 策略对象导出
... objectType ip,url等
... objectSubType 子类型
... objectIds 1,2,3
... objectName 字符串
Should Not Be Empty ${objectType}
${params} Create Dictionary objectType=${objectType}
Run Keyword If "${objectSubType}"!="${EMPTY}" Set To Dictionary ${params} objectSubType=${objectSubType}
Run Keyword If "${objectIds}"!="${EMPTY}" Set To Dictionary ${params} objectIds=${objectIds}
Run Keyword If "${objectName}"!="${EMPTY}" Set To Dictionary ${params} objectName=${objectName}
${response} BaseGetRequestReturnBinary ${objectUrl}/batch ${params} ${version}
[Return] ${response}
GetItemNum
[Arguments] ${objectType} ${objectSubType}
[Documentation] 获取策略对象单元总数
${getTotal} Create Dictionary pageNo=${1} pageSize=${1}
Run Keyword If "${objectType}"=="ip" and "${objectSubType}"=="endpoint" Set To Dictionary ${getTotal} itemType=IP
... ELSE IF "${objectType}"=="ip" and "${objectSubType}"=="geo_location" Set To Dictionary ${getTotal} itemType=geo_location
... ELSE IF "${objectType}"=="ip" and "${objectSubType}"=="as_number" Set To Dictionary ${getTotal} itemType=as_number
... ELSE IF "${objectType}"=="url" Set To Dictionary ${getTotal} itemType=URL
... ELSE Set To Dictionary ${getTotal} itemType=${objectType}
${rescode} ${data} GetObjectItems1 ${getTotal}
${total} Set Variable ${data['total']}
Run Keyword If "${objectType}"=="fqdn_category" Set To Dictionary ${getTotal} isInitialize=1
${rescode} ${data} Run Keyword If "${objectType}"=="fqdn_category" GetObjectItems1 ${getTotal}
... ELSE Set Variable ${rescode} ${data}
${total} Run Keyword If "${objectType}"=="fqdn_category" Evaluate ${total} - ${data['total']}
... ELSE Set Variable ${total}
[Return] ${total}
CountLines1
[Arguments] ${file}
[Documentation] 获取文件总行数
${count} Set Variable ${0}
${openFile} Evaluate enumerate(open(r"${file}",'r'))
FOR ${line} IN @{openFile}
${val} Run Keyword If "${line[0]}"=="0" Set Variable ${line[1]}
... ELSE Set Variable ${EMPTY}
${val2} Run Keyword If "${line[1]}"=="\n" Set Variable ${line[0]}
... ELSE Set Variable ${EMPTY}
log ${line}
log "${line[1]}"
${match} Get Regexp Matches ${val} ^-->
#${match2} Get Regexp Matches ${val} ^(\t)*$\n
${len} Get Length ${match}
#${len2} Get Length ${match2}
${count} Run Keyword If "${line[0]}"=="0" and ${len}>0 Set Variable ${count}
... ELSE Evaluate ${count}+1
END
[Return] ${count}
PolicProtocolFields
[Arguments] ${policyType} ${protocol} ${objectType}
[Documentation] 策略对象生效协议字段查询
... policyType策略类型
... protocol协议
... objectType对象类型
${dict} Create Dictionary
Run Keyword If "${policyType}"!="${EMPTY}" Set To Dictionary ${dict} policyType=${policyType}
Run Keyword If "${protocol}"!="${EMPTY}" Set To Dictionary ${dict} protocol=${protocol}
Run Keyword If "${objectType}"!="${EMPTY}" Set To Dictionary ${dict} objectType=${objectType}
${parmStr} DictionaryToQueryParams ${dict}
${response} BaseFormRequest ${objectUrl}/protocolFields ${parmStr} ${version}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${response['data']}
ObjectReference
[Arguments] ${objectId}
[Documentation] 策略对象相关性查询
${response} BaseFormRequest ${objectUrl}/reference objectId=${objectId} ${version}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${response['data']}
AppIdTreeSearch
[Arguments] ${referenceObjectId}
[Documentation] App ID对象树查询
${response} BaseFormRequest ${objectUrl}/appId/tree referenceObjectId=${referenceObjectId} ${version}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} 200
[Return] ${response['data']}
AddCategories
[Arguments] ${returnData} ${categoryList} ${opAction} ${testCode}=null
[Documentation] 新增Category
... returnData,是否返回数据,固定为1
Comment 此处思路给category单独的另一套关键字,原因:地址与json串名称与Object部分不同了
${returnData}= Run Keyword If '${returnData}' == '${EMPTY}' Set Variable 1
... ELSE Set Variable ${returnData}
#必选参数判定
Should Not Be Empty ${categoryList}
${dictType} = Evaluate type(${categoryList})
${body} Run Keyword If "${dictType}" == "<class 'list'>" CategoryListOperation ${returnData} ${categoryList} ${opAction}
... ELSE IF "${dictType}" == "<class 'dict'>" CategoryOperation ${returnData} ${categoryList} ${opAction}
... ELSE Set Variable ${EMPTY}
log ${body}
# ${response} BasePostRequestForV2 ${categoryUrl} ${body} ${version}
${response} Run Keyword If "${opAction}"=="add" BasePostRequestForV2 ${categoryUrl} ${body} ${version}
... ELSE IF "${opAction}"=="update" BaseEditRequestForV2 ${categoryUrl} ${body} ${version} 1
${CategoryObjIds} Run Keyword If "${returnData}" == "1" and ${testCode} == 200 and "${opAction}"=="add" GetCategoryObjIds ${response}
... ELSE Set Variable ${EMPTY}
${CategoryIds} Run Keyword If "${returnData}" == "1" and ${testCode} == 200 and "${opAction}"=="add" GetCategoryIds ${response}
... ELSE Set Variable ${EMPTY}
${rescode} Set Variable ${response['code']}
Should Be Equal As Strings ${rescode} ${testCode}
[Return] ${rescode} ${CategoryObjIds} ${CategoryIds}
QueryUpadateRecord
[Arguments] ${body} ${code}
${response} BaseGetRequestOK /${version}/system/feature/update body=${body}
log ${response}
${rescode} Set Variable ${response['code']}
Shoule Be Equal As Strings ${rescode} ${code}
[Return] ${rescode}
DeleteCategoryByIds
[Arguments] ${categoryids}
#删除对象
log todeleteobjAndCategory
${response} BaseDeleteRequest /${version}/category/dict {"categoryIds":[${categoryids}]}
${response_code} Get From Dictionary ${response} code
Should Be Equal As Strings ${response_code} 200
${response} Convert to String ${response}
log ${response}
DelLocalIPObject
log to_DelLocalIPObject
${emptyList} Create List
${objectId1} Set Variable [${testClentID}]
${objectId1} json.loads ${objectId1}
# ${objectId2} Set Variable [${testImsiId},${testPhoneNumId}]
# ${objectId2} json.loads ${objectId2}
# ${objectId3} Set Variable [${testApnId}]
# ${objectId3} json.loads ${objectId3}
DeleteIpByIds ${objectId1}
# DeleteMobileIdentityByIds ${objectId2}
# DeleteApnByIds ${objectId3}
SET GLOBAL VARIABLE ${testClentID} ${EMPTY}
# SET GLOBAL VARIABLE ${testClentSubID} ${EMPTY}
# SET GLOBAL VARIABLE ${testImsiId} ${EMPTY}
# SET GLOBAL VARIABLE ${testPhoneNumId} ${EMPTY}
# SET GLOBAL VARIABLE ${testApnId} ${EMPTY}
###############################################################################
#数据分离,测试数据来自对应的yaml文件
ObjectsByTemplate
[Documentation] 根据测试数据文件,使用对应公共模板,创建对象
... 入参:${dataFilePath}数据文件,全路径文件名 ${keyword}测试用例名称
... data数据文件格式参照:other/data/object/demo_data.yaml
... 返回数据:对象idlist${objectIds},格式:[107582, 107583]
... 返回数据:策略id+类型list${policyIds},格式:[{'objectId': 107582, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'},{'objectId': 107583, 'protocolField': 'TSG_SECURITY_SOURCE_ADDR'}]
[Arguments] ${dataFilePath} ${keyword}
${yamlData}= OperatingSystem.Get File ${dataFilePath}
${loadedData}= yaml.Safe Load ${yamlData}
${list} Get From Dictionary ${loadedData} ${keyword}_data
${objectIds} Create List
Comment 循环创建策略
FOR ${key} IN @{list}
${objectId} ${objectList} ${attribute} ${atributeObjectId} Run Keyword And Continue On Failure CreateObjectList ${key} ${keyword}
#返回的对象和策略信息添加到对象和策略列表
Run Keyword If "${objectId}" !="None" and "${objectId}" !="[]" AppendListToList ${objectIds} ${objectId}
END
[Return] ${objectIds}
OrangeFilter
[Documentation] filer对象处理,把一个filter的list处理为一个filter
#[Arguments] ${filterList} ${objectList}
[Arguments] ${objectList}
# ${filter} Create Dictionary objectList=${objectList}
# ${list} Create Dictionary filter=${filter}
${list} Create List ${objectList}
log ${list}
log aaa
[Return] ${list}
GetPortFromPortRange
[Documentation] 从port范围(0-65535)获取port:
[Arguments] ${port}
Log ${port}
@{List} Split String ${port} -
${len} Get Length ${List}
${portTemp} Run Keyword If ${len} == 2 Get From List ${List} 1
... ELSE Get From List ${List} 0
Log ${portTemp}
[Return] ${portTemp}
OrangeAttribute
[Documentation] 组织策略验证条件
... ${itemvalue}策略中的对象item
... ${objectSubType} 对象字类型
... ${protocolField}对象在策略中的位置
... ${appName}策略验证中的协议,只能是一种
[Arguments] ${itemvalue} ${objectSubType} ${protocolField} ${appName} ${port}=null ${isHexbin}=${EMPTY}
${iptype} Set Variable ${EMPTY}
log ${iptype}
${iptype} Run Keyword If "${appName}" != "${EMPTY}" and "${objectSubType}" == "endpoint" check_ip ${itemvalue} ELSE Set Variable ${EMPTY}
#clientip使用本机ip
${strValue} Run Keyword If ${isHexbin}==1 HexToStr ${itemvalue}
... ELSE Set Variable ${itemvalue}
${attributeValue} Run Keyword If "${appName}" != "${EMPTY}" and "${objectSubType}" == "endpoint" Create Dictionary ip=${itemvalue} port=${port} tableName=${protocolField} addrType=${iptype} protocol=-1
... ELSE IF ("${objectSubType}" == "User-Agent" or "${objectSubType}" == "Set-Cookie" or "${objectSubType}" == "Cookie" or "${objectSubType}" == "Content-Type" or "${objectSubType}" == "Connection" or "${objectSubType}" == "ETag" or "${objectSubType}" == "Accept-Encoding" or "${objectSubType}" == "Age") and "${isHexbin}"=="1" Create Dictionary string=${strValue} district=${objectSubType}
... ELSE IF ("${objectSubType}" == "User-Agent" or "${objectSubType}" == "Set-Cookie" or "${objectSubType}" == "Cookie" or "${objectSubType}" == "Content-Type" or "${objectSubType}" == "Connection" or "${objectSubType}" == "ETag" or "${objectSubType}" == "Accept-Encoding" or "${objectSubType}" == "Age") and "${isHexbin}"!="1" Create Dictionary string=${strValue} district=${objectSubType}
... ELSE Create Dictionary string=${itemvalue}
${attributeType} Run Keyword If "${objectSubType}" == "endpoint" Set Variable ip ELSE Set Variable string
${protocolField} Run Keyword If "${protocolField}" == "None" Set Variable subscriberid ELSE Set Variable ${protocolField}
${temp} aisincludeb TSG_SECURITY_SOURCE ${protocolField}
${temp1} aisincludeb TSG_SECURITY_DESTINATION ${protocolField}
${attributeName} Run Keyword If "${temp}" == "True" Set Variable source
... ELSE IF "${temp1}" == "True" Set Variable destination
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_HOST" or "${protocolField}" == "TSG_FIELD_DOH_HOST" Set Variable host
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_URL" or "${protocolField}" == "TSG_FIELD_FTP_URI" Set Variable url
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_REQ_HDR" Set Variable req_hdr
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_RES_HDR" Set Variable res_hdr
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_REQ_BODY" Set Variable req_body
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_RES_BODY" Set Variable res_body
... ELSE IF "${protocolField}" == "TSG_FIELD_SSL_SNI" or "${protocolField}" == "TSG_FIELD_QUIC_SNI" Set Variable sni
... ELSE IF "${protocolField}" == "TSG_FIELD_SSL_SAN" Set Variable san
... ELSE IF "${protocolField}" == "TSG_FIELD_SSL_CN" Set Variable cn
... ELSE IF "${protocolField}" == "TSG_FIELD_DNS_QNAME" or "${protocolField}" == "TSG_FIELD_DOH_QNAME" Set Variable qname
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_SUBJECT" Set Variable subject
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_CONTENT" Set Variable content
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_ATT_NAME" Set Variable att_name
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_ATT_CONTENT" Set Variable att_content
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_FROM" Set Variable from
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_TO" Set Variable to
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_ACCOUNT" Set Variable account
#... ELSE IF "${protocolField}" == "TSG_FIELD_FTP_URI" Set Variable qname
... ELSE IF "${protocolField}" == "TSG_FIELD_FTP_CONTENT" Set Variable content
... ELSE IF "${protocolField}" == "TSG_FIELD_FTP_ACCOUNT" Set Variable account
#... ELSE IF "${protocolField}" == "TSG_FIELD_QUIC_SNI" Set Variable sni
... ELSE IF "${protocolField}" == "TSG_FIELD_SIP_ORIGINATOR_DESCRIPTION" Set Variable originator
... ELSE IF "${protocolField}" == "TSG_FIELD_SIP_RESPONDER_DESCRIPTION" Set Variable responder
... ELSE IF "${protocolField}" == "TSG_FILED_GTP_PHONE_NUMBER" Set Variable phone_number
... ELSE IF "${protocolField}" == "TSG_SECURITY_SOURCE_ASN" or "${protocolField}" == "TSG_SECURITY_DESTINATION_ASN" Set Variable as_number
... ELSE IF "${protocolField}" == "TSG_FILED_GTP_IMSI" Set Variable imsi
... ELSE IF "${protocolField}" == "TSG_FILED_GTP_APN" Set Variable apn
... ELSE Set Variable ${protocolField}
#... ELSE IF ${protocolField} == "" Set Variable qname
log ${appportol}
${potolId} Get From Dictionary ${appportol} ${appName}
#${attribute} Run Keyword If "${objectSubType}" == "endpoint" or "${temp}" == "True" or "${temp1}" == "True" Create Dictionary attributeValue=${attributeValue} attributeName=${attributeName} attributeType=${attributeType}
${attribute} Run Keyword If "${temp}" == "True" or "${temp1}" == "True" Create Dictionary attributeValue=${attributeValue} attributeName=${attributeName} attributeType=${attributeType}
... ELSE IF "${objectSubType}" == "subscriberid" or "${protocolField}" == "TSG_FILED_GTP_IMSI" or "${protocolField}" == "TSG_FILED_GTP_PHONE_NUMBER" or "${protocolField}" == "TSG_FILED_GTP_APN" Create Dictionary attributeValue=${attributeValue} attributeName=${attributeName} attributeType=${attributeType}
... ELSE IF "${objectSubType}" == "User-Agent" or "${objectSubType}" == "Set-Cookie" or "${objectSubType}" == "Cookie" or "${objectSubType}" == "Content-Type" or "${objectSubType}" == "Connection" or "${objectSubType}" == "ETag" or "${objectSubType}" == "Accept-Encoding" or "${objectSubType}" == "Age" Create Dictionary attributeValue=${attributeValue} attributeName=${attributeName} attributeType=signature protocol=${potolId} appId=${potolId} appName=${appName}
... ELSE Create Dictionary attributeValue=${attributeValue} attributeName=${attributeName} appId=${potolId} appName=${appName} appId=${potolId} appName=${appName} attributeType=${attributeType}
#${attribute} Create Dictionary attributeValue=${itemvalue} attributeName=${attributeName} appId=${potolId} appName=${appName} attributeType=${attributeType}
#协议使用策略中定义协议
#{"verifyList":[{"policyType":"tsg_security","verifySession":{"attributes":[{"attributeType":"string","attributeName":"url","appId":67,"appName":"http","attributeValue":{"string":"http://tsg.internal.geedge.net/#/Trouble_shooting/Policy_Verify?t=1624263064956"}},{"attributeType":"string","attributeName":"host","appId":67,"appName":"http","attributeValue":{"string":"tsg.internale.geedge.net"}},{"attributeType":"string","attributeName":"req_body","appId":67,"appName":"http","attributeValue":{"string":"requestcontent"}},{"attributeType":"string","attributeName":"res_body","appId":67,"appName":"http","attributeValue":{"string":"rescontent"}},{"attributeType":"signature","attributeName":"req_hdr","protocol":67,"appId":67,"appName":"http","attributeValue":{"string":"ua","district":"User-Agent"}},{"attributeType":"signature","attributeName":"req_hdr","protocol":67,"appId":67,"appName":"http","attributeValue":{"string":"ck","district":"Cookie"}},{"attributeType":"signature","attributeName":"res_hdr","protocol":67,"appId":67,"appName":"http","attributeValue":{"string":"sc","district":"Set-Cookie"}},{"attributeType":"signature","attributeName":"res_hdr","protocol":67,"appId":67,"appName":"http","attributeValue":{"string":"ct","district":"Content-Type"}},{"attributeType":"string","attributeName":"app_id","attributeValue":{"string":67}},{"attributeType":"ip","attributeName":"source","attributeValue":{"ip":"192.168.50.10","port":"10000","tableName":"TSG_SECURITY_SOURCE_ADDR","addrType":4,"protocol":"6"}},{"attributeType":"ip","attributeName":"destination","attributeValue":{"ip":"172.16.0.1","port":"80","tableName":"TSG_SECURITY_DESTINATION_ADDR","addrType":4,"protocol":"6"}}]}}]}
#{"verifyList":[{"policyType":"tsg_security","verifySession":{"attributes":[{"attributeType":"string","attributeName":"sni","appId":199,"appName":"ssl","attributeValue":{"string":"sni"}},{"attributeType":"string","attributeName":"san","appId":199,"appName":"ssl","attributeValue":{"string":"san"}},{"attributeType":"string","attributeName":"cn","appId":199,"appName":"ssl","attributeValue":{"string":"cn"}},{"attributeType":"string","attributeName":"app_id","attributeValue":{"string":199}},{"attributeType":"ip","attributeName":"source","attributeValue":{"ip":"192.168.50.10","port":"10000","tableName":"TSG_SECURITY_SOURCE_ADDR","addrType":4,"protocol":"6"}},{"attributeType":"ip","attributeName":"destination","attributeValue":{"ip":"172.16.0.1","port":"80","tableName":"TSG_SECURITY_DESTINATION_ADDR","addrType":4,"protocol":"6"}}]}}]}
[Return] ${attribute}
CreateObjectList
[Documentation] 处理对象
... ${objectData}对象数据,多个对象列表
... ${keyword} 对象创建输入关键字 为后继使用特点对象名称等做准备
... ${appName} 策略中对象引用时传入对应的协议,做策略校验使用
[Arguments] ${objectData} ${keyword}=null ${appName}=null
log ${appName}
Comment 针对位置进行处理
${protocolFieldReturn} ${protocolField} Run Keyword And Ignore Error Get From Dictionary ${objectData} protocolField
${protocolField} Run Keyword If "${protocolField}" == "TSG_FIELD_HTTP_HOST" Set Variable ATTR_SERVER_FQDN
... ELSE IF "${protocolField}" == "TSG_FIELD_DOH_HOST" Set Variable ATTR_DOH_HOST
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_URL" Set Variable ATTR_HTTP_URL
... ELSE IF "${protocolField}" == "TSG_FIELD_FTP_URI" Set Variable ATTR_FTP_URI
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_REQ_HDR" Set Variable ATTR_HTTP_REQ_HDR
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_RES_HDR" Set Variable ATTR_HTTP_RES_HDR
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_REQ_BODY" Set Variable ATTR_HTTP_REQ_BODY
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_RES_BODY" Set Variable ATTR_HTTP_RES_BODY
... ELSE IF "${protocolField}" == "TSG_FIELD_SSL_SNI" Set Variable ATTR_SERVER_FQDN
... ELSE IF "${protocolField}" == "TSG_FIELD_SSL_SAN" Set Variable ATTR_SSL_SAN
... ELSE IF "${protocolField}" == "TSG_FIELD_SSL_CN" Set Variable ATTR_SSL_CN
... ELSE IF "${protocolField}" == "TSG_FIELD_DNS_QNAME" Set Variable ATTR_DNS_QNAME
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_SUBJECT" Set Variable ATTR_MAIL_SUBJECT
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_CONTENT" Set Variable ATTR_MAIL_CONTENT
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_ATT_NAME" Set Variable ATTR_MAIL_ATT_NAME
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_ATT_CONTENT" Set Variable ATTR_MAIL_ATT_CONTENT
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_FROM" Set Variable ATTR_MAIL_FROM
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_TO" Set Variable ATTR_MAIL_TO
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_ACCOUNT" Set Variable ATTR_MAIL_ACCOUNT
... ELSE IF "${protocolField}" == "TSG_FIELD_FTP_CONTENT" Set Variable ATTR_FTP_CONTENT
... ELSE IF "${protocolField}" == "TSG_FIELD_FTP_ACCOUNT" Set Variable ATTR_FTP_ACCOUNT
... ELSE IF "${protocolField}" == "TSG_FIELD_SIP_ORIGINATOR_DESCRIPTION" Set Variable ATTR_SIP_ORIGINATOR_DESCRIPTION
... ELSE IF "${protocolField}" == "TSG_FIELD_SIP_RESPONDER_DESCRIPTION" Set Variable ATTR_SIP_RESPONDER_DESCRIPTION
... ELSE IF "${protocolField}" == "TSG_SECURITY_SOURCE_ADDR" Set Variable ATTR_SOURCE_IP
... ELSE IF "${protocolField}" == "TSG_SECURITY_DESTINATION" Set Variable ATTR_DESTINATION_ADDR
... ELSE IF "${protocolField}" == "TSG_FILED_GTP_IMSI" Set Variable ATTR_GTP_IMSI
... ELSE IF "${protocolField}" == "TSG_FILED_GTP_APN" Set Variable ATTR_GTP_APN
... ELSE IF "${protocolField}" == "TSG_FILED_GTP_PHONE_NUMBER" Set Variable ATTR_GTP_PHONE_NUMBER
log ${objectData}
${objectIds} ${objectList} ${attribute} ${atributeObjectId} CreateObjects ${objectData} ${appName}
#${objectIds} ${objectList} CreateObjects ${objectData}
log ${protocolField}
${objecTemptList} Run Keyword If "${protocolFieldReturn}"=="FAIL" Set Variable ${objectList}
... ELSE IF "${protocolField}" == "ATTR_SOURCE_IP" or "${protocolField}" == "None" or "${protocolField}" == "TSG_SECURITY_SOURCE_LOCATION" or "${protocolField}" == "TSG_SECURITY_SOURCE_ASN" or "${protocolField}" == "ATTR_GTP_IMSI" or "${protocolField}" == "ATTR_GTP_PHONE_NUMBER" or "${protocolField}" == "ATTR_GTP_APN" OrangeFilter ${objectList}
##############destination
... ELSE IF "${protocolField}" == "ATTR_DESTINATION_ADDR" or "${protocolField}" == "TSG_SECURITY_DESTINATION_LOCATION" Set Variable ${objectList}
#filter
... ELSE OrangeFilter ${objectList}
[Return] ${objectIds} ${objecTemptList} ${attribute} ${atributeObjectId}
CreateObjects
[Documentation] 处理对象
[Arguments] ${objectData} ${appName}=null
log ${appName}
Comment 针对位置进行处理
${protocolFieldReturn} ${protocolField} Run Keyword And Ignore Error Get From Dictionary ${objectData} protocolField
${objList} Get From Dictionary ${objectData} objectList
Comment ${objJson}对象模板取自全局变量
${objJson} Set Variable ${objModeJson}
${objectJson} Set Variable ${objListMode}
#JSON处理
${return} ${objectType} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectType
${objectJson} = Run Keyword If "${return}" != "FAIL" and "${objectType}" != "None" Replace String ${objectJson} "type": "ip" "type":"${objectType}"
... ELSE Set Variable ${objectJson}
${return} ${objectSubType} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectSubType
${objectSubType1} Run Keyword If "${objectSubType}"=="endpoint" Set Variable ip
... ELSE Set Variable ${objectSubType}
${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" != "None" Replace String ${objectJson} "sub_type": "ip" "sub_type":"${objectSubType1}"
... ELSE Set Variable ${objectJson}
${return} ${objectId} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectId
${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectId}" != "None" Replace String ${objectJson} "object_id": null "object_id":${objectId}
... ELSE Set Variable ${objectJson}
${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectId}" != "None" Replace String ${objectJson} "op": "add" "op": "update"
... ELSE Set Variable ${objectJson}
Comment 替换vsysid
${objectJson} = Run Keyword If "${vsysId}"!="1" Replace String ${objectJson} "vsys_id": 1 "vsys_id": ${vsysId}
... ELSE Set Variable ${objectJson}
#${objectId} Run Keyword If "${return}"!="FAIL" Set Variable ${objectId} ELSE Set Variable ${EMPTY}
#JSON处理
${objectJsonList} Create List
${objListType} = Evaluate type(${objList})
${itemvalue} Set Variable ${Empty}
${port} Set Variable ${Empty}
FOR ${obj} IN @{objList}
${returnAddItemList} ${addItemList} Run Keyword And Ignore Error Get From Dictionary ${obj} addItemList
log ${addItemList}
Run Keyword If "${returnAddItemList}" == "PASS" and "${addItemList}" == "None" Continue For Loop
${returnUpdateItemList} ${updateItemList} Run Keyword And Ignore Error Get From Dictionary ${obj} updateItemList
Run Keyword If "${returnUpdateItemList}" == "PASS" and "${updateItemList}" == "None" Continue For Loop
${returnDeleteItemIds} ${deleteItemList} Run Keyword And Ignore Error Get From Dictionary ${obj} deleteItemIds
Run Keyword If "${returnDeleteItemIds}" == "PASS" and "${deleteItemList}" == "None" Continue For Loop
${deleteItemList} Run Keyword If "${returnDeleteItemIds}" == "FAIL" Create List
... ELSE Set Variable ${deleteItemList}
${protocolFieldTemp} Run Keyword If "${protocolFieldReturn}" == "FAIL" Set Variable ${Empty}
... ELSE Set Variable ${protocolField}
Comment 处理updateItemList
${itemListJson} ${itemvalue} ${port} ${isHexbin} Run Keyword If "${returnAddItemList}" == "PASS" OrangeObjectItem ${addItemList} ${protocolFieldTemp} ${appName} ${objectSubType} ${itemvalue} ${objectType}
... ELSE IF "${returnUpdateItemList}" == "PASS" and "${addItemList}" != "None" OrangeObjectItem ${updateItemList} ${protocolFieldTemp} ${appName} ${objectSubType} ${itemvalue}
... ELSE IF ${deleteItemList} ${itemvalue}
log ${objectJson}
${objectJsonTemp} = Run Keyword If "${returnAddItemList}" != "FAIL" and "${objectSubType}" == "ip_learning" Replace String ${objectJson} "add_item_list": [null] "add_item_list": [], ${itemListJson}
... ELSE IF "${returnAddItemList}" != "FAIL" Replace String ${objectJson} "member": "object" "member": ${itemListJson}
... ELSE IF "${returnUpdateItemList}" != "FAIL" and "${objectSubType}" == "ip_learning" Replace String ${objectJson} "update_item_list": [null] "update_item_list": [], ${itemListJson}
... ELSE IF "${returnUpdateItemList}" != "FAIL" Replace String ${objectJson} "update_item_list": [null] "update_item_list": ${itemListJson}
... ELSE IF "${returnDeleteItemIds}" != "FAIL" and "${objectSubType}" == "ip_learning" Replace String ${objectJson} "delete_item_ids": [null] "delete_item_ids": [], ${itemListJson}
... ELSE IF "${returnDeleteItemIds}" != "FAIL" Replace String ${objectJson} "delete_item_ids": [null] "delete_item_ids": ${itemListJson}
... ELSE Set Variable ${objectJson}
${objectJsonTemp} = Replace String ${objectJsonTemp} [null] []
${objectJsonTemp} = Replace String ${objectJsonTemp} None null
#Create File ${path}/test.txt ${objectJson}
#Append To File ${path}/test.txt ${objectJson}
${objectJsonList} json.loads ${objectJsonTemp}
# AppendListToList ${objectJsonList} ${objDictionary}
END
log ${objectJsonList}
${return} ${returnCode} Run Keyword And Ignore Error Get From Dictionary ${objectData} returnCode
${returnCode} = Run Keyword If "${return}"=="PASS" Set Variable ${returnCode}
... ELSE Set Variable ${Empty}
${objectData} Run Keyword If ${tsgVersion}>=22.06 Create Dictionary op=add return_data=1 object=${objectJsonList} vsys_id=${vsysId}
... ELSE Create Dictionary op_action=add return_data=1 object_listt=${objectJsonList}
Log !!!!!!!!!!!!!!!!!!!!!!!!!!!!
Log ${itemvalue}
${itemvalue} Run Keyword If "${itemvalue}" != "None" and "${itemvalue}" != "${Empty}" and "${objectSubType}" != "endpoint" and "${objectSubType}" != "ip_learning" and "${objectSubType}" != "geo_location" strip ${itemvalue}
... ELSE Set Variable ${itemvalue}
#0919
${rescode} ${objectIds} ${verifyObjectId} CreateObject ${objectData} ${returnCode} ${itemvalue} ${objectType}
#Should Be Equal As Strings ${rescode} 200
${protocolField} Run Keyword If "${protocolFieldReturn}" == "FAIL" Set Variable ${EMPTY}
... ELSE Set Variable ${protocolField}
${objectsList} Run Keyword If "${protocolField}" != "${EMPTY}" and "${objectIds}" != "[]" ObjectIdsToObjList ${objectIds} ${protocolField}
... ELSE Create List
Log 策略校验数据拼接
#${verifyCondition} Set Variable ${Empty}
#判断IPv4 V6
${isForPolicy} Run Keyword If "${appName}" == "${EMPTY}" or "${appName}" == "null" Set Variable False
... ELSE Set Variable True
${attribute} Run Keyword IF "${isForPolicy}" == "True" and "${itemvalue}" != "${EMPTY}" and "${itemvalue}" != "None" OrangeAttribute ${itemvalue} ${objectSubType} ${protocolField} ${appName} ${port} ${isHexbin}
#${atributeObjectId} Run Keyword IF ${appName}" != "${EMPTY} and "${itemvalue}" != "${EMPTY}" and "${itemvalue}" != "None" and ${addTestClentIPFlag} != 1 Set Variable ${verifyObjectId},
${atributeObjectId} Run Keyword IF "${isForPolicy}" == "True" and "${itemvalue}" != "${EMPTY}" and "${itemvalue}" != "None" Set Variable ${verifyObjectId}
log pass
[Return] ${objectIds} ${objectsList} ${attribute} ${atributeObjectId}
OrangeObjectItem
[Arguments] ${itemList} ${protocolField}=null ${appName}=null ${objectSubType}=null ${itemvalue}=null ${objectType}=null
[Documentation] 处理对象中的新增或修改列表
${isForPolicy} Run Keyword If "${appName}" == "${EMPTY}" or "${appName}" == "null" Set Variable False
... ELSE Set Variable True
Comment 获取troubleshooting验证数据,处理目的地址:目的地址从列表中获取第一个
${temp1} Run Keyword If "${isForPolicy}" == "True" and "${protocolField}" != "${EMPTY}" and "${protocolField}" != "None" aisincludeb TSG_SECURITY_DESTINATION_ADDR ${protocolField}
... ELSE Set Variable ${EMPTY}
Comment 处理源地址ip_learning无法实时做策略校验,所以条件仅有iplearning的不做策略校验,不适合此自动化
log ${isForPolicy}
log ${protocolField}
log ${objectSubType}
log ${itemList}
log ${itemvalue}
${temp} Run Keyword If "${isForPolicy}" == "True" and "${protocolField}" != "${EMPTY}" and "${protocolField}" != "None" and "${objectSubType}" != "ip_learning" aisincludeb TSG_SECURITY_SOURCE_ADDR ${protocolField}
... ELSE Set Variable ${EMPTY}
Comment 如果是目的地址则从目的地址中获取
Comment 如果对象类型为不为IP、SUB ID、Geography、IP Learning、IMSI、Phone Number、APN则统一获取item的第一条记录作为策略校验条件; IPleaning和地域不在策略验证范围内
${itemvalue} ${isHexbin} Run Keyword If "${isForPolicy}" == "True" and "${itemvalue}" == "${Empty}" and "${objectSubType}" == "endpoint" and "${temp}" == "True" GetIPFromIpRangeOrCIDR ${itemList} #如果策略协议不为空;且item不为空,且是endpoint,且是源的位置,添加到策略校验条件参数中
... ELSE IF "${isForPolicy}" == "True" and "${itemvalue}" == "${Empty}" and "${objectSubType}" == "endpoint" and "${temp1}" == "True" GetIPFromIpRangeOrCIDR ${itemList} #如果策略协议不为空;且item不为空,且是endpoint,且是目的位置,添加到策略校验条件参数中
... ELSE IF "${objectSubType}" == "ip_learning" or "${objectSubType}" == "geo_location" Set Variable ${Empty} 0
... ELSE IF "${isForPolicy}" == "True" and "${itemvalue}" == "${Empty}" and "${objectSubType}" != "ip_learning" and "${objectSubType}" != "geo_location" and ${addTestClentIPFlag} != 1 GetFirstFromItemList ${itemList} #如果策略协议不为空;且item不为空,且是不是ip_learning和geo_location,且有默认客户端信息那,添加到策略校验条件参数中
... ELSE IF "${isForPolicy}" == "True" and "${protocolField}" == "None" and "${temp1}" == "${EMPTY}" GetFirstFromItemList ${itemList} #目的subid处理,如果策略协议不为空;且item不为空,是目的位置的subid,添加到策略校验条件参数中
... ELSE IF "${isForPolicy}" == "True" and "${protocolField}" != "None" and "${temp1}" == "False" and "${temp}" == "False" GetFirstFromItemList ${itemList} #filter条件处理,如果策略协议不为空;且item不为空
... ELSE IF "${isForPolicy}" == "True" Set Variable ${itemvalue} #如果是一个对象的多个itemlist则不重复添加
... ELSE Set Variable ${Empty} 0
${port} Run Keyword If "${isForPolicy}" == "True" GetPortFromItemList ${itemList} ${protocolField}
... ELSE Set Variable 8080
#${itemvalue} Run Keyword If ${appName}" != "${EMPTY} and "itemvalue" != "${Empty}" and "${objectSubType}" != "endpoint" and "${objectSubType}" != "ip_learning" and "${objectSubType}" != "geo_location" GetFirstFromItemList ${itemList}
#... ELSE IF ${appName}" != "${EMPTY} and "${objectSubType}" == "endpoint" and "${temp1}" == "False" Set Variable ${testClentIP}
#... ELSE IF ${appName}" != "${EMPTY} and "${objectSubType}" == "endpoint" and "${temp1}" == "True" GetIPFromIpRangeOrCIDR ${itemList}
#... ELSE Set Variable ${Empty}
Comment 处理keywordArray
log ${itemList}
${items} Run Keyword If "${objectType}"!="ip" JoinKeywordsData ${itemList} ${objectType} ${objectSubType}
... ELSE JoinIpData ${itemList}
${itemListJson} json.Dumps ${items}
${itemListJson} = Run keyword IF "${objectSubType}" == "endpoint" Replace String ${itemListJson} testClentIP ${testClentIP}
... ELSE Set Variable ${itemListJson}
#${objectJson} = Replace String ${objectJson} "addItemList": "addItemList":${itemList}
${itemListJson} = Run Keyword If "${objectSubType}" == "ip_learning" Replace String ${itemListJson} [{" "
... ELSE Set Variable ${itemListJson}
${itemListJson} = Run Keyword If "${objectSubType}" == "ip_learning" Replace String ${itemListJson} "}] "
... ELSE Set Variable ${itemListJson}
[Return] ${itemListJson} ${itemvalue} ${port} ${isHexbin}
JoinIpData
[Arguments] ${itemList}
${items} Create List
FOR ${item} IN @{itemList}
${ip_address} Get From Dictionary ${item} ip
${port} Get From Dictionary ${item} port
${ip} Create Dictionary ip_address=${ip_address} port_range=${port}
${ip} Create Dictionary ip=${ip} op=add
Append To List ${items} ${ip}
END
${items} Create Dictionary items=${items} type=1
[Return] ${items}
JoinKeywordsData
[Arguments] ${itemList} ${objectType} ${objectSubType}
${items} Create List
FOR ${item} IN @{itemList}
${patterns} Create List
${return} ${itemValue} Run Keyword And Ignore Error Get From Dictionary ${item} keywordArray
${keywords} Set Variable ${itemValue[0]}
${keywords} Create Dictionary keywords=${keywords}
# Set To Dictionary ${keywords} keywords=${keywords}
Append To List ${patterns} ${keywords}
${patterns} Create Dictionary patterns=${patterns}
${context_name} Run Keyword If "${objectType}" == "http_signature" Set Variable ${objectSubType}
${string} Run Keyword If "${objectType}" == "fqdn" or "${objectType}" == "account" or "${objectType}" == "keywords" or "${objectType}" == "url" Create Dictionary string=${patterns} op=add
... ELSE IF "${objectType}" == "http_signature" Create Dictionary contextual_string=${patterns} op=add
Run Keyword If "${objectType}" == "http_signature" Set To Dictionary ${string['contextual_string']} context_name=${context_name}
... ELSE Log ${string}
Append To List ${items} ${string}
log ${patterns}
END
${items} Create Dictionary items=${items} type=item
# ${member} Create Dictionary member=${items}
# ${member} json.dumps ${member}
# log ${member}
log ${keywords}
[Return] ${items}
GetFirstFromItemList
[Arguments] ${addItemList}
[Documentation] 从测试数据对象中获取第一个item作为测试参数
${itemValue} Set Variable ${Empty}
${return} Set Variable ${Empty}
FOR ${item} IN @{addItemList}
${return} ${itemValue} Run Keyword And Ignore Error Get From Dictionary ${item} keywordArray
${returnIsHexbin} ${isHexbin} Run Keyword And Ignore Error Get From Dictionary ${item} isHexbin
Exit For Loop If "${return}" == "FAIL" or "${itemValue}" != "${EMPTY}"
END
${temp} Run Keyword If "${return}" == "PASS" and "${itemValue}" != "${EMPTY}" GetFirstFromList ${itemValue}
${isHexbin} Run Keyword If "${returnIsHexbin}" == "PASS" and "${isHexbin}" == "1" Set Variable ${isHexbin}
... ELSE Set Variable 0
[Return] ${temp} ${isHexbin}
GetFirstFromList
[Arguments] ${list}
[Documentation] 从测试数据对象中获取第一个item作为测试参数
${tempValue} Set Variable ${Empty}
Log $$$$$$$$$$$$$$$$$$$$$$$GetFirstFromList:${list}
FOR ${item1} IN @{list}
${tempValue} Set Variable ${item1}
Exit For Loop If "${tempValue}" != "${EMPTY}"
END
${len} Get Length ${tempValue}
[Return] ${tempValue}
GetIPFromIpRangeOrCIDR
[Arguments] ${addItemList}
[Documentation] 从测试数据对象中获取第一个item作为测试参数
${itemValue} Set Variable ${Empty}
${isHexbin} Set Variable 0
FOR ${item} IN @{addItemList}
log ${item}
${itemValue} Get From Dictionary ${item} ip
@{List} Split String ${itemValue} /
${itemValue} Get From List ${List} 0
@{List} Split String ${itemValue} -
${itemValue} Get From List ${List} 0
Exit For Loop If "${itemValue}" != "${EMPTY}"
END
[Return] ${itemValue} ${isHexbin}
GetPortFromItemList
[Arguments] ${addItemList} ${protocolField}
[Documentation] 从测试数据对象中获取第一个item作为测试参数
${portTemp} Set Variable ${Empty}
${return} Set Variable ${Empty}
FOR ${item} IN @{addItemList}
log ${item}
${return} ${portTemp} Run Keyword And Ignore Error Get From Dictionary ${item} port
Exit For Loop If "${return}" != "FAIL" or "${portTemp}" != "${EMPTY}"
END
${temp} Run Keyword If "${protocolField}" != "None" aisincludeb TSG_SECURITY_SOURCE ${protocolField}
... ELSE Set Variable False
${temp1} Run Keyword If "${protocolField}" != "None" aisincludeb TSG_SECURITY_DESTINATION ${protocolField}
... ELSE Set Variable False
Comment 如果条件是IP端口处理
Log 888888888888888888888888888888888888888888888888:${portTemp}
${port1} Run Keyword If "${return}" == "FAIL" Set Variable ${Empty}
... ELSE IF "${portTemp}" != "${Empty}" and "${portTemp}" != "None" GetPortFromPortRange ${portTemp}
... ELSE IF "${temp}" == "True" Set Variable 10000
... ELSE IF "${temp1}" == "True" Set Variable 80
... ELSE Set Variable 8080
Log ${port1}
[Return] ${port1}
ObjectIdsToObjList
[Tags]
[Arguments] ${objectIds} ${protocolField}
[Documentation] 参数${objectIds}对象id
... 参数:对象在策略中的位置
... 返回对象id在策略中的位置list
${objectsList} Create List
# FOR ${obj} IN @{objectIds}
# ${obj} Evaluate int(${obj})
# ${objectList} Create Dictionary object_id=${obj} protocol_field=${protocolField}
# Append To List ${objectsList} ${objectList}
# END
${protocolField} Run Keyword If "${protocolField}" == "TSG_FIELD_HTTP_HOST" Set Variable ATTR_SERVER_FQDN
... ELSE IF "${protocolField}" == "TSG_FIELD_DOH_HOST" Set Variable ATTR_DOH_HOST
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_URL" Set Variable ATTR_HTTP_URL
... ELSE IF "${protocolField}" == "TSG_FIELD_FTP_URI" Set Variable ATTR_FTP_URI
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_REQ_HDR" Set Variable ATTR_HTTP_REQ_HDR
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_RES_HDR" Set Variable ATTR_HTTP_RES_HDR
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_REQ_BODY" Set Variable ATTR_HTTP_REQ_BODY
... ELSE IF "${protocolField}" == "TSG_FIELD_HTTP_RES_BODY" Set Variable ATTR_HTTP_RES_BODY
... ELSE IF "${protocolField}" == "TSG_FIELD_SSL_SNI" Set Variable ATTR_SERVER_FQDN
... ELSE IF "${protocolField}" == "TSG_FIELD_SSL_SAN" Set Variable ATTR_SSL_SAN
... ELSE IF "${protocolField}" == "TSG_FIELD_SSL_CN" Set Variable ATTR_SSL_CN
... ELSE IF "${protocolField}" == "TSG_FIELD_DNS_QNAME" Set Variable ATTR_DNS_QNAME
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_SUBJECT" Set Variable ATTR_MAIL_SUBJECT
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_CONTENT" Set Variable ATTR_MAIL_CONTENT
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_ATT_NAME" Set Variable ATTR_MAIL_ATT_NAME
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_ATT_CONTENT" Set Variable ATTR_MAIL_ATT_CONTENT
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_FROM" Set Variable ATTR_MAIL_FROM
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_TO" Set Variable ATTR_MAIL_TO
... ELSE IF "${protocolField}" == "TSG_FIELD_MAIL_ACCOUNT" Set Variable ATTR_MAIL_ACCOUNT
... ELSE IF "${protocolField}" == "TSG_FIELD_FTP_CONTENT" Set Variable ATTR_FTP_CONTENT
... ELSE IF "${protocolField}" == "TSG_FIELD_FTP_ACCOUNT" Set Variable ATTR_FTP_ACCOUNT
... ELSE IF "${protocolField}" == "TSG_FIELD_SIP_ORIGINATOR_DESCRIPTION" Set Variable ATTR_SIP_ORIGINATOR_DESCRIPTION
... ELSE IF "${protocolField}" == "TSG_FIELD_SIP_RESPONDER_DESCRIPTION" Set Variable ATTR_SIP_RESPONDER_DESCRIPTION
... ELSE IF "${protocolField}" == "TSG_SECURITY_SOURCE_ADDR" Set Variable ATTR_SOURCE_IP
... ELSE IF "${protocolField}" == "TSG_SECURITY_DESTINATION" Set Variable ATTR_DESTINATION_ADDR
... ELSE IF "${protocolField}" == "TSG_FILED_GTP_IMSI" Set Variable ATTR_GTP_IMSI
... ELSE IF "${protocolField}" == "TSG_FILED_GTP_APN" Set Variable ATTR_GTP_APN
... ELSE IF "${protocolField}" == "TSG_FILED_GTP_PHONE_NUMBER" Set Variable ATTR_GTP_PHONE_NUMBER
FOR ${obj} IN @{objectIds}
${obj} Evaluate int(${obj})
# ${objectList} Create Dictionary object_id=${obj} protocol_field=${protocolField}
${object_id_list} Create List
Append To List ${object_id_list} ${obj}
${objectList} Create Dictionary object_ids=${object_id_list}
Append To List ${objectsList} ${objectList}
${objectsList} Create Dictionary objects=${objectsList} attribute_name=${protocolField} is_negate=${0}
END
Log objectsList:${objectsList}
[Return] ${objectsList}
CreateObject
[Arguments] ${ipList} ${code}=null ${verifyValue}=null ${objectType}=null
[Documentation] 参数${ipList}对象dict
... ${code} 输入对象应返回参数,为空则代表200
Comment 创建IP
${returnData} Get From Dictionary ${ipList} return_data
${bodyJson} json.Dumps ${ipList}
log ${bodyJson}
#${bodyJson} = Replace String ${bodyJson} [null] []
${response} BasePostRequestForV2 ${objectUrl} ${bodyJson} ${version}
${rescode} Set Variable ${response['code']}
Run Keyword If "${code}" == "${Empty}" Should Be Equal As Strings ${rescode} 200
... ELSE Should Be Equal As Strings ${rescode} ${code}
${addObjectIds} Run Keyword If "${rescode}"=="200" and "${returnData}" == "1" getObjectListIds ${response}
... ELSE Create List
${createIpIds} Run Keyword IF "${createIpIds}" != "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "ip" AppendListToList ${createIpIds} ${addObjectIds}
... ELSE IF "${createIpIds}" == "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "ip" Set Variable ${addObjectIds}
${createFqdnIds} Run Keyword IF "${createFqdnIds}" != "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "fqdn" AppendListToList ${createFqdnIds} ${addObjectIds}
... ELSE IF "${createFqdnIds}" == "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "fqdn" Set Variable ${addObjectIds}
${createHttpSignatureIds} Run Keyword IF "${createHttpSignatureIds}" != "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "http_signature" AppendListToList ${createHttpSignatureIds} ${addObjectIds}
... ELSE IF "${createHttpSignatureIds}" == "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "http_signature" Set Variable ${addObjectIds}
${createKeywordsIds} Run Keyword IF "${createKeywordsIds}" != "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "keywords" AppendListToList ${createKeywordsIds} ${addObjectIds}
... ELSE IF "${createKeywordsIds}" == "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "keywords" Set Variable ${addObjectIds}
${createUrlIds} Run Keyword IF "${createUrlIds}" != "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "url" AppendListToList ${createUrlIds} ${addObjectIds}
... ELSE IF "${createUrlIds}" == "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "url" Set Variable ${addObjectIds}
${createAccountIds} Run Keyword IF "${createAccountIds}" != "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "account" AppendListToList ${createAccountIds} ${addObjectIds}
... ELSE IF "${createAccountIds}" == "${EMPTY}" and "${addObjectIds}" != "${EMPTY}" and "${objectType}" == "account" Set Variable ${addObjectIds}
Run Keyword If "${objectType}" == "ip" SET GLOBAL VARIABLE ${createIpIds} ${createIpIds}
... ELSE IF "${objectType}" == "fqdn" SET GLOBAL VARIABLE ${createFqdnIds} ${createFqdnIds}
... ELSE IF "${objectType}" == "http_signature" SET GLOBAL VARIABLE ${createHttpSignatureIds} ${createHttpSignatureIds}
... ELSE IF "${objectType}" == "keywords" SET GLOBAL VARIABLE ${createKeywordsIds} ${createKeywordsIds}
... ELSE IF "${objectType}" == "url" SET GLOBAL VARIABLE ${createUrlIds} ${createUrlIds}
... ELSE IF "${objectType}" == "account" SET GLOBAL VARIABLE ${createAccountIds} ${createAccountIds}
${objectIdTemp} Run Keyword IF "${verifyValue}" != "${Empty}" and "${verifyValue}" != "None" GetObjectVerifyId ${response} ${verifyValue}
... ELSE Set Variable ${EMPTY}
Log addObjectIds:${addObjectIds}
[Return] ${rescode} ${addObjectIds} ${objectIdTemp}
GetObjectVerifyId
[Documentation]
... 获取结果中用于策略校验的对象ID
[Arguments] ${value} ${verifyValue}
Log Call Get-ObjectIds
${objectId} Set Variable ${EMPTY}
${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data
Return From Keyword If "${return}"=="FAIL" ${objectIdsTemp}
Log %%%%%%%%%%%%%%:${verifyValue}
# FOR ${object} IN @{value['data']['object_list']}
# ${object1} json.Dumps ${object}
# ${verifyValue} Replace String ${verifyValue} & \\&
# ${verifyValue} Replace String ${verifyValue} $ \\$
# ${verifyValue} Replace String ${verifyValue} * \\*
# ${temp} aisincludeb ${verifyValue} ${object1}
# ${objectId} Run Keyword IF "${temp}"=="True" Set Variable ${object['object_id']}
# ... ELSE Set Variable ${EMPTY}
# Exit For Loop If "${temp}"=="True"
# END
${objectId} Set Variable ${data['object']['id']}
[Return] ${objectId}
GetIniCategoryId
[Arguments] ${categoryName}
Connect To Database Using Custom Params pymysql ${mysqlHost}
${iniCategoryId} query SELECT group_id FROM tsg_obj_fqdn_cat WHERE low_boundary IN (SELECT category_id FROM tsg_category_dict WHERE category_name='${categoryName}') AND is_initialize=1
Disconnect From Database
${iniCategoryId} Set Variable ${iniCategoryId}[0][0]
[Return] ${iniCategoryId}
DeleteGroupObjects
[Arguments] ${objectids}
FOR ${var} IN @{objectids}
log ${var}
DeleteGroupObject ${var}
END
DeleteGroupObject
[Arguments] ${objectids}
#删除对象
log todeleteobjAndCategory
${response} BaseDeleteRequest /${version}/policy/object {"objectIds":${objectids},"vsysId":${vsysId}}
${response_code} Get From Dictionary ${response} code
Should Be Equal As Strings ${response_code} 200
${response} Convert to String ${response}
log ${response}
DeleteGroupCategories
[Arguments] ${categoryids}
FOR ${var} IN @{categoryids}
log ${var}
DeleteGroupCategory ${var}
END
DeleteGroupCategory
[Arguments] ${categoryids}
#删除对象
log todeleteobjAndCategory
${response} BaseDeleteRequest /${version}/category/dict {"categoryIds":${categoryids},"vsysId":${vsysId}}
${response_code} Get From Dictionary ${response} code
Should Be Equal As Strings ${response_code} 200
${response} Convert to String ${response}
log ${response}
DeleteObject
[Arguments] ${objectids}
#删除对象
log todeleteobj
${response} BaseDeleteRequest /${version}/policy/object {"objectIds":[${objectids}]}
${response_code} Get From Dictionary ${response} code
Should Be Equal As Strings ${response_code} 200
${response} Convert to String ${response}
log ${response}
SearchObjectWithAccessToken
[Arguments] ${requestUri} ${data} ${accessToken} ${apiVersion} ${code}
${response} BaseGetRequestWithToken ${requestUri} ${data} ${accessToken} ${apiVersion} ${code}
${response_code} Get From Dictionary ${response} code
Should Be Equal As Strings ${response_code} ${code}
[Return] ${response_code}
|