mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-02 04:31:34 -05:00
fix(server): reject duplicate nest ids, invalid metadata and bare --database
- POST /api/nests with an existing id (active or deleted) now returns 409 with the current record instead of a 500 from the UNIQUE constraint. - Uploaded nest metadata must have string text fields and a defined status; null fields and undefined statuses (e.g. 99) are 400 instead of a 500 or a stored invalid value. - --database <path> is accepted alongside --database=<path>; a missing or repeated path fails startup instead of silently using OPENNEST_DB/default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a7073d38c
commit
5dff83cfb8
7 files changed
+309
-37
No files matched your search
@@ -0,0 +1,34 @@
|
||||
namespace OpenNest.Server.Tests;
|
||||
|
||||
public sealed class ServerOptionsTests
|
||||
{
|
||||
private static readonly string Default = Path.Combine("data", "nests.db");
|
||||
|
||||
[Theory]
|
||||
[InlineData(new[] { "--database=/srv/a.db" }, "/srv/a.db")]
|
||||
[InlineData(new[] { "--database", "/srv/a.db" }, "/srv/a.db")]
|
||||
[InlineData(new[] { "--urls=http://127.0.0.1:8090", "--database", "/srv/a.db" }, "/srv/a.db")]
|
||||
[InlineData(new[] { "--database=/srv/a=b.db" }, "/srv/a=b.db")]
|
||||
public void DatabasePath_AcceptsBothForms_AndOverridesEnvironment(string[] args, string expected)
|
||||
{
|
||||
Assert.Equal(expected, ServerOptions.DatabasePath(args, "/env/nests.db"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DatabasePath_WithoutArgument_UsesEnvironmentThenDefault()
|
||||
{
|
||||
Assert.Equal("/env/nests.db", ServerOptions.DatabasePath(["--urls=http://127.0.0.1:8090"], "/env/nests.db"));
|
||||
Assert.Equal(Default, ServerOptions.DatabasePath([], null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("--database")]
|
||||
[InlineData("--database", "--urls=http://127.0.0.1:8090")]
|
||||
[InlineData("--database=")]
|
||||
[InlineData("--database= ")]
|
||||
[InlineData("--database=/a.db", "--database", "/b.db")]
|
||||
public void DatabasePath_MissingOrRepeated_FailsInsteadOfFallingBack(params string[] args)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => ServerOptions.DatabasePath(args, "/env/nests.db"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user