"""Tests for secure filename handling and upload validation.""" import pytest def test_sanitize_normal_filename(): from app.api.uploads import sanitize_filename assert sanitize_filename("test.wav") == "test.wav" assert sanitize_filename("my song.mp3") == "my_song.mp3" def test_sanitize_path_traversal(): from app.api.uploads import sanitize_filename # Path components are stripped, only the basename remains result = sanitize_filename("../../etc/passwd") assert ".." not in result assert "/" not in result assert result == "passwd" result2 = sanitize_filename("../../../root/.ssh/id_rsa") assert ".." not in result2 assert "/" not in result2 assert result2 == "id_rsa" result3 = sanitize_filename("/etc/shadow") assert ".." not in result3 assert result3 == "shadow" def test_sanitize_hidden_file(): from app.api.uploads import sanitize_filename result = sanitize_filename(".hidden.wav") assert not result.startswith(".") def test_sanitize_special_chars(): from app.api.uploads import sanitize_filename result = sanitize_filename("file