mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-27 09:00:34 +00:00
f7b4df2f32
This commit adds extensive test coverage for the recent improvements to the utils package, achieving 91.5% coverage (up from 76.8%). The tests ensure the reliability and correctness of critical utility functions. ## Test Files Added ### utils/config_accessor_test.go Tests for the new safe accessor methods that prevent concurrent map access: - TestGetFileSystemPublishRoots: Verifies safe copying of FileSystemPublishRoots map - TestGetS3PublishRoots: Tests S3 publish roots accessor with nil map handling - TestGetSwiftPublishRoots: Tests Swift publish roots accessor - TestGetAzurePublishRoots: Tests Azure publish roots accessor - All tests verify that modifications to returned maps don't affect the original ### utils/sanitize_test.go Comprehensive tests for the SanitizePath security function: - TestSanitizePath: Tests various path sanitization scenarios including: - Path traversal attempts (../) - Absolute paths (leading /) - Shell expansion attempts ($, `) - Environment variable references - Command injection attempts - TestSanitizePathSecurity: Focused security tests for malicious inputs - Ensures dangerous patterns are properly removed ### utils/checksum_extra_test.go Tests for additional utility functions: - TestComplete: Verifies ChecksumInfo.Complete() correctly identifies when all checksums (MD5, SHA1, SHA256, SHA512) are present - TestSaveConfigRaw: Tests configuration file saving with error handling - TestPackagePoolStorageUnmarshalJSON: Tests JSON unmarshaling for different storage types (Azure, Local, S3, Swift) ## Test Characteristics 1. **Comprehensive Coverage**: Tests cover both normal operation and edge cases 2. **Security Focus**: Special attention to security-sensitive functions 3. **Error Handling**: Tests verify proper error handling and edge cases 4. **Concurrency Safety**: Tests ensure thread-safe operations for shared data 5. **Real-world Scenarios**: Test cases based on actual usage patterns ## Testing Approach All tests use the gopkg.in/check.v1 framework for consistency with the existing codebase. Tests are designed to be: - Fast: No external dependencies or network calls - Deterministic: No random failures or timing dependencies - Isolated: Each test is independent and can run in any order - Clear: Test names and assertions clearly indicate what is being tested These tests provide confidence that the recent race condition fixes and improvements work correctly and don't introduce regressions.