update(security_test.py): moving tests to new framework
We should be moving tests over to pytest [none]
This commit is contained in:
parent
0b51ea34b1
commit
85bcb63439
7 changed files with 190 additions and 107 deletions
53
app.py
53
app.py
|
@ -21,10 +21,12 @@ from data import model
|
|||
from data.archivedlogs import LogArchive
|
||||
from data.billing import Billing
|
||||
from data.buildlogs import BuildLogs
|
||||
from data.model.user import LoginWrappedDBUser
|
||||
from data.queue import WorkQueue, BuildMetricQueueReporter
|
||||
from data.userevent import UserEventsBuilderModule
|
||||
from data.userfiles import Userfiles
|
||||
from data.users import UserAuthentication
|
||||
from path_converters import RegexConverter, RepositoryPathConverter, APIRepositoryPathConverter
|
||||
from oauth.services.github import GithubOAuthService
|
||||
from oauth.services.gitlab import GitLabOAuthService
|
||||
from oauth.loginmanager import OAuthLoginManager
|
||||
|
@ -134,37 +136,6 @@ for handler in root_logger.handlers:
|
|||
app.request_class = RequestWithId
|
||||
|
||||
# Register custom converters.
|
||||
class RegexConverter(BaseConverter):
|
||||
""" Converter for handling custom regular expression patterns in paths. """
|
||||
def __init__(self, url_map, regex_value):
|
||||
super(RegexConverter, self).__init__(url_map)
|
||||
self.regex = regex_value
|
||||
|
||||
|
||||
class RepositoryPathConverter(BaseConverter):
|
||||
""" Converter for handling repository paths. Handles both library and non-library paths (if
|
||||
configured).
|
||||
"""
|
||||
def __init__(self, url_map):
|
||||
super(RepositoryPathConverter, self).__init__(url_map)
|
||||
self.weight = 200
|
||||
|
||||
if features.LIBRARY_SUPPORT:
|
||||
# Allow names without namespaces.
|
||||
self.regex = r'[^/]+(/[^/]+)?'
|
||||
else:
|
||||
self.regex = r'([^/]+/[^/]+)'
|
||||
|
||||
|
||||
class APIRepositoryPathConverter(BaseConverter):
|
||||
""" Converter for handling repository paths. Does not handle library paths.
|
||||
"""
|
||||
def __init__(self, url_map):
|
||||
super(APIRepositoryPathConverter, self).__init__(url_map)
|
||||
self.weight = 200
|
||||
self.regex = r'([^/]+/[^/]+)'
|
||||
|
||||
|
||||
app.url_map.converters['regex'] = RegexConverter
|
||||
app.url_map.converters['repopath'] = RepositoryPathConverter
|
||||
app.url_map.converters['apirepopath'] = APIRepositoryPathConverter
|
||||
|
@ -242,25 +213,5 @@ def load_user(user_uuid):
|
|||
logger.debug('User loader loading deferred user with uuid: %s', user_uuid)
|
||||
return LoginWrappedDBUser(user_uuid)
|
||||
|
||||
class LoginWrappedDBUser(UserMixin):
|
||||
def __init__(self, user_uuid, db_user=None):
|
||||
self._uuid = user_uuid
|
||||
self._db_user = db_user
|
||||
|
||||
def db_user(self):
|
||||
if not self._db_user:
|
||||
self._db_user = model.user.get_user_by_uuid(self._uuid)
|
||||
return self._db_user
|
||||
|
||||
@property
|
||||
def is_authenticated(self):
|
||||
return self.db_user() is not None
|
||||
|
||||
@property
|
||||
def is_active(self):
|
||||
return self.db_user().verified
|
||||
|
||||
def get_id(self):
|
||||
return unicode(self._uuid)
|
||||
|
||||
get_app_url = partial(get_app_url, app.config)
|
||||
|
|
Reference in a new issue