This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
dongxiaoyan-tsg-autotest/02-Keyword/tsg_bfapi/LoginLogout.robot

121 lines
4.7 KiB
Plaintext
Raw Normal View History

2020-04-01 12:42:05 +08:00
*** Settings ***
Resource ../../03-Variable/BifangApiVariable.txt
Resource ../../03-Variable/ApplicationID.txt
Library REST http://${host}:${port}
2020-04-01 12:42:05 +08:00
Library Collections
Library SSHLibrary
Resource PolicyObject.robot
2020-05-29 20:17:44 +08:00
Resource ../tsg_ui/logout/Logout.robot
Resource ../tsg_ui/login/Login.robot
#Resource ../../02-Keyword/tsg_bfapi/PolicyObject.robot
Resource ../../02-Keyword/tsg_bfapi/policy_object/Policy.robot
2020-04-01 12:42:05 +08:00
Resource Tag.robot
*** Keywords ***
Login
[Tags] tsg_adc tsg_bf_api
2020-04-01 12:42:05 +08:00
#[Arguments] ${username} ${password} ${authmode} ${authCode} ${ldapId}
# 毕方接口用户名密码
GET /${version}/user/encryptpwd?password=${password}
2020-04-01 12:42:05 +08:00
Object response body
#OUTPUT response body
#${rescode} Integer $.code
Integer $.code 200
#log ${rescode}
${pwd} String $.data.encryptpwd
#log ${pwd}
${pwdstr} Get From List ${pwd} 0
#log aaaaaaa
log ${pwdstr}
#log bbb
SET GLOBAL VARIABLE ${encodePassword} ${pwdstr}
#log aaaaaaa
log ${encodePassword}
#log aaaaaaa
#log ${host}:${port}
#getToken##################################################################################
#log ${username}
#log ${pwdstr}
POST /${version}/user/login?username=${username}&password=${encodePassword}&authMode=${authmode}
2020-04-01 12:42:05 +08:00
Object response body
#OUTPUT response body
Integer $.code 200
#${rescodelist} Integer $.code
#${rescode} Get From List ${rescodelist} 0
${rescode} Integer $.code
log ${rescode}
${tokenGlobal} String $.data.token
${tokenStr} Get From List ${tokenGlobal} 0
log ${tokenStr}
SET GLOBAL VARIABLE ${token} ${tokenStr}
log ${token}
SET GLOBAL VARIABLE ${headers} {"Contest-Type":"application/json","Authorization":"${token}"}
#Return ${rescode}
Logout
[Tags] tsg_adc tsg_bf_api
POST /${version}/user/logout headers=${headers}
2020-04-01 12:42:05 +08:00
Object response body
Integer $.code 200
${rescode} Integer $.code
#[Return] ${rescode}
ApiLoginAndAddLocalIP
[Tags] tsg_adc tsg_bf_api
log ApiLoginAndAddLocalIP
2020-04-01 12:42:05 +08:00
loginlogout.Login
#log **********
Run Keyword If ${addTestClentIPFlag}==1 AddLocalIPObject
log ApiLoginAndAddLocalIP
#ApiAddAutoTagsCase
#[Return] ${rescode}
#添加tsgUIAPI
Run Keyword If ${addTsgUIAPIFlag}==1 SecurityPolicy-Allow-TSGUIAPI-Add
2020-04-01 12:42:05 +08:00
ApiLogoutAndDelLocalIP
[Tags] tsg_adc tsg_bf_api
log ApiLogoutAndDelLocalIP
2020-04-01 12:42:05 +08:00
log to_LogoutAndDelLocalIP_LogoutAndDelLocalIP
#删除tsgUIAPI 先删除白名单是因为此策略也引用了本机IP
Run Keyword If ${addTsgUIAPIFlag}==1 SecurityPolicy-Allow-TSGUIAPI-DEL
2020-04-01 12:42:05 +08:00
Run Keyword If ${addTestClentIPFlag}==1 DelLocalIPObject
2020-04-01 12:42:05 +08:00
#ApiDeleteAutoTagsCase
loginlogout.Logout
#[Return] ${rescode}
CliLogin
[Tags] tsg_cli cli_login
2020-04-01 12:42:05 +08:00
Open Connection ${cliHost}
SSHLibrary.Login ${cliUsername} ${cliPassword}
CliLogout
[Tags] tsg_cli cli_logout
2020-04-01 12:42:05 +08:00
Close Connection
2020-04-13 19:29:32 +08:00
Log Close CLI Connection
SecurityPolicy-Allow-TSGUIAPI-Add
[Tags] uiallow
log toAddTSGUIAPI
${addItemList1} Create Dictionary isSession=endpoint ip=${host}/32 port=0-0 direction=0 protocol=0 isInitialize=0
#可以添加多个
${addItemLists} Create list ${addItemList1}
#objectList对象
${objectDict} Create Dictionary objectType=ip objectSubType=endpoint isValid=${1} addItemList=${addItemLists}
${rescode} ${objectId} AddObjects ${1} ${objectDict}
SET GLOBAL VARIABLE ${testBifangIP} ${objectId}
Comment 创建安全策略
${policyDict} Create Dictionary policyName=SecurityPolicy-Allow-TSGUIAPI policyType=tsg_security policyDesc=autotest action=allow destination=${objectId}|TSG_SECURITY_DESTINATION_ADDR userRegion={} isValid=${1} appIdObjects=${HTTP_ID},${SSL_ID}
log ${policyDict}
${rescode} ${policyId} AddPolicies 1 ${policyDict} v2
SET GLOBAL VARIABLE ${testBifangPolicy} ${policyId}
log addTSGUIAPISucess
SecurityPolicy-Allow-TSGUIAPI-DEL
[Tags] uiallow
log toDelTSGUIAPI
#${policyId1} set Variable {"policyType":"tsg_security","policyIds":[${testBifangPolicy}]}
#${policyIds} Create List ${testBifangPolicy}
DeletePolicyAndGroupObject ${testBifangPolicy} ${testBifangIP}
log delTSGUIAPISucess