Add access control for media downloads

Introduced IAccesserToDownloadMedia and its implementation to enforce access checks when downloading media files. Updated MediaController to use the new accesser service and improved error handling and validation in upload/download actions. Refactored and moved MediaService to the Medias namespace, registered new services in DI, and added comprehensive tests for access logic. Also fixed GroupMembershipConfiguration to make InvitationId optional and performed minor test and namespace cleanups.
This commit is contained in:
Artemy
2025-07-21 14:51:57 +07:00
parent 58e7716ded
commit c0d02e0fa1
11 changed files with 243 additions and 30 deletions
@@ -0,0 +1,43 @@
using Govor.Application.Exceptions.AuthService;
using Govor.Application.Infrastructure.Validators;
namespace Govor.Application.Tests.Infrastructure.Validators;
[TestFixture]
public class UsernameValidatorTests
{
private UsernameValidator _validator;
[SetUp]
public void SetUp()
{
_validator = new UsernameValidator();
}
[TestCase("Иван")]
[TestCase("Алексей")]
[TestCase("Ёжик")]
[TestCase("Иван123")] // содержит цифры
public void Validate_ValidUsernames_ShouldNotThrow(string username)
{
Assert.DoesNotThrow(() => _validator.Validate(username));
}
[TestCase("Ivan")] // не кириллица
[TestCase("123Иван")] // начинается не с буквы
[TestCase("!@#$")] // спецсимволы
[TestCase("")] // пусто
[TestCase("И")] // меньше минимума
[TestCase("ИванИванИванИванИванИванИванИванИванИванИванИванИван")] // больше максимума (44 символа)
public void Validate_InvalidUsernames_ShouldThrow(string username)
{
Assert.Throws<InvalidUsernameException>(() => _validator.Validate(username));
}
[TestCase("Иван", ExpectedResult = true)]
[TestCase("1234", ExpectedResult = false)]
public bool TryValidate_ShouldReturnTrueRegardlessOfInput(string username)
{
return _validator.TryValidate(username);
}
}