From 476f4ce243a41f50f7614851f9542f7ceca8ec63 Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Wed, 17 Feb 2021 13:03:29 +0000 Subject: [PATCH] Encode pubkey in validators Follow up change for py2->py3 migration. The pubkey must be encoded in order to avoid 'data must be bytes-like' error. The key is a type of str which in py2 meant bytes, however, in py3 it's just string. Therefore the pubkey must be encoded before it's passed to load_ssh_public_key which requires bytes-like data. Change-Id: I943438a59923bd9c4e9dd38058020e49fd2f3d24 --- refstack/api/validators.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/refstack/api/validators.py b/refstack/api/validators.py index 1b797ad4..3150fa84 100644 --- a/refstack/api/validators.py +++ b/refstack/api/validators.py @@ -126,8 +126,14 @@ class TestResultValidator(BaseValidator): raise api_exc.ValidationError('Malformed signature', e) try: + pubkey = request.headers.get('X-Public-Key', '') + try: + pubkey.encode('utf-8') + except AttributeError: + # it's already in bytes + pass key = load_ssh_public_key( - request.headers.get('X-Public-Key', ''), + pubkey, backend=backends.default_backend() ) except (binascii.Error, ValueError) as e: