Commit 87517def by fanxun

sso结构调整

parent f8fdf32c
...@@ -73,3 +73,4 @@ class SSOConfig(BaseConfig): ...@@ -73,3 +73,4 @@ class SSOConfig(BaseConfig):
sso_url = r'http://testtbdzj.hikcreate.com/web/auth/users/login' # sso登录地址 sso_url = r'http://testtbdzj.hikcreate.com/web/auth/users/login' # sso登录地址
sso_salt = 'hikcreate_xj' # SSO盐值 sso_salt = 'hikcreate_xj' # SSO盐值
sso_token = '' sso_token = ''
header = {}
import pytest,time import pytest,time
import requests import requests
from config import BaseConfig from config import SSOConfig
from common.utils.encryption import Encryption from common.utils.encryption import Encryption
# from common.utils.getExcelData import get_excelData # from common.utils.getExcelData import get_excelData
from common.tools import request_main from common.tools import request_main
...@@ -14,13 +14,13 @@ class SSOLogin(): ...@@ -14,13 +14,13 @@ class SSOLogin():
"""SSO登录""" """SSO登录"""
def _sso_pwd_encrypted(self, org_pwd): def _sso_pwd_encrypted(self, org_pwd):
"""md5加密""" """md5加密"""
encrypted_password = Encryption().get_md5(org_pwd, salt=BaseConfig.salt) encrypted_password = Encryption().get_md5(org_pwd, salt=SSOConfig.sso_salt)
return encrypted_password return encrypted_password
def sso_login(self,url, method, headers=None): def sso_login(self,url, method='post', headers=None):
"""SSO登录获取token""" """SSO登录获取token"""
encrypted_password = self._sso_pwd_encrypted(BaseConfig.password) encrypted_password = self._sso_pwd_encrypted(SSOConfig.sso_password)
req_data = {f"loginName":BaseConfig.username,"password":encrypted_password} req_data = {f"loginName":SSOConfig.sso_username,"password":encrypted_password}
res = request_main(url, headers, method, req_data) res = request_main(url, headers, method, req_data)
return res['data']['token'] return res['data']['token']
......
...@@ -4,12 +4,11 @@ import pytest ...@@ -4,12 +4,11 @@ import pytest
from config import SSOConfig from config import SSOConfig
from common.utils.encryption import Encryption from common.utils.encryption import Encryption
from common.tools import request_main from common.tools import request_main
from service.login import SSOLogin
@pytest.fixture(scope='module', autouse=True) @pytest.fixture(scope='module', autouse=True)
def sso_login(): def sso_login():
"""SSO登录获取token""" """SSO登录获取token"""
encrypted_password = Encryption().get_md5(SSOConfig.sso_password, salt=SSOConfig.sso_salt) sso_token = SSOLogin().sso_login(url=SSOConfig.sso_url)
req_data = {"loginName": SSOConfig.sso_username, "password": encrypted_password} setattr(SSOConfig, 'sso_token', sso_token)
res = request_main(SSOConfig.sso_url, headers=None, method='post', data=req_data) \ No newline at end of file
setattr(SSOConfig, 'sso_token', res['data']['token'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment