diff --git a/cluster/community_test.go b/cluster/community_test.go index 62219e63..c3131361 100644 --- a/cluster/community_test.go +++ b/cluster/community_test.go @@ -27,7 +27,7 @@ func TestCluster_PostInCommunity(t *testing.T) { cluster := NewCluster(t, "a.localdomain", "b.localdomain", "g.localdomain") defer cluster.Stop() - if _, _, err := user.Create(t.Context(), "g.localdomain", cluster["g.localdomain"].DB, cluster["g.localdomain"].Config, "stuff", ap.Group, nil); err != nil { + if _, _, err := user.CreatePortable(t.Context(), "g.localdomain", cluster["g.localdomain"].DB, cluster["g.localdomain"].Config, "stuff", ap.Group, nil); err != nil { t.Fatal("Failed to create community") } @@ -93,7 +93,7 @@ func TestCluster_ReplyInCommunity(t *testing.T) { cluster := NewCluster(t, "a.localdomain", "b.localdomain", "g.localdomain") defer cluster.Stop() - if _, _, err := user.Create(t.Context(), "g.localdomain", cluster["g.localdomain"].DB, cluster["g.localdomain"].Config, "stuff", ap.Group, nil); err != nil { + if _, _, err := user.CreatePortable(t.Context(), "g.localdomain", cluster["g.localdomain"].DB, cluster["g.localdomain"].Config, "stuff", ap.Group, nil); err != nil { t.Fatal("Failed to create community") } diff --git a/cmd/tootik/main.go b/cmd/tootik/main.go index 393460f2..e1a33b54 100644 --- a/cmd/tootik/main.go +++ b/cmd/tootik/main.go @@ -206,7 +206,7 @@ func main() { switch cmd { case "add-community": - _, _, err := user.Create(ctx, *domain, db, &cfg, flag.Arg(1), ap.Group, nil) + _, _, err := user.CreatePortable(ctx, *domain, db, &cfg, flag.Arg(1), ap.Group, nil) if err != nil { panic(err) } diff --git a/fed/deliver_test.go b/fed/deliver_test.go index 11daa95f..a7d28b69 100644 --- a/fed/deliver_test.go +++ b/fed/deliver_test.go @@ -25,7 +25,6 @@ import ( "os" "testing" - "github.com/dimkr/tootik/ap" "github.com/dimkr/tootik/cfg" "github.com/dimkr/tootik/front/user" "github.com/dimkr/tootik/migrations" @@ -62,10 +61,10 @@ func TestDeliver_TwoUsersTwoPosts(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) - bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", ap.Person, nil) + bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", nil) assert.NoError(err) _, err = db.Exec( @@ -166,10 +165,10 @@ func TestDeliver_ForwardedPost(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) - bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", ap.Person, nil) + bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", nil) assert.NoError(err) _, err = db.Exec( @@ -265,10 +264,10 @@ func TestDeliver_OneFailed(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) - bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", ap.Person, nil) + bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", nil) assert.NoError(err) _, err = db.Exec( @@ -378,7 +377,7 @@ func TestDeliver_OneFailedRetry(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) _, err = db.Exec( @@ -471,7 +470,7 @@ func TestDeliver_OneInvalidURLRetry(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) _, err = db.Exec( @@ -564,7 +563,7 @@ func TestDeliver_MaxAttempts(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) _, err = db.Exec( @@ -658,7 +657,7 @@ func TestDeliver_SharedInbox(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) _, err = db.Exec( @@ -744,7 +743,7 @@ func TestDeliver_SharedInboxRetry(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) _, err = db.Exec( @@ -853,7 +852,7 @@ func TestDeliver_SharedInboxUnknownActor(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) _, err = db.Exec( @@ -941,7 +940,7 @@ func TestDeliver_SharedInboxSingleWorker(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) _, err = db.Exec( @@ -1027,7 +1026,7 @@ func TestDeliver_SameInbox(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) _, err = db.Exec( @@ -1113,10 +1112,10 @@ func TestDeliver_ToAndCCDuplicates(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) - bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", ap.Person, nil) + bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", nil) assert.NoError(err) _, err = db.Exec( @@ -1217,10 +1216,10 @@ func TestDeliver_PublicInTo(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) - bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", ap.Person, nil) + bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", nil) assert.NoError(err) _, err = db.Exec( @@ -1321,10 +1320,10 @@ func TestDeliver_AuthorInTo(t *testing.T) { assert.NoError(migrations.Run(context.Background(), "localhost.localdomain", db)) - alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "alice", nil) assert.NoError(err) - bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", ap.Person, nil) + bob, _, err := user.Create(context.Background(), "localhost.localdomain", db, &cfg, "bob", nil) assert.NoError(err) _, err = db.Exec( diff --git a/front/register.go b/front/register.go index 7fbb5217..f4484c81 100644 --- a/front/register.go +++ b/front/register.go @@ -96,14 +96,14 @@ func (h *Handler) register(w text.Writer, r *Request, args ...string) { if h.Config.EnablePortableActorRegistration { w.Status(10, "Create portable user? (y/n)") return - } else if _, _, err := user.Create(r.Context, h.Domain, h.DB, h.Config, userName, ap.Person, clientCert); err != nil { + } else if _, _, err := user.Create(r.Context, h.Domain, h.DB, h.Config, userName, clientCert); err != nil { r.Log.Warn("Failed to create new user", "name", userName, "error", err) w.Status(40, "Failed to create new user") return } case "n": - if _, _, err := user.Create(r.Context, h.Domain, h.DB, h.Config, userName, ap.Person, clientCert); err != nil { + if _, _, err := user.Create(r.Context, h.Domain, h.DB, h.Config, userName, clientCert); err != nil { r.Log.Warn("Failed to create new user", "name", userName, "error", err) w.Status(40, "Failed to create new user") return diff --git a/front/user/create.go b/front/user/create.go index f4709d78..271e6329 100644 --- a/front/user/create.go +++ b/front/user/create.go @@ -242,7 +242,7 @@ func CreatePortableWithKey( } // Create creates a new user. -func Create(ctx context.Context, domain string, db *sql.DB, cfg *cfg.Config, name string, actorType ap.ActorType, cert *x509.Certificate) (*ap.Actor, [2]httpsig.Key, error) { +func Create(ctx context.Context, domain string, db *sql.DB, cfg *cfg.Config, name string, cert *x509.Certificate) (*ap.Actor, [2]httpsig.Key, error) { rsaPriv, rsaPubPem, err := generateRSAKey() if err != nil { return nil, [2]httpsig.Key{}, fmt.Errorf("failed to generate RSA key pair: %w", err) @@ -261,7 +261,7 @@ func Create(ctx context.Context, domain string, db *sql.DB, cfg *cfg.Config, nam "https://w3id.org/security/v1", }, ID: id, - Type: actorType, + Type: ap.Person, PreferredUsername: name, Icon: []ap.Attachment{ { @@ -293,20 +293,6 @@ func Create(ctx context.Context, domain string, db *sql.DB, cfg *cfg.Config, nam Published: ap.Time{Time: time.Now()}, } - if actorType == ap.Application { - actor.Generator.Type = ap.Application - actor.Generator.Implements = []ap.Implement{ - { - Name: "RFC-9421: HTTP Message Signatures", - Href: "https://datatracker.ietf.org/doc/html/rfc9421", - }, - { - Name: "RFC-9421 signatures using the Ed25519 algorithm", - Href: "https://datatracker.ietf.org/doc/html/rfc9421#name-eddsa-using-curve-edwards25", - }, - } - } - keys := [2]httpsig.Key{ {ID: actor.PublicKey.ID, PrivateKey: rsaPriv}, {ID: actor.AssertionMethod[0].ID, PrivateKey: ed25519Priv}, diff --git a/test/register_test.go b/test/register_test.go index 4697ad06..ec8d4d5d 100644 --- a/test/register_test.go +++ b/test/register_test.go @@ -29,7 +29,6 @@ import ( "sync" "testing" - "github.com/dimkr/tootik/ap" "github.com/dimkr/tootik/cfg" "github.com/dimkr/tootik/fed" "github.com/dimkr/tootik/front" @@ -749,7 +748,7 @@ func TestRegister_AlreadyRegistered(t *testing.T) { _, err = tlsReader.Write([]byte("gemini://localhost.localdomain:8965/users/register\r\n")) assert.NoError(err) - _, _, err = user.Create(context.Background(), domain, db, &cfg, "erin", ap.Person, erinKeyPair.Leaf) + _, _, err = user.Create(context.Background(), domain, db, &cfg, "erin", erinKeyPair.Leaf) assert.NoError(err) handler, err := front.NewHandler(domain, &cfg, fed.NewResolver(nil, domain, &cfg, &http.Client{}, db), db, &inbox.Inbox{}) diff --git a/test/server.go b/test/server.go index 4b8cc431..0cf3da71 100644 --- a/test/server.go +++ b/test/server.go @@ -79,17 +79,17 @@ func newTestServer() *server { panic(err) } - alice, _, err := user.Create(context.Background(), domain, db, &cfg, "alice", ap.Person, nil) + alice, _, err := user.Create(context.Background(), domain, db, &cfg, "alice", nil) if err != nil { panic(err) } - bob, _, err := user.Create(context.Background(), domain, db, &cfg, "bob", ap.Person, nil) + bob, _, err := user.Create(context.Background(), domain, db, &cfg, "bob", nil) if err != nil { panic(err) } - carol, _, err := user.Create(context.Background(), domain, db, &cfg, "carol", ap.Person, nil) + carol, _, err := user.Create(context.Background(), domain, db, &cfg, "carol", nil) if err != nil { panic(err) }