2661db7485
* Add flag to enable trust per repo * Add api for enabling/disabling trust * Add new LogEntryKind for changing repo trust settings Also add tests for repo trust api * Add `set_trust` method to repository * Expose new logkind to UI * Fix registry tests * Rebase migrations and regen test.db * Raise downstreamissue if trust metadata can't be removed * Refactor change_repo_trust * Add show_if to change_repo_trust endpoint
42 lines
1.9 KiB
Python
42 lines
1.9 KiB
Python
import pytest
|
|
|
|
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
|
from endpoints.api.repository import RepositoryTrust
|
|
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
|
from mock import patch, ANY, MagicMock
|
|
|
|
|
|
INVALID_RESPONSE = {
|
|
u'detail': u"u'invalid_req' is not of type 'boolean'",
|
|
u'error_message': u"u'invalid_req' is not of type 'boolean'",
|
|
u'error_type': u'invalid_request',
|
|
u'status': 400,
|
|
u'title': u'invalid_request',
|
|
u'type': u'http://localhost/api/v1/error/invalid_request'
|
|
}
|
|
|
|
NOT_FOUND_RESPONSE = {
|
|
u'detail': u'Not Found',
|
|
u'error_message': u'Not Found',
|
|
u'error_type': u'not_found',
|
|
u'message': u'You have requested this URI [/api/v1/repository/devtable/repo/changetrust] but did you mean /api/v1/repository/<apirepopath:repository>/changetrust or /api/v1/repository/<apirepopath:repository>/changevisibility or /api/v1/repository/<apirepopath:repository>/tag/<tag>/images ?',
|
|
u'status': 404,
|
|
u'title': u'not_found',
|
|
u'type': u'http://localhost/api/v1/error/not_found'
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize('trust_enabled,repo_found,expected_body,expected_status', [
|
|
(True, True,{'success': True}, 200),
|
|
(False, True, {'success': True}, 200),
|
|
(False, False, NOT_FOUND_RESPONSE, 404),
|
|
('invalid_req', False, INVALID_RESPONSE , 400),
|
|
])
|
|
def test_post_changetrust(trust_enabled, repo_found, expected_body, expected_status, client):
|
|
with patch('endpoints.api.repository.tuf_metadata_api'):
|
|
with patch('endpoints.api.repository.model') as mock_model:
|
|
mock_model.repository.get_repository.return_value = MagicMock() if repo_found else None
|
|
with client_with_identity('devtable', client) as cl:
|
|
params = {'repository': 'devtable/repo'}
|
|
request_body = {'trust_enabled': trust_enabled}
|
|
assert expected_body == conduct_api_call(cl, RepositoryTrust, 'POST', params, request_body, expected_status).json
|