Prevent CNR methods from auth-ing on non-app repos
This commit is contained in:
parent
bdda74d6df
commit
4c34b00b38
2 changed files with 26 additions and 0 deletions
|
@ -2,6 +2,8 @@ import logging
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
from flask import abort
|
||||||
|
|
||||||
from data import model
|
from data import model
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,6 +26,11 @@ def require_repo_permission(permission_class, scopes=None, allow_public=False,
|
||||||
def wrapped(*args, **kwargs):
|
def wrapped(*args, **kwargs):
|
||||||
namespace_name, repo_name = get_reponame_method(*args, **kwargs)
|
namespace_name, repo_name = get_reponame_method(*args, **kwargs)
|
||||||
|
|
||||||
|
image_repo = model.repository.get_repository(namespace_name, repo_name, kind_filter='image')
|
||||||
|
if image_repo is not None:
|
||||||
|
logger.debug('Tried to invoked a CNR method on an image repository')
|
||||||
|
abort(501)
|
||||||
|
|
||||||
logger.debug('Checking permission %s for repo: %s/%s', permission_class,
|
logger.debug('Checking permission %s for repo: %s/%s', permission_class,
|
||||||
namespace_name, repo_name)
|
namespace_name, repo_name)
|
||||||
permission = permission_class(namespace_name, repo_name)
|
permission = permission_class(namespace_name, repo_name)
|
||||||
|
|
19
endpoints/appr/test/test_decorators.py
Normal file
19
endpoints/appr/test/test_decorators.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from werkzeug.exceptions import NotImplemented as NIE
|
||||||
|
|
||||||
|
from data import model
|
||||||
|
from endpoints.test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
||||||
|
from endpoints.appr import require_app_repo_read
|
||||||
|
|
||||||
|
def test_require_app_repo_read(app):
|
||||||
|
called = [False]
|
||||||
|
|
||||||
|
# Ensure that trying to read an *image* repository fails.
|
||||||
|
@require_app_repo_read
|
||||||
|
def empty(**kwargs):
|
||||||
|
called[0] = True
|
||||||
|
|
||||||
|
with pytest.raises(NIE):
|
||||||
|
empty(namespace='devtable', package_name='simple')
|
||||||
|
assert not called[0]
|
Reference in a new issue