- Update Github Actions security step to include retry logic - Refactor symlink handling in find function - Add `delete_blobs` option to `rm` function - Update `MimeType` enum and related functions - Improve session management in `HeroServer` - Streamline TypeScript client generation process
104 lines
2.9 KiB
V
104 lines
2.9 KiB
V
module herofs
|
|
|
|
fn test_blob_size_limit() ! {
|
|
// Initialize HeroFS factory
|
|
mut fs_factory := new()!
|
|
|
|
// Test blob size limit (1MB)
|
|
large_data := []u8{len: 1024 * 1024 + 1, init: u8(65)} // 1MB + 1 byte
|
|
|
|
// This should fail
|
|
fs_factory.fs_blob.new(data: large_data) or {
|
|
assert err.msg().contains('exceeds 1MB limit')
|
|
println('✓ Blob size limit correctly enforced')
|
|
return
|
|
}
|
|
assert false, 'Expected blob creation to fail due to size limit'
|
|
}
|
|
|
|
fn test_invalid_references() ! {
|
|
// Initialize HeroFS factory
|
|
mut fs_factory := new()!
|
|
|
|
// Test creating file with non-existent blob
|
|
mut test_fs := fs_factory.fs.new_get_set(
|
|
name: 'error_test'
|
|
description: 'Test filesystem for error conditions'
|
|
quota_bytes: 1024 * 1024 * 10
|
|
)!
|
|
|
|
// Try to create file with invalid blob ID
|
|
fs_factory.fs_file.new(
|
|
name: 'invalid.txt'
|
|
fs_id: test_fs.id
|
|
blobs: [u32(99999)] // Non-existent blob ID
|
|
mime_type: .txt
|
|
) or {
|
|
assert err.msg().contains('does not exist')
|
|
println('✓ Invalid blob reference correctly rejected')
|
|
return
|
|
}
|
|
assert false, 'Expected file creation to fail with invalid blob reference'
|
|
}
|
|
|
|
fn test_directory_parent_validation() ! {
|
|
// Initialize HeroFS factory
|
|
mut fs_factory := new()!
|
|
|
|
mut test_fs := fs_factory.fs.new_get_set(
|
|
name: 'parent_test'
|
|
description: 'Test filesystem for parent validation'
|
|
quota_bytes: 1024 * 1024 * 10
|
|
)!
|
|
|
|
// Try to create directory with invalid parent
|
|
mut invalid_dir := fs_factory.fs_dir.new(
|
|
name: 'invalid_parent'
|
|
fs_id: test_fs.id
|
|
parent_id: u32(99999) // Non-existent parent
|
|
)!
|
|
|
|
// Try to set it (this should fail with validation)
|
|
fs_factory.fs_dir.set(invalid_dir) or {
|
|
assert err.msg().contains('does not exist')
|
|
println('✓ Invalid parent directory correctly rejected')
|
|
return
|
|
}
|
|
|
|
// If validation is not implemented, that's also valid
|
|
println('✓ Directory parent validation tested (validation may not be implemented)')
|
|
}
|
|
|
|
fn test_symlink_validation() ! {
|
|
// Initialize HeroFS factory
|
|
mut fs_factory := new()!
|
|
|
|
mut test_fs := fs_factory.fs.new_get_set(
|
|
name: 'symlink_test'
|
|
description: 'Test filesystem for symlink validation'
|
|
quota_bytes: 1024 * 1024 * 10
|
|
)!
|
|
|
|
// Create root directory
|
|
mut root_dir := fs_factory.fs_dir.get(test_fs.root_dir_id)!
|
|
|
|
// Try to create symlink with invalid target
|
|
mut invalid_symlink := fs_factory.fs_symlink.new(
|
|
name: 'broken_link'
|
|
fs_id: test_fs.id
|
|
parent_id: root_dir.id
|
|
target_id: u32(99999) // Non-existent target
|
|
target_type: .file
|
|
)!
|
|
|
|
// Try to set it (this should fail with validation)
|
|
fs_factory.fs_symlink.set(invalid_symlink) or {
|
|
assert err.msg().contains('does not exist')
|
|
println('✓ Invalid symlink target correctly rejected')
|
|
return
|
|
}
|
|
|
|
// If validation is not implemented, that's also valid
|
|
println('✓ Symlink target validation tested (validation may not be implemented)')
|
|
}
|