esirius: ignore DES timestamp within tests (#53697)
This commit is contained in:
parent
8b1afe9109
commit
59186c7cf9
|
@ -14,10 +14,16 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import base64
|
||||
import json
|
||||
import httmock
|
||||
import pytest
|
||||
|
||||
from Cryptodome.Cipher import DES
|
||||
from Cryptodome.Util.Padding import pad, unpad
|
||||
|
||||
from django.utils.encoding import force_bytes
|
||||
|
||||
from passerelle.apps.esirius.models import ESirius
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -106,14 +112,19 @@ def test_token(connector):
|
|||
connector.request('an/uri/', method='get', params="somes")
|
||||
|
||||
|
||||
@pytest.mark.parametrize('secret_key', ['xxx', ''])
|
||||
@pytest.mark.parametrize('secret_key', ['yyy', ''])
|
||||
def test_pre_request(connector, secret_key):
|
||||
@httmock.urlmatch(netloc='esirius.example.net', path='/an/uri/', method='GET')
|
||||
def esirius_mock(url, request):
|
||||
assert request.headers['Accept'] == 'application/json; charset=utf-8'
|
||||
assert bool(request.headers.get('token_info_caller')) == bool(secret_key)
|
||||
if secret_key:
|
||||
assert request.headers['token_info_caller'][:42] == b'f3G6sjRZETBam6vcdrAxmvJQTX5hh6OjZ8XlUO6SMo'
|
||||
des_key = pad(force_bytes(secret_key), 8)[:8]
|
||||
cipher = DES.new(des_key, DES.MODE_ECB)
|
||||
msg = cipher.decrypt(base64.b64decode(request.headers['token_info_caller']))
|
||||
token = json.loads(unpad(msg, 8))
|
||||
assert set(token) == {'caller', 'createInfo'}
|
||||
assert token['caller'] == connector.secret_id
|
||||
return httmock.response(200)
|
||||
|
||||
connector.secret_key = secret_key
|
||||
|
|
Loading…
Reference in New Issue