Compare commits
31 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
ff1219c436 | 1 year ago |
![]() |
cfddcb9f81 | 1 year ago |
![]() |
e81b7dd24d | 1 year ago |
![]() |
107c9f5282 | 1 year ago |
![]() |
ecd9028d04 | 1 year ago |
![]() |
29fc5af697 | 1 year ago |
![]() |
eb1053ca52 | 1 year ago |
|
b3ba44f127 | 1 year ago |
![]() |
6ae765733a | 1 year ago |
![]() |
aab1eb74a2 | 1 year ago |
![]() |
7714126252 | 1 year ago |
![]() |
2d6a7be4f2 | 1 year ago |
![]() |
89880432c1 | 1 year ago |
|
ea827253e4 | 1 year ago |
|
fda24219e2 | 1 year ago |
|
c5044f41fe | 1 year ago |
|
57f0135bb3 | 1 year ago |
|
4a899b32cc | 1 year ago |
![]() |
7d932dac22 | 1 year ago |
![]() |
4b6122f781 | 1 year ago |
![]() |
d46b15d95c | 1 year ago |
![]() |
a98f15d103 | 1 year ago |
|
4131223667 | 1 year ago |
![]() |
6d71bedb85 | 1 year ago |
![]() |
ad694fc28a | 1 year ago |
![]() |
ac5fe15de3 | 1 year ago |
|
6218b1e828 | 1 year ago |
|
bd26d85d34 | 1 year ago |
|
f1b4f53cd4 | 1 year ago |
|
a93dcb9975 | 1 year ago |
|
9f2e9c0996 | 1 year ago |
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -0,0 +1,5 @@
|
||||
using Model;
|
||||
|
||||
namespace API.DTO;
|
||||
|
||||
public record MemberDto(User User, MemberRole Role);
|
@ -0,0 +1,112 @@
|
||||
using API.Controllers.Admin;
|
||||
using DbServices;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Model;
|
||||
using StubContext;
|
||||
|
||||
namespace UnitTests;
|
||||
|
||||
public class AdminTeamsControllerTest
|
||||
{
|
||||
private static (TeamsAdminController, AppContext.AppContext) GetController()
|
||||
{
|
||||
var connection = new SqliteConnection("Data Source=:memory:");
|
||||
connection.Open();
|
||||
var context = new StubAppContext(
|
||||
new DbContextOptionsBuilder<AppContext.AppContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options
|
||||
);
|
||||
context.Database.EnsureCreated();
|
||||
var controller = new TeamsAdminController(
|
||||
new DbTeamService(context),
|
||||
new LoggerFactory().CreateLogger<TeamsAdminController>()
|
||||
);
|
||||
|
||||
return (controller, context);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void CountTeamsTest()
|
||||
{
|
||||
var (controller, context) = GetController();
|
||||
(await controller.CountTeams()).Should().BeEquivalentTo(new TeamsAdminController.CountTeamsResponse(2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void ListTeamsTest()
|
||||
{
|
||||
var (controller, context) = GetController();
|
||||
(await controller.ListTeams(0, 5)).Should().BeEquivalentTo(new Team[]
|
||||
{
|
||||
new(
|
||||
1,
|
||||
"Lakers",
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Los_Angeles_Lakers_logo.svg/2560px-Los_Angeles_Lakers_logo.svg.png",
|
||||
"#FFFFFF",
|
||||
"#000000"
|
||||
),
|
||||
new(
|
||||
2,
|
||||
"Auvergne",
|
||||
"https://sancy.iut.uca.fr/~lafourcade/img/photo19.jpg",
|
||||
"#FFFFFF",
|
||||
"#000000"
|
||||
)
|
||||
});
|
||||
|
||||
(await controller.ListTeams(3, 5)).Should()
|
||||
.BeEquivalentTo(new Team[] { });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void AddTeamTest()
|
||||
{
|
||||
var (controller, context) = GetController();
|
||||
(await controller.AddTeam(new ("PANPAN", "https://ih1.redbubble.net/image.2005529554.3887/bg,f8f8f8-flat,750x,075,f-pad,750x1000,f8f8f8.jpg", "#FFFFFF", "#000000")))
|
||||
.Should()
|
||||
.BeEquivalentTo(controller.Ok(new Team(3, "PANPAN", "https://ih1.redbubble.net/image.2005529554.3887/bg,f8f8f8-flat,750x,075,f-pad,750x1000,f8f8f8.jpg", "#FFFFFF", "#000000")));
|
||||
|
||||
var teamEntity = await context.Teams.FirstOrDefaultAsync(t => t.Name == "PANPAN");
|
||||
teamEntity.Should().NotBeNull();
|
||||
teamEntity!.Id.Should().Be(3);
|
||||
teamEntity.Picture.Should().BeEquivalentTo("https://ih1.redbubble.net/image.2005529554.3887/bg,f8f8f8-flat,750x,075,f-pad,750x1000,f8f8f8.jpg");
|
||||
teamEntity.MainColor.Should().BeEquivalentTo("#FFFFFF");
|
||||
teamEntity.SecondColor.Should().BeEquivalentTo("#000000");
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void UpdateTeamTest()
|
||||
{
|
||||
var (controller, context) = GetController();
|
||||
(await controller.UpdateTeam(1, new ("PANPAN", "https://ih1.redbubble.net/image.2005529554.3887/bg,f8f8f8-flat,750x,075,f-pad,750x1000,f8f8f8.jpg", "#FFFFFF", "#000000")))
|
||||
.Should()
|
||||
.BeEquivalentTo(controller.Ok());
|
||||
|
||||
var teamEntity = await context.Teams.FirstOrDefaultAsync(t => t.Name == "PANPAN");
|
||||
teamEntity.Should().NotBeNull();
|
||||
teamEntity!.Id.Should().Be(1);
|
||||
teamEntity.Picture.Should().BeEquivalentTo("https://ih1.redbubble.net/image.2005529554.3887/bg,f8f8f8-flat,750x,075,f-pad,750x1000,f8f8f8.jpg");
|
||||
teamEntity.MainColor.Should().BeEquivalentTo("#FFFFFF");
|
||||
teamEntity.SecondColor.Should().BeEquivalentTo("#000000");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void DeleteTeamsTest()
|
||||
{
|
||||
var (controller, context) = GetController();
|
||||
(await controller.DeleteTeams(new TeamsAdminController.DeleteTeamsRequest([10, 1, 2])))
|
||||
.Should()
|
||||
.BeEquivalentTo(controller.Ok());
|
||||
|
||||
(await context.Teams.CountAsync()).Should().Be(0);
|
||||
|
||||
(await controller.DeleteTeams(new TeamsAdminController.DeleteTeamsRequest([10, 1, 2])))
|
||||
.Should()
|
||||
.BeEquivalentTo(controller.Ok());
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using API.Controllers;
|
||||
using DbServices;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Moq;
|
||||
using StubContext;
|
||||
|
||||
namespace UnitTests;
|
||||
|
||||
public class AuthControllerTests
|
||||
{
|
||||
public static AuthenticationController GetController()
|
||||
{
|
||||
var connection = new SqliteConnection("Data Source=:memory:");
|
||||
connection.Open();
|
||||
var context = new StubAppContext(
|
||||
new DbContextOptionsBuilder<AppContext.AppContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options
|
||||
);
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
var mock = new Mock<IConfiguration>();
|
||||
mock.Setup(c => c["JWT:Key"]).Returns("qzdjnqzdjzdnjzdjqzdjzdqzdnzqdnzqdjnzqd");
|
||||
|
||||
|
||||
var controller = new AuthenticationController(
|
||||
new DbUserService(context),
|
||||
mock.Object
|
||||
);
|
||||
|
||||
return controller;
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void GenerateTokenTest()
|
||||
{
|
||||
var controller = GetController();
|
||||
var result = await controller.GenerateToken(new("maxime@mail.com", "123456"));
|
||||
result.Should()
|
||||
.BeAssignableTo(controller.Ok("").GetType());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void RegisterTest()
|
||||
{
|
||||
var controller = GetController();
|
||||
var result = await controller.RegisterAccount(new("test", "test@mail.com", "123456"));
|
||||
result.Should()
|
||||
.BeAssignableTo(controller.Ok("").GetType());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
using API.Controllers;
|
||||
using DbServices;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Model;
|
||||
using StubContext;
|
||||
|
||||
namespace UnitTests;
|
||||
|
||||
public class TeamsControllerTest
|
||||
{
|
||||
private static (TeamsController, AppContext.AppContext) GetController(int userId)
|
||||
{
|
||||
var connection = new SqliteConnection("Data Source=:memory:");
|
||||
connection.Open();
|
||||
var context = new StubAppContext(
|
||||
new DbContextOptionsBuilder<AppContext.AppContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options
|
||||
);
|
||||
context.Database.EnsureCreated();
|
||||
var controller = new TeamsController(
|
||||
new DbTeamService(context),
|
||||
new DbTacticService(context),
|
||||
new DbUserService(context),
|
||||
new ManualContextAccessor(userId)
|
||||
);
|
||||
|
||||
return (controller, context);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void CreateTeamTest()
|
||||
{
|
||||
var (controller, context) = GetController(1);
|
||||
var result = await controller.CreateTeam(new("Space Station", "55652433-1DB1-4778-A1FA-D56060BA1F1C", "#FFFFFF",
|
||||
"#AAFFBB"));
|
||||
result.Should().BeEquivalentTo(controller.Ok(new Team(3, "Space Station",
|
||||
"55652433-1DB1-4778-A1FA-D56060BA1F1C", "#FFFFFF", "#AAFFBB")));
|
||||
(await context.Teams.FindAsync(3))!.Name.Should().BeEquivalentTo("Space Station");
|
||||
(await context.Members.AnyAsync(m => m.TeamId == 3 && m.UserId == 1)).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetMembersOfTest()
|
||||
{
|
||||
var (controller, context) = GetController(1);
|
||||
var result = await controller.GetMembersOf(1);
|
||||
// result.Should().BeEquivalentTo(controller.Ok(new Member[]
|
||||
// {
|
||||
// new(1, 1, MemberRole.Coach),
|
||||
// new(1, 2, MemberRole.Player)
|
||||
// }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void AddMemberTest()
|
||||
{
|
||||
var (controller, context) = GetController(1);
|
||||
var result = await controller.AddMember(1, new(3, "COACH"));
|
||||
result.Should().BeEquivalentTo(controller.Ok(new Member(1, 3, MemberRole.Coach)));
|
||||
|
||||
(await context.Members.AnyAsync(m => m.TeamId == 1 && m.UserId == 3)).Should().BeTrue();
|
||||
|
||||
result = await controller.AddMember(1, new(3, "COACH"));
|
||||
result.Should().BeEquivalentTo(controller.Forbid());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void UpdateMemberTest()
|
||||
{
|
||||
var (controller, context) = GetController(1);
|
||||
var result = await controller.UpdateMember(1, 2, new("COACH"));
|
||||
result.Should().BeEquivalentTo(controller.Ok());
|
||||
|
||||
(await context.Members.FirstAsync(m => m.TeamId == 1 && m.UserId == 2)).Role.Should().Be(MemberRole.Coach);
|
||||
|
||||
result = await controller.UpdateMember(10, 2, new("COACH"));
|
||||
result.Should().BeEquivalentTo(controller.NotFound());
|
||||
|
||||
result = await controller.UpdateMember(1, 3, new("COACH"));
|
||||
result.Should().BeEquivalentTo(controller.NotFound());
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void RemoveMemberTest()
|
||||
{
|
||||
var (controller, context) = GetController(1);
|
||||
var result = await controller.RemoveMember(1, 2);
|
||||
result.Should().BeEquivalentTo(controller.Ok());
|
||||
|
||||
result = await controller.RemoveMember(10, 2);
|
||||
result.Should().BeEquivalentTo(controller.NotFound());
|
||||
|
||||
result = await controller.RemoveMember(1, 3);
|
||||
result.Should().BeEquivalentTo(controller.NotFound());
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using System.Security.Cryptography;
|
||||
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
|
||||
|
||||
namespace DbServices;
|
||||
|
||||
public class Hashing
|
||||
{
|
||||
public static (string, byte[]) HashString(string str)
|
||||
{
|
||||
byte[] salt = RandomNumberGenerator.GetBytes(128 / 8);
|
||||
string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
|
||||
password: str,
|
||||
salt,
|
||||
prf: KeyDerivationPrf.HMACSHA256,
|
||||
iterationCount: 50000,
|
||||
numBytesRequested: 256 / 8
|
||||
));
|
||||
|
||||
return (hashed, salt);
|
||||
}
|
||||
|
||||
public static bool PasswordsMatches(string password, string str, byte[] salt)
|
||||
{
|
||||
string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
|
||||
password: str,
|
||||
salt,
|
||||
prf: KeyDerivationPrf.HMACSHA256,
|
||||
iterationCount: 50000,
|
||||
numBytesRequested: 256 / 8
|
||||
));
|
||||
|
||||
return hashed == password;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -exu
|
||||
|
||||
apt update && apt install rsync openssh-client -y
|
||||
|
||||
mkdir -p ~/.ssh
|
||||
echo "$PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||
chmod 0600 ~/.ssh
|
||||
chmod 0500 ~/.ssh/id_rsa*
|
||||
ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev mkdir -p /srv/www/iqball/$DRONE_BRANCH/
|
||||
rsync -avz -e "ssh -p 80 -o 'StrictHostKeyChecking=no'" ci/deploy_staging_server.sh iqball@maxou.dev:/srv/www/iqball/$DRONE_BRANCH/
|
||||
ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev "chmod +x /srv/www/iqball/$DRONE_BRANCH/deploy_staging_server.sh && /srv/www/iqball/$DRONE_BRANCH/deploy_staging_server.sh $DRONE_BRANCH $DRONE_COMMIT_SHA"
|
||||
|
Loading…
Reference in new issue