Skip to content

Commit

Permalink
raise pyjwt version (#11350)
Browse files Browse the repository at this point in the history
* raise pyjwt version

* fix test

* restrict py>=3

* try to fix Py27 tests

* skip tests

* wip
  • Loading branch information
memsharded authored May 30, 2022
1 parent b7aed80 commit b9105af
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
1 change: 0 additions & 1 deletion conans/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
PyJWT>=1.4.0, <2.0.0
requests>=2.25, <3.0.0
urllib3>=1.26.6, <1.27
colorama>=0.3.3, <0.5.0
Expand Down
1 change: 1 addition & 0 deletions conans/requirements_server.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Server
bottle>=0.12.8, < 0.13
pluginbase>=0.5
PyJWT>=2.4.0, <3.0.0
3 changes: 2 additions & 1 deletion conans/server/crypto/jwt/jwt_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from calendar import timegm

import jwt

Expand All @@ -20,7 +21,7 @@ def get_token_for(self, profile_fields=None):
profile_fields = profile_fields or {}

if self.expire_time:
profile_fields["exp"] = datetime.utcnow() + self.expire_time
profile_fields["exp"] = timegm((datetime.utcnow() + self.expire_time).timetuple())

return jwt.encode(profile_fields, self.secret, algorithm="HS256")

Expand Down
3 changes: 3 additions & 0 deletions conans/server/launcher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python
import os
import sys

from conans import SERVER_CAPABILITIES, REVISIONS
from conans.paths import conan_expand_user
Expand All @@ -16,6 +17,8 @@

class ServerLauncher(object):
def __init__(self, force_migration=False, server_dir=None):
if sys.version_info.major == 2:
raise Exception("The conan_server needs Python>=3 for running")
self.force_migration = force_migration
if server_dir:
user_folder = server_folder = server_dir
Expand Down
6 changes: 2 additions & 4 deletions conans/server/service/v1/upload_download_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_file_path(self, filepath, token):
logger.debug("Get file: user=%s path=%s" % (user, filepath))
file_path = os.path.normpath(os.path.join(self.base_store_folder, encoded_path))
return file_path
except (jwt.ExpiredSignature, jwt.DecodeError, AttributeError):
except (jwt.ExpiredSignatureError, jwt.DecodeError, AttributeError):
raise NotFoundException("File not found")

def put_file(self, file_saver, abs_filepath, token, upload_size):
Expand All @@ -46,7 +46,7 @@ def put_file(self, file_saver, abs_filepath, token, upload_size):
os.remove(abs_filepath)
file_saver.save(os.path.dirname(abs_filepath))

except (jwt.ExpiredSignature, jwt.DecodeError, AttributeError):
except (jwt.ExpiredSignatureError, jwt.DecodeError, AttributeError):
raise NotFoundException("File not found")

def _valid_path(self, filepath, encoded_path):
Expand All @@ -59,5 +59,3 @@ def _valid_path(self, filepath, encoded_path):
return True
else:
return False


6 changes: 3 additions & 3 deletions conans/server/store/disk_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from conans.client.tools.env import no_op
from conans.errors import NotFoundException
from conans.util.files import decode_text, md5sum, path_exists, relative_dirs, rmdir
from conans.util.files import md5sum, path_exists, relative_dirs, rmdir


class ServerDiskAdapter(object):
Expand Down Expand Up @@ -33,7 +33,7 @@ def get_download_urls(self, paths, user=None):
url_path = url_path.replace("\\", "/")
# FALTA SIZE DEL FICHERO PARA EL UPLOAD URL!
signature = self.updown_auth_manager.get_token_for(url_path, user)
url = "%s/%s?signature=%s" % (self.base_url, url_path, decode_text(signature))
url = "%s/%s?signature=%s" % (self.base_url, url_path, signature)
ret[filepath] = url

return ret
Expand All @@ -51,7 +51,7 @@ def get_upload_urls(self, paths_sizes, user=None):
url_path = url_path.replace("\\", "/")
# FALTA SIZE DEL FICHERO PARA EL UPLOAD URL!
signature = self.updown_auth_manager.get_token_for(url_path, user, filesize)
url = "%s/%s?signature=%s" % (self.base_url, url_path, decode_text(signature))
url = "%s/%s?signature=%s" % (self.base_url, url_path, signature)
ret[filepath] = url

return ret
Expand Down
2 changes: 1 addition & 1 deletion conans/test/unittests/server/crypto/jwt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_jwt_manager(self):

# Now wait 2 seconds and check if its valid now
time.sleep(2)
self.assertRaises(jwt.ExpiredSignature, manager.get_profile, token)
self.assertRaises(jwt.ExpiredSignatureError, manager.get_profile, token)

def test_jwt_credentials_manager(self):
manager = JWTCredentialsManager(self.secret, self.expire_time)
Expand Down

0 comments on commit b9105af

Please sign in to comment.