Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cluster/community_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/tootik/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
41 changes: 20 additions & 21 deletions fed/deliver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions front/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions front/user/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
{
Expand Down Expand Up @@ -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},
Expand Down
3 changes: 1 addition & 2 deletions test/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand Down
6 changes: 3 additions & 3 deletions test/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading