keypair err mgt + shorturl random improve

This commit is contained in:
ycc
2026-02-02 15:11:41 +01:00
parent f8537aad6d
commit f498cfad1e
23 changed files with 778 additions and 1052 deletions

View File

@@ -9,10 +9,14 @@ import (
)
func TestGetUid(t *testing.T) {
k, err := meowlib.NewKeyPair()
if err != nil {
t.Fatal(err)
}
srv := Server{
Name: "test",
Url: "http://127.0.0.1:8080",
PublicKey: meowlib.NewKeyPair().Public,
PublicKey: k.Public,
}
uid := srv.GetUid()
if uid != "http://127.0.0.1:8080" {
@@ -21,14 +25,18 @@ func TestGetUid(t *testing.T) {
}
func TestStoreServer(t *testing.T) {
createId()
createId(t)
ss := ServerStorage{DbFile: "test.db"}
k, err := meowlib.NewKeyPair()
if err != nil {
t.Fatal(err)
}
srv := Server{
Name: "test",
Url: "http://127.0.0.1",
PublicKey: meowlib.NewKeyPair().Public,
PublicKey: k.Public,
}
err := ss.StoreServer(&srv)
err = ss.StoreServer(&srv)
if err != nil {
log.Fatal(err)
}
@@ -49,15 +57,19 @@ func TestStoreServer(t *testing.T) {
}
func TestLoadServersFromUids(t *testing.T) {
createId()
createId(t)
GetConfig().SetMemPass("test")
ss := ServerStorage{DbFile: "test.db"}
k, err := meowlib.NewKeyPair()
if err != nil {
t.Fatal(err)
}
srv := Server{
Name: "test",
Url: "http://localhost:8080",
PublicKey: meowlib.NewKeyPair().Public,
PublicKey: k.Public,
}
err := ss.StoreServer(&srv)
err = ss.StoreServer(&srv)
if err != nil {
log.Fatal(err)
}
@@ -77,14 +89,18 @@ func TestLoadServersFromUids(t *testing.T) {
}
func TestLoadServerCardsFromUids(t *testing.T) {
createId()
createId(t)
ss := ServerStorage{DbFile: "test.db"}
k, err := meowlib.NewKeyPair()
if err != nil {
t.Fatal(err)
}
srv := Server{
Name: "test",
Url: "http://localhost:8080",
PublicKey: meowlib.NewKeyPair().Public,
PublicKey: k.Public,
}
err := ss.StoreServer(&srv)
err = ss.StoreServer(&srv)
if err != nil {
log.Fatal(err)
}
@@ -104,13 +120,16 @@ func TestLoadServerCardsFromUids(t *testing.T) {
}
func TestServerExists(t *testing.T) {
createId()
createId(t)
ss := ServerStorage{DbFile: "test.db"}
k, err := meowlib.NewKeyPair()
if err != nil {
t.Fatal(err)
}
server := &Server{
Name: "test",
Url: "http://localhost:8080",
PublicKey: meowlib.NewKeyPair().Public,
PublicKey: k.Public,
}
// Check if server exists before storing it
@@ -142,13 +161,16 @@ func TestServerExists(t *testing.T) {
}
func TestStoreServerIfNotExists(t *testing.T) {
createId()
createId(t)
ss := ServerStorage{DbFile: "test.db"}
k, err := meowlib.NewKeyPair()
if err != nil {
t.Fatal(err)
}
server := &Server{
Name: "test",
Url: "http://localhost:8080",
PublicKey: meowlib.NewKeyPair().Public,
PublicKey: k.Public,
}
// Check if server exists before storing it
@@ -181,26 +203,32 @@ func TestStoreServerIfNotExists(t *testing.T) {
}
func TestStoreServerIfNotExists_ServerExists(t *testing.T) {
createId()
createId(t)
ss := ServerStorage{DbFile: "test.db"}
k, err := meowlib.NewKeyPair()
if err != nil {
t.Fatal(err)
}
server := &Server{
Name: "test",
Url: "http://localhost:8080",
PublicKey: meowlib.NewKeyPair().Public,
PublicKey: k.Public,
}
// Store the server
err := ss.StoreServer(server)
err = ss.StoreServer(server)
if err != nil {
t.Errorf("Failed to store server: %v", err)
}
k, err = meowlib.NewKeyPair()
if err != nil {
t.Fatal(err)
}
// Store the server again with a different public key
newServer := &Server{
Name: "test",
Url: "http://localhost:8080",
PublicKey: meowlib.NewKeyPair().Public,
PublicKey: k.Public,
}
err = ss.StoreServerIfNotExists(newServer)