function test_acl_functions
Comprehensive test function that validates ACL (Access Control List) management operations in FileCloudAPI, including creating, reading, updating, and deleting ACL entries for users and groups.
/tf/active/vicechatdev/test_acl_functions.py
25 - 125
moderate
Purpose
This function serves as an integration test suite for FileCloud's ACL management functionality. It tests the complete lifecycle of ACL operations: authentication, folder creation/verification, retrieving system-wide and path-specific ACLs, adding ACL entries for users and groups with various permissions, verifying the additions, deleting ACL entries, and final verification. It's designed to validate that the FileCloudAPI correctly handles permission management for files and folders in a FileCloud server environment.
Source Code
def test_acl_functions(server_url: str, username: str, password: str, test_path: str) -> None:
"""
Test ACL management functions in FileCloudAPI.
Args:
server_url: URL of the FileCloud server
username: Username for authentication
password: Password for authentication
test_path: Path to use for ACL testing
"""
# Initialize the API client
api = FileCloudAPI(server_url, username, password)
# Login to the server
print(f"Logging in to {server_url} as {username}...")
if not api.login():
print("Login failed. Check your credentials.")
sys.exit(1)
print("Login successful.")
# Test creating a folder for ACL testing if it doesn't exist
folder_exists = api.check_folder_exists(test_path)
if not folder_exists:
print(f"Creating test folder: {test_path}")
result = api.create_folder('/', os.path.basename(test_path.rstrip('/')))
if not result.get('success', False):
print(f"Failed to create test folder: {result.get('message')}")
sys.exit(1)
# Test getting all ACLs in the system
print("\n1. Getting all ACLs in the system...")
acls_result = api.get_acls()
print_json(acls_result)
# Test getting ACL for the test path
print(f"\n2. Getting ACL for path: {test_path}")
acl_result = api.get_acl(test_path)
print_json(acl_result)
# Test getting all ACLs for the test path
print(f"\n3. Getting all ACLs for path: {test_path}")
all_acls_result = api.get_all_acls_for_path(test_path)
print_json(all_acls_result)
# Test adding an ACL entry (read permission for a test user)
test_user = "sandra@vicebio.com" # Replace with an existing user in your system
print(f"\n4. Adding ACL entry for user '{test_user}' with read permission...")
add_result = api.add_acl_entry(
path=test_path,
entry_type="user",
value=test_user,
permissions="R",
flag='allow' # Read permission
)
print_json(add_result)
# Verify the ACL entry was added
print(f"\n5. Verifying ACL entry was added for path: {test_path}")
verify_acl = api.get_acl(test_path)
print_json(verify_acl)
# Test adding an ACL entry for a group (if you have a group to test with)
test_group = "testgroup" # Replace with an existing group in your system
print(f"\n6. Adding ACL entry for group '{test_group}' with read and write permissions...")
add_group_result = api.add_acl_entry(
path=test_path,
entry_type="group",
value=test_group,
permissions="rw" # Read and write permissions
)
print_json(add_group_result)
# Verify the group ACL entry was added
print(f"\n7. Verifying group ACL entry was added for path: {test_path}")
verify_group_acl = api.get_acl(test_path)
print_json(verify_group_acl)
# Test deleting the user ACL entry
print(f"\n8. Deleting ACL entry for user '{test_user}'...")
delete_result = api.delete_acl_entry(
path=test_path,
entry_type="user",
value=test_user
)
print_json(delete_result)
# Test deleting the group ACL entry
print(f"\n9. Deleting ACL entry for group '{test_group}'...")
delete_group_result = api.delete_acl_entry(
path=test_path,
entry_type="group",
value=test_group
)
print_json(delete_group_result)
# Final verification that ACL entries were removed
print(f"\n10. Final verification of ACL for path: {test_path}")
final_acl = api.get_acl(test_path)
print_json(final_acl)
print("\nACL test completed.")
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
server_url |
str | - | positional_or_keyword |
username |
str | - | positional_or_keyword |
password |
str | - | positional_or_keyword |
test_path |
str | - | positional_or_keyword |
Parameter Details
server_url: The complete URL of the FileCloud server to connect to (e.g., 'https://filecloud.example.com'). Must be a valid HTTP/HTTPS URL pointing to an accessible FileCloud instance.
username: The username credential for authenticating with the FileCloud server. Must be an existing user account with sufficient privileges to manage ACLs and create folders.
password: The password credential corresponding to the username. Used for authentication during the login process.
test_path: The file system path within FileCloud where ACL testing will be performed (e.g., '/testfolder' or '/path/to/test'). If the folder doesn't exist, it will be created. Should be a path where the authenticated user has permission to create folders and manage ACLs.
Return Value
Type: None
Returns None. This is a test function that performs operations and prints results to stdout. Success or failure is communicated through console output and potential sys.exit(1) calls on critical failures (login failure or folder creation failure). All test results are printed using print_json() function for formatted output.
Dependencies
FC_apiossysargparsejsonloggingtyping
Required Imports
import os
import sys
from FC_api import FileCloudAPI
Usage Example
# Assuming print_json function is defined
def print_json(data):
import json
print(json.dumps(data, indent=2))
# Import the required module
from FC_api import FileCloudAPI
import os
import sys
# Define test parameters
server_url = "https://filecloud.example.com"
username = "admin@example.com"
password = "secure_password"
test_path = "/test_acl_folder"
# Run the ACL tests
test_acl_functions(server_url, username, password, test_path)
# The function will:
# 1. Login to FileCloud
# 2. Create test folder if needed
# 3. Test all ACL operations
# 4. Print results for each operation
# 5. Clean up by removing test ACL entries
Best Practices
- Update the hardcoded test_user ('sandra@vicebio.com') and test_group ('testgroup') variables to match actual users/groups in your FileCloud system before running
- Ensure the authenticated user has sufficient privileges to create folders and manage ACLs in the target location
- The function calls sys.exit(1) on critical failures, so it's designed for standalone execution rather than being called within larger applications
- Consider wrapping this function in try-except blocks if integrating into a larger test suite to prevent abrupt termination
- The print_json() function must be available in the scope; ensure it's defined or imported before calling this function
- Use a dedicated test path that won't interfere with production data
- Review and clean up any residual ACL entries if the test fails midway through execution
- The function performs destructive operations (creating folders, modifying ACLs), so use with caution in production environments
- Consider parameterizing test_user and test_group as function arguments for better reusability
- Monitor console output to verify each step completes successfully
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function main_v42 75.5% similar
-
function test_filecloud_operations 66.9% similar
-
function test_filecloud_connection_v1 62.1% similar
-
function test_filecloud_connection 62.1% similar
-
function test_upload_modalities 60.7% similar