2017-01-27 16:22:40 +00:00
|
|
|
import pytest
|
2017-04-07 20:12:28 +00:00
|
|
|
from flask_principal import AnonymousIdentity
|
2017-01-27 16:22:40 +00:00
|
|
|
|
2017-02-17 23:20:23 +00:00
|
|
|
from endpoints.api import api
|
2017-05-18 21:52:50 +00:00
|
|
|
from endpoints.api.repositorynotification import RepositoryNotification
|
2017-02-17 23:20:23 +00:00
|
|
|
from endpoints.api.team import OrganizationTeamSyncing
|
2017-03-22 18:30:13 +00:00
|
|
|
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
2017-04-07 21:25:44 +00:00
|
|
|
from endpoints.api.repository import RepositoryTrust
|
|
|
|
from endpoints.api.signing import RepositorySignatures
|
|
|
|
from endpoints.api.search import ConductRepositorySearch
|
2017-01-27 16:22:40 +00:00
|
|
|
from endpoints.api.superuser import SuperUserRepositoryBuildLogs, SuperUserRepositoryBuildResource
|
|
|
|
from endpoints.api.superuser import SuperUserRepositoryBuildStatus
|
2017-04-24 17:49:29 +00:00
|
|
|
|
|
|
|
from test.fixtures import *
|
2017-01-27 16:22:40 +00:00
|
|
|
|
2017-03-22 18:30:13 +00:00
|
|
|
TEAM_PARAMS = {'orgname': 'buynlarge', 'teamname': 'owners'}
|
|
|
|
BUILD_PARAMS = {'build_uuid': 'test-1234'}
|
2017-04-07 20:12:28 +00:00
|
|
|
REPO_PARAMS = {'repository': 'devtable/someapp'}
|
2017-04-07 21:25:44 +00:00
|
|
|
SEARCH_PARAMS = {'query': ''}
|
2017-05-18 21:52:50 +00:00
|
|
|
NOTIFICATION_PARAMS = {'namespace': 'devtable', 'repository': 'devtable/simple', 'uuid': 'some uuid'}
|
|
|
|
|
2017-01-27 16:22:40 +00:00
|
|
|
|
2017-03-22 18:30:13 +00:00
|
|
|
@pytest.mark.parametrize('resource,method,params,body,identity,expected', [
|
2017-02-17 23:20:23 +00:00
|
|
|
(OrganizationTeamSyncing, 'POST', TEAM_PARAMS, {}, None, 403),
|
|
|
|
(OrganizationTeamSyncing, 'POST', TEAM_PARAMS, {}, 'freshuser', 403),
|
|
|
|
(OrganizationTeamSyncing, 'POST', TEAM_PARAMS, {}, 'reader', 403),
|
|
|
|
(OrganizationTeamSyncing, 'POST', TEAM_PARAMS, {}, 'devtable', 400),
|
|
|
|
|
|
|
|
(OrganizationTeamSyncing, 'DELETE', TEAM_PARAMS, {}, None, 403),
|
|
|
|
(OrganizationTeamSyncing, 'DELETE', TEAM_PARAMS, {}, 'freshuser', 403),
|
|
|
|
(OrganizationTeamSyncing, 'DELETE', TEAM_PARAMS, {}, 'reader', 403),
|
|
|
|
(OrganizationTeamSyncing, 'DELETE', TEAM_PARAMS, {}, 'devtable', 200),
|
|
|
|
|
2017-04-07 21:25:44 +00:00
|
|
|
(ConductRepositorySearch, 'GET', SEARCH_PARAMS, None, None, 200),
|
|
|
|
(ConductRepositorySearch, 'GET', SEARCH_PARAMS, None, 'freshuser', 200),
|
|
|
|
(ConductRepositorySearch, 'GET', SEARCH_PARAMS, None, 'reader', 200),
|
|
|
|
(ConductRepositorySearch, 'GET', SEARCH_PARAMS, None, 'devtable', 200),
|
|
|
|
|
2017-03-22 18:30:13 +00:00
|
|
|
(SuperUserRepositoryBuildLogs, 'GET', BUILD_PARAMS, None, None, 401),
|
|
|
|
(SuperUserRepositoryBuildLogs, 'GET', BUILD_PARAMS, None, 'freshuser', 403),
|
|
|
|
(SuperUserRepositoryBuildLogs, 'GET', BUILD_PARAMS, None, 'reader', 403),
|
|
|
|
(SuperUserRepositoryBuildLogs, 'GET', BUILD_PARAMS, None, 'devtable', 400),
|
2017-01-27 16:22:40 +00:00
|
|
|
|
2017-03-22 18:30:13 +00:00
|
|
|
(SuperUserRepositoryBuildStatus, 'GET', BUILD_PARAMS, None, None, 401),
|
|
|
|
(SuperUserRepositoryBuildStatus, 'GET', BUILD_PARAMS, None, 'freshuser', 403),
|
|
|
|
(SuperUserRepositoryBuildStatus, 'GET', BUILD_PARAMS, None, 'reader', 403),
|
|
|
|
(SuperUserRepositoryBuildStatus, 'GET', BUILD_PARAMS, None, 'devtable', 400),
|
2017-01-27 16:22:40 +00:00
|
|
|
|
2017-03-22 18:30:13 +00:00
|
|
|
(SuperUserRepositoryBuildResource, 'GET', BUILD_PARAMS, None, None, 401),
|
|
|
|
(SuperUserRepositoryBuildResource, 'GET', BUILD_PARAMS, None, 'freshuser', 403),
|
|
|
|
(SuperUserRepositoryBuildResource, 'GET', BUILD_PARAMS, None, 'reader', 403),
|
|
|
|
(SuperUserRepositoryBuildResource, 'GET', BUILD_PARAMS, None, 'devtable', 404),
|
2017-04-17 22:03:32 +00:00
|
|
|
|
2017-04-07 20:12:28 +00:00
|
|
|
(RepositorySignatures, 'GET', REPO_PARAMS, {}, 'freshuser', 403),
|
|
|
|
(RepositorySignatures, 'GET', REPO_PARAMS, {}, 'reader', 403),
|
2017-04-17 22:03:32 +00:00
|
|
|
(RepositorySignatures, 'GET', REPO_PARAMS, {}, 'devtable', 404),
|
|
|
|
|
2017-05-18 21:52:50 +00:00
|
|
|
(RepositoryNotification, 'POST', NOTIFICATION_PARAMS, {}, None, 403),
|
|
|
|
(RepositoryNotification, 'POST', NOTIFICATION_PARAMS, {}, 'freshuser', 403),
|
|
|
|
(RepositoryNotification, 'POST', NOTIFICATION_PARAMS, {}, 'reader', 403),
|
|
|
|
(RepositoryNotification, 'POST', NOTIFICATION_PARAMS, {}, 'devtable', 204),
|
|
|
|
|
2017-04-15 12:26:33 +00:00
|
|
|
(RepositoryTrust, 'POST', REPO_PARAMS, {'trust_enabled': True}, None, 403),
|
|
|
|
(RepositoryTrust, 'POST', REPO_PARAMS, {'trust_enabled': True}, 'freshuser', 403),
|
|
|
|
(RepositoryTrust, 'POST', REPO_PARAMS, {'trust_enabled': True}, 'reader', 403),
|
|
|
|
(RepositoryTrust, 'POST', REPO_PARAMS, {'trust_enabled': True}, 'devtable', 404),
|
2017-01-27 16:22:40 +00:00
|
|
|
])
|
2017-03-22 18:30:13 +00:00
|
|
|
def test_api_security(resource, method, params, body, identity, expected, client):
|
|
|
|
with client_with_identity(identity, client) as cl:
|
|
|
|
conduct_api_call(cl, resource, method, params, body, expected)
|