Use stamp files with authz venv setup

Also fix incorrect bytes-strs usage
This commit is contained in:
Junhyun Shim 2022-08-18 15:43:39 +02:00
parent 37ff1c2eb6
commit 9fc343c442
3 changed files with 18 additions and 31 deletions

View File

@ -403,25 +403,29 @@ if(WITH_PYTHON)
set(authz_venv_activate ". ${authz_venv_dir}/bin/activate")
endif()
set(authz_venv_stamp_file ${authz_venv_dir}/venv.ready)
if (NOT WIN32)
add_test(
NAME authorization_venv_setup
COMMAND bash -c "${Python3_EXECUTABLE} -m venv ${authz_venv_dir} && \
COMMAND bash -c "
${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tests/authorization/* ${authz_venv_dir}/ && \
${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tests/TestRunner/*_cluster.py ${authz_venv_dir}/ && \
${authz_venv_activate} && \
pip install --upgrade pip && \
pip install --upgrade -r ${authz_venv_dir}/requirements.txt && \
(cd ${CMAKE_BINARY_DIR}/bindings/python && python3 setup.py install) && \
deactivate"
( \
[[ ! -f ${authz_venv_stamp_file} ]] && \
${Python3_EXECUTABLE} -m venv ${authz_venv_dir} && \
${authz_venv_activate} && \
pip install --upgrade pip && \
pip install --upgrade -r ${authz_venv_dir}/requirements.txt && \
(cd ${CMAKE_BINARY_DIR}/bindings/python && python3 setup.py install) && \
touch ${authz_venv_stamp_file} \
|| echo \"venv already set up\")"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_test(
NAME token_based_tenant_authorization
WORKING_DIRECTORY ${authz_venv_dir}
COMMAND bash -c "${authz_venv_activate} && \
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib pytest authz_test.py --build-dir ${CMAKE_BINARY_DIR} && \
deactivate"
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib pytest authz_test.py --build-dir ${CMAKE_BINARY_DIR}"
)
set_tests_properties(token_based_tenant_authorization PROPERTIES FIXTURES_REQUIRED authz_virtual_env)
set_tests_properties(authorization_venv_setup PROPERTIES FIXTURES_SETUP authz_virtual_env)

View File

@ -21,11 +21,9 @@ def token_claim_1h(tenant_name: str):
}
def test_simple_tenant_access(db, token_gen, default_tenant, default_tenant_tr_gen):
token = token_gen(token_claim_1h(str(default_tenant)))
token = token_gen(token_claim_1h(default_tenant.decode("ascii")))
tr = default_tenant_tr_gen()
tr.options.set_authorization_token(token)
tr.options.set_debug_transaction_identifier("XYZ")
tr.options.set_log_transaction()
tr[b'abc'] = b'def'
tr.commit().wait()
tr = default_tenant_tr_gen()

View File

@ -23,17 +23,6 @@ def pytest_addoption(parser):
def random_alphanum_str(k: int):
return ''.join(random.choices(string.ascii_letters + string.digits, k=k))
def cleanup_tenant(db, tenant_name):
try:
tenant = db.open_tenant(tenant_name)
del tenant[:]
fdb.tenant_management.delete_tenant(db, tenant_name)
except fdb.FDBError as e:
if e.code == 2131: # tenant not found
pass
else:
raise
@pytest.fixture
def build_dir(request):
return request.config.option.build_dir
@ -85,7 +74,7 @@ def cluster(build_dir, public_key_jwks_str, trusted_client):
build_dir=build_dir,
tls_config=TLSConfig(server_chain_len=3, client_chain_len=2),
public_key_json_str=public_key_jwks_str,
remove_at_exit=False,
remove_at_exit=True,
custom_config={"code-probes": "all"}) as cluster:
fdb.options.set_tls_key_path(str(cluster.client_key_file) if trusted_client else "")
fdb.options.set_tls_cert_path(str(cluster.client_cert_file) if trusted_client else "")
@ -98,17 +87,13 @@ def db(cluster):
db = fdb.open(str(cluster.cluster_file))
db.options.set_transaction_timeout(2000) # 2 seconds
db.options.set_transaction_retry_limit(3)
yield db
tenants = fdb.tenant_management.list_tenants(db, b'', b'\xff', 100)
print("Cleaning up tenants: {}".format(tenants))
for tenant in tenants:
cleanup_tenant(db, tenant)
return db
@pytest.fixture
def default_tenant(db):
def default_tenant(cluster):
tenant = random_alphanum_str(8).encode("ascii")
yield tenant
cleanup_tenant(db, tenant)
cluster.fdbcli_exec("createtenant {}".format(tenant.decode("ascii")))
return tenant
@pytest.fixture
def default_tenant_tr_gen(db, default_tenant):