CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
104 lines
6.2 KiB
C#
104 lines
6.2 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Protocol;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Server.Tests.Api;
|
|
|
|
[Category("server")]
|
|
public sealed class UserTests(TestContext context)
|
|
{
|
|
[Test]
|
|
public async Task AdminsManageAccountsAndTemporaryPasswords()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var admin = await server.AdminAsync();
|
|
using var created = await admin.PostAsJsonAsync("/api/v1/users", new CreateUserRequest("lucia", "Lucia", "editor", 2_000_000_000_000, null, AllowRenderNode: false),
|
|
ProtocolJson.Default.CreateUserRequest);
|
|
await created.ExpectAsync(HttpStatusCode.Created);
|
|
var account = await created.ReadAsync(ProtocolJson.Default.TemporaryPasswordResponse);
|
|
Assert.True(account.User.MustChangePassword);
|
|
Assert.Equal(14, account.TemporaryPassword.Length);
|
|
Assert.Equal(0L, account.User.Permissions & (long)Permissions.RenderNode);
|
|
|
|
using (var taken = await admin.PostAsJsonAsync("/api/v1/users", new CreateUserRequest("LUCIA", null, "viewer", 0, null, false), ProtocolJson.Default.CreateUserRequest))
|
|
await taken.ExpectErrorAsync(HttpStatusCode.Conflict, "username_taken");
|
|
using (var badName = await admin.PostAsJsonAsync("/api/v1/users", new CreateUserRequest("lu cia", null, "viewer", 0, null, false), ProtocolJson.Default.CreateUserRequest))
|
|
await badName.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_username");
|
|
using (var badRole = await admin.PostAsJsonAsync("/api/v1/users", new CreateUserRequest("lucio", null, "owner", 0, null, false), ProtocolJson.Default.CreateUserRequest))
|
|
await badRole.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_role");
|
|
|
|
using (var promoted = await admin.PatchAsJsonAsync($"/api/v1/users/{account.User.Id}", new UpdateUserRequest(null, "uploader", 5, null, true), ProtocolJson.Default.UpdateUserRequest))
|
|
{
|
|
var user = await promoted.ReadAsync(ProtocolJson.Default.UserDto);
|
|
Assert.Equal(("uploader", 5L), (user.Role, user.QuotaBytes));
|
|
Assert.Equal((long)(RolePermissions.Default(UserRole.Uploader) | Permissions.RenderNode), user.Permissions);
|
|
}
|
|
|
|
using var reset = await admin.PostAsJsonAsync($"/api/v1/users/{account.User.Id}/reset-password", new ResetPasswordRequest(null), ProtocolJson.Default.ResetPasswordRequest);
|
|
var temporary = await reset.ReadAsync(ProtocolJson.Default.TemporaryPasswordResponse);
|
|
var login = await server.LoginAsync("lucia", temporary.TemporaryPassword);
|
|
Assert.True(login.MustChangePassword);
|
|
|
|
using var list = await admin.GetAsync("/api/v1/users");
|
|
var rows = await list.ReadAsync(ProtocolJson.Default.ListUserSummaryDto);
|
|
var lucia = rows.Single(r => r.User.Username == "lucia");
|
|
Assert.Equal("tests", lucia.LastClient);
|
|
Assert.NotNull(lucia.LastSeen);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TheLastAdministratorStays()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var admin = await server.AdminAsync();
|
|
using var me = await admin.GetAsync("/api/v1/auth/me");
|
|
var self = await me.ReadAsync(ProtocolJson.Default.UserDto);
|
|
using (var demote = await admin.PatchAsJsonAsync($"/api/v1/users/{self.Id}", new UpdateUserRequest(null, "editor", null, null, null), ProtocolJson.Default.UpdateUserRequest))
|
|
await demote.ExpectErrorAsync(HttpStatusCode.Conflict, "self");
|
|
using (var delete = await admin.DeleteAsync($"/api/v1/users/{self.Id}")) await delete.ExpectErrorAsync(HttpStatusCode.Conflict, "self");
|
|
}
|
|
|
|
[Test]
|
|
public async Task ResettingOnesOwnPasswordIsRefusedAndTheSessionSurvives()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var admin = await server.AdminAsync();
|
|
using var me = await admin.GetAsync("/api/v1/auth/me");
|
|
var self = await me.ReadAsync(ProtocolJson.Default.UserDto);
|
|
using (var reset = await admin.PostAsJsonAsync($"/api/v1/users/{self.Id}/reset-password", new ResetPasswordRequest(null), ProtocolJson.Default.ResetPasswordRequest))
|
|
await reset.ExpectErrorAsync(HttpStatusCode.Conflict, "self");
|
|
using var still = await admin.GetAsync("/api/v1/auth/me");
|
|
Assert.False((await still.ReadAsync(ProtocolJson.Default.UserDto)).MustChangePassword);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TheSignInLogListsFailedAttemptsToo()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var admin = await server.AdminAsync();
|
|
using (var wrong = await server.Client.PostAsJsonAsync("/api/v1/auth/login", new LoginRequest("admin", "not-the-password", "tests"), ProtocolJson.Default.LoginRequest))
|
|
Assert.Equal(HttpStatusCode.Unauthorized, wrong.StatusCode);
|
|
using var log = await admin.GetAsync("/api/v1/audit?action=login,login_failed");
|
|
var actions = (await log.ReadAsync(ProtocolJson.Default.PageAuditEntryDto)).Items.Select(e => e.Action).ToHashSet();
|
|
Assert.True(actions.SetEquals(["login", "login_failed"]), string.Join(",", actions));
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeletingAUserHandsTheirSequencesToTheAdmin()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var (editor, user, _) = await server.UserAsync("simone", "editor");
|
|
using var created = await editor.PostAsJsonAsync("/api/v1/sequences", new CreateSequenceRequest("Comet", null), ProtocolJson.Default.CreateSequenceRequest);
|
|
var sequence = await created.ReadAsync(ProtocolJson.Default.SequenceDto);
|
|
var admin = await server.AdminAsync();
|
|
using (var deleted = await admin.DeleteAsync($"/api/v1/users/{user.Id}")) await deleted.ExpectAsync(HttpStatusCode.NoContent);
|
|
using var me = await admin.GetAsync("/api/v1/auth/me");
|
|
var adminId = (await me.ReadAsync(ProtocolJson.Default.UserDto)).Id;
|
|
Assert.Equal(adminId, (await server.Database.Sequences.GetAsync(sequence.Id))!.OwnerUserId);
|
|
using var audit = await admin.GetAsync("/api/v1/audit?action=user_deleted");
|
|
Assert.Count(1, (await audit.ReadAsync(ProtocolJson.Default.PageAuditEntryDto)).Items);
|
|
}
|
|
}
|