This commit is contained in:
john 2025-05-16 16:10:01 +02:00
parent 14fd359ea8
commit a4ef2b4a20
26 changed files with 331 additions and 78 deletions

View file

@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Geralt" Version="3.3.0" />
<PackageReference Include="Npgsql" Version="9.0.3" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

View file

@ -59,5 +59,16 @@ CREATE SCHEMA authn;
CREATE TABLE authn.user_identity
(
);
id uuid PRIMARY KEY,
username text NOT NULL UNIQUE,
password_hash bytea,
password_salt bytea
);
CREATE TABLE authn.user_session
(
id varchar(256) PRIMARY KEY,
user_id uuid NOT NULL REFERENCES authn.user_identity (id) ON DELETE CASCADE,
expires timestamptz NOT NULL
);

View file

@ -1,26 +1,46 @@
using System.Text;
using Geralt;
using Npgsql;
namespace Femto.Database.Seed;
public static class TestDataSeeder
{
private const int Iterations = 3;
private const int MemorySize = 67108864;
public static async Task Seed(NpgsqlDataSource dataSource)
{
var id = Guid.Parse("0196960c-6296-7532-ba66-8fabb38c6ae0");
var username = "johnbotris";
var salt = new byte[32];
var password = "hunter2"u8;
var hashInput = new byte[password.Length + salt.Length];
password.CopyTo(hashInput);
salt.CopyTo(hashInput, password.Length);
var passwordHash = new byte[128];
Argon2id.ComputeHash(
passwordHash,
hashInput,
Iterations,
MemorySize
);
await using var addToHistoryCommand = dataSource.CreateCommand(
"""
$"""
INSERT INTO blog.author
(id, username)
VALUES
('0196960c-6296-7532-ba66-8fabb38c6ae0', 'johnbotris')
(@id, @username)
;
INSERT INTO blog.post
(id, author_id, content)
VALUES
('019691a0-48ed-7eba-b8d3-608e25e07d4b', '0196960c-6296-7532-ba66-8fabb38c6ae0', 'However, authors often misinterpret the zoology as a smothered advantage, when in actuality it feels more like a blindfold accordion. They were lost without the chastest puppy that composed their Santa.'),
('019691a0-4ace-7bb5-a8f3-e3362920eba0', '0196960c-6296-7532-ba66-8fabb38c6ae0', 'Extending this logic, a swim can hardly be considered a seasick duckling without also being a tornado. Some posit the whity voyage to be less than dippy.'),
('019691a0-4c3e-726f-b8f6-bcbaabe789ae', '0196960c-6296-7532-ba66-8fabb38c6ae0','Few can name a springless sun that isn''t a thudding Vietnam. The burn of a competitor becomes a frosted target.'),
('019691a0-4dd3-7e89-909e-94a6fd19a05e', '0196960c-6296-7532-ba66-8fabb38c6ae0','Some unwitched marbles are thought of simply as currencies. A boundary sees a nepal as a chordal railway.')
('019691a0-48ed-7eba-b8d3-608e25e07d4b', @id, 'However, authors often misinterpret the zoology as a smothered advantage, when in actuality it feels more like a blindfold accordion. They were lost without the chastest puppy that composed their Santa.'),
('019691a0-4ace-7bb5-a8f3-e3362920eba0', @id, 'Extending this logic, a swim can hardly be considered a seasick duckling without also being a tornado. Some posit the whity voyage to be less than dippy.'),
('019691a0-4c3e-726f-b8f6-bcbaabe789ae', @id,'Few can name a springless sun that isn''t a thudding Vietnam. The burn of a competitor becomes a frosted target.'),
('019691a0-4dd3-7e89-909e-94a6fd19a05e', @id,'Some unwitched marbles are thought of simply as currencies. A boundary sees a nepal as a chordal railway.')
;
INSERT INTO blog.post_media
@ -33,9 +53,19 @@ public static class TestDataSeeder
('019691b6-07cb-7353-8c33-68456188f462', '019691a0-4c3e-726f-b8f6-bcbaabe789ae', 'https://wallpapers.com/images/hd/big-chungus-2bxloyitgw7q1hfg.jpg', 1),
('019691b6-2608-7088-8110-f0f6e35fa633', '019691a0-4dd3-7e89-909e-94a6fd19a05e', 'https://www.pinclipart.com/picdir/big/535-5356059_big-transparent-chungus-png-background-big-chungus-clipart.png', 0)
;
INSERT INTO authn.user_identity
(id, username, password_hash, password_salt)
VALUES
(@id, @username, @passwordHash, @salt);
"""
);
addToHistoryCommand.Parameters.AddWithValue("@id", id);
addToHistoryCommand.Parameters.AddWithValue("@username", username);
addToHistoryCommand.Parameters.AddWithValue("@passwordHash", passwordHash);
addToHistoryCommand.Parameters.AddWithValue("@salt", salt);
await addToHistoryCommand.ExecuteNonQueryAsync();
}
}
}