mirror of
https://github.com/quay/quay.git
synced 2026-01-26 06:21:37 +03:00
* initial checkin for the superuser/config endpoint to show how its intended to return data bug: fixing NaN value error for quota displayed on member org page (PROJQUAY-6465) (#3224) bug: fixing NaN value error for quota displayed on member org page (PROJQUAY-6465) fixed black formatting fixed flake and black formatting fixed isort formatting test need to be updated for superuser endpoints. There is no explicit superuser token test so globalreadonlysuperuser shall succeed too fixed double json encoding changed naming to comply with other SuperUserClasses, added SuperUserPermission check as scope only isnt sufficient fixed another black error fixed response for devtable check fixed response for devtable as that is a superuser fixed black format :/ added allow_if_global_readonly_superuser to config endpoint repush for checks fixed app.logger to module specific logger ; added missed SCHEMA return added unittest for checking superuser config dump API call (no clue if the unittests build up a full setup since we mock all kind of stuff in the other calls) removed env PWD check as it seems to be unset in the github runners added missing unittest step added FeatureFlag for config dump formatting * removed wrong commit in the branch * changed from route decorator to in method check and changed unittests to fail as the default config is to deny the request * added one test for security_tests * rebumped the security tests
109 lines
4.3 KiB
Python
109 lines
4.3 KiB
Python
import pytest
|
|
|
|
from data.database import DeletedNamespace, User
|
|
from endpoints.api.superuser import (
|
|
SuperUserDumpConfig,
|
|
SuperUserList,
|
|
SuperUserManagement,
|
|
SuperUserOrganizationList,
|
|
)
|
|
from endpoints.api.test.shared import conduct_api_call
|
|
from endpoints.test.shared import client_with_identity
|
|
from test.fixtures import *
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"disabled",
|
|
[
|
|
(True),
|
|
(False),
|
|
],
|
|
)
|
|
def test_list_all_users(disabled, app):
|
|
with client_with_identity("devtable", app) as cl:
|
|
params = {"disabled": disabled}
|
|
result = conduct_api_call(cl, SuperUserList, "GET", params, None, 200).json
|
|
assert len(result["users"])
|
|
for user in result["users"]:
|
|
if not disabled:
|
|
assert user["enabled"]
|
|
|
|
|
|
def test_list_all_orgs(app):
|
|
with client_with_identity("devtable", app) as cl:
|
|
result = conduct_api_call(cl, SuperUserOrganizationList, "GET", None, None, 200).json
|
|
assert len(result["organizations"]) == 8
|
|
|
|
|
|
def test_paginate_orgs(app):
|
|
with client_with_identity("devtable", app) as cl:
|
|
params = {"limit": 4}
|
|
firstResult = conduct_api_call(cl, SuperUserOrganizationList, "GET", params, None, 200).json
|
|
assert len(firstResult["organizations"]) == 4
|
|
assert firstResult["next_page"] is not None
|
|
params["next_page"] = firstResult["next_page"]
|
|
secondResult = conduct_api_call(
|
|
cl, SuperUserOrganizationList, "GET", params, None, 200
|
|
).json
|
|
assert len(secondResult["organizations"]) == 4
|
|
assert secondResult.get("next_page", None) is None
|
|
|
|
|
|
def test_paginate_test_list_all_users(app):
|
|
with client_with_identity("devtable", app) as cl:
|
|
params = {"limit": 7}
|
|
firstResult = conduct_api_call(cl, SuperUserList, "GET", params, None, 200).json
|
|
assert len(firstResult["users"]) == 7
|
|
assert firstResult["next_page"] is not None
|
|
params["next_page"] = firstResult["next_page"]
|
|
secondResult = conduct_api_call(cl, SuperUserList, "GET", params, None, 200).json
|
|
assert len(secondResult["users"]) == 6
|
|
assert secondResult.get("next_page", None) is None
|
|
|
|
|
|
def test_change_install_user(app):
|
|
with client_with_identity("devtable", app) as cl:
|
|
params = {"username": "randomuser"}
|
|
body = {"email": "new_email123@test.com"}
|
|
result = conduct_api_call(cl, SuperUserManagement, "PUT", params, body, 200).json
|
|
|
|
assert result["email"] == body["email"]
|
|
|
|
|
|
def test_get_superuserdumpconfig(app):
|
|
import features
|
|
|
|
features.import_features({"FEATURE_SUPERUSER_CONFIGDUMP": True})
|
|
with client_with_identity("devtable", app) as cl:
|
|
result = conduct_api_call(cl, SuperUserDumpConfig, "GET", None, None, 200).json
|
|
# we check for json struct to be returned by the function
|
|
assert isinstance(result.get("config", False), dict)
|
|
assert isinstance(result.get("warning", False), dict)
|
|
assert isinstance(result.get("env", False), dict)
|
|
assert isinstance(result.get("schema", False), dict)
|
|
|
|
# we check for some Keys that are expected to be always present
|
|
with pytest.raises(AttributeError):
|
|
result.get("config", {})["AUTHENTICATION_TYPE"]
|
|
result.get("config", {})["SERVER_HOSTNAME"]
|
|
# satisfy the test after passing without KeyError raised
|
|
raise AttributeError()
|
|
# we check for some Keys that are expected to be present in warning
|
|
# which means, they are not in config.yaml but set by the application
|
|
with pytest.raises(AttributeError):
|
|
result.get("warning", {})["APPLICATION_ROOT"]
|
|
result.get("warning", {})["EXPLAIN_TEMPLATE_LOADING"]
|
|
# satisfy the test after passing without KeyError raised
|
|
raise AttributeError()
|
|
# we check for some Keys that are expected to be present in env
|
|
with pytest.raises(AttributeError):
|
|
result.get("env", {})["PATH"]
|
|
result.get("env", {})["PYTHONPATH"]
|
|
# satisfy the test after passing without KeyError raised
|
|
raise AttributeError()
|
|
# we check for some Keys that are expected to be present in schema
|
|
with pytest.raises(AttributeError):
|
|
result.get("schema", {})["description"]
|
|
result.get("schema", {})["required"]
|
|
raise AttributeError()
|