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 a valid user account with sufficient permissions to create folders and manage ACLs.
password: The password credential corresponding to the username. Used for authentication with the FileCloud server.
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 permissions 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. It exits the program with sys.exit(1) if login fails or folder creation fails. Success or failure of individual ACL operations is printed to the console via print_json() calls.
Dependencies
FC_apiossysargparsejsonloggingtyping
Required Imports
import os
import sys
from FC_api import FileCloudAPI
Usage Example
from FC_api import FileCloudAPI
import os
import sys
# Assuming print_json is defined elsewhere
def print_json(data):
import json
print(json.dumps(data, indent=2))
# Run the ACL tests
server_url = 'https://filecloud.example.com'
username = 'admin@example.com'
password = 'secure_password'
test_path = '/acl_test_folder'
test_acl_functions(server_url, username, password, test_path)
# The function will:
# 1. Login to FileCloud
# 2. Create test folder if needed
# 3. Test getting all ACLs
# 4. Test getting ACL for specific path
# 5. Add ACL entries for user and group
# 6. Verify additions
# 7. Delete ACL entries
# 8. Verify deletions
# 9. Print results at each step
Best Practices
- Ensure the test_user ('sandra@vicebio.com') and test_group ('testgroup') exist in your FileCloud system before running, or modify these variables to match existing users/groups
- Run this test in a non-production environment or use a dedicated test path to avoid affecting production ACLs
- The function will exit the program (sys.exit(1)) on login or folder creation failure, so handle this appropriately in your test framework
- Requires the print_json() helper function to be defined in the same module for output formatting
- The test creates a folder if it doesn't exist, so ensure the authenticated user has folder creation permissions
- ACL permissions use specific flags: 'R' for read, 'rw' for read-write, and 'allow' flag for permission type
- Clean up test data after running if needed, as the function creates folders and ACL entries
- Monitor the console output to verify each step completes successfully
- Consider wrapping sys.exit() calls in try-except blocks if integrating into a larger test suite
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function main_v23 76.5% similar
-
function test_filecloud_operations 66.8% similar
-
function test_filecloud_connection 62.1% similar
-
function test_upload_modalities 60.7% similar
-
function check_filecloud_structure 59.8% similar