Check complete Home binding within event transactions
4 files changed,
+16
−9
go.mod+1 −1go.sum+2 −0internal/calendar/agent_authority.go+9 −7internal/calendar/agent_authority_test.go+4 −1
CI passed — run details
diff --git a/go.mod b/go.mod| index 0b10dfd..73a1de6 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -5,7 +5,7 @@ go 1.25.0 |
| toolchain go1.26.5 |
| require ( |
| - amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c |
| + amadan.net/oficina/home/connect v0.0.0-20261025004522-7430dd23a847 |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 |
| amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 |
| github.com/carlosframework/rastrillo v0.23.0 |
diff --git a/go.sum b/go.sum| index cda714f..1c7e30c 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -4,6 +4,8 @@ amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768 h1:bVscoa9fH5Ld |
| amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw= |
| amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c h1:3yxO2D8BxDLMGfFV2o6Sp9Z91yLnjDCIuRKHVWORa8A= |
| amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c/go.mod h1:YroavXe43Wietec+po8mtSk4a9Bir2h31Q3iAf4MWxI= |
| +amadan.net/oficina/home/connect v0.0.0-20261025004522-7430dd23a847 h1:pJYp3kEWLUXXoi4UtRH8SIX+HyAyQUQOaFNE7XuY20Y= |
| +amadan.net/oficina/home/connect v0.0.0-20261025004522-7430dd23a847/go.mod h1:YroavXe43Wietec+po8mtSk4a9Bir2h31Q3iAf4MWxI= |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 h1:RPKtyry/71i06o8L+gjAaUyexbmG56kO1YPs601URAM= |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k= |
| amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 h1:5EFx7BLJj/+G/rt8bTmeyMWVfF5s5Sns7ajTvX4w/I8= |
diff --git a/internal/calendar/agent_authority.go b/internal/calendar/agent_authority.go| index bec2cdb..95b66bc 100644 |
| --- a/internal/calendar/agent_authority.go |
| +++ b/internal/calendar/agent_authority.go |
| @@ -3,13 +3,13 @@ package calendar |
| import ( |
| "context" |
| "crypto/hmac" |
| - "database/sql" |
| "encoding/json" |
| "errors" |
| "net/http" |
| "strings" |
| access "amadan.net/oficina/agent-access.git" |
| + "amadan.net/oficina/home/connect/linkstore" |
| "gorm.io/gorm" |
| ) |
| @@ -62,16 +62,18 @@ func (a *App) checkAgentWriter(ctx context.Context, tx *gorm.DB, p access.Princi |
| if e := check(ctx, p); e != nil { |
| return Person{}, e |
| } |
| - var id int64 |
| - if e := tx.Raw("SELECT person_id FROM home_identity_links WHERE issuer=? AND subject=?", a.cfg.Home.Issuer, p.Subject).Row().Scan(&id); e != nil { |
| - if errors.Is(e, sql.ErrNoRows) { |
| - return Person{}, access.Fail("forbidden", "The linked identity is unavailable.") |
| - } |
| + person, e := a.home.bridge.ResolveOn(ctx, tx.Statement.ConnPool, p.Subject) |
| + if errors.Is(e, linkstore.ErrRefused) { |
| + return Person{}, access.Fail("forbidden", "The linked identity is unavailable.") |
| + } |
| + if e != nil { |
| return Person{}, e |
| } |
| - if id != expected.ID { |
| + if person.ID != expected.ID || person.Label != expected.Address { |
| return Person{}, access.Fail("forbidden", "The linked identity changed.") |
| } |
| + id := person.ID |
| + |
| var current Person |
| if e := tx.First(¤t, id).Error; e != nil { |
| return Person{}, e |
diff --git a/internal/calendar/agent_authority_test.go b/internal/calendar/agent_authority_test.go| index ce4ae06..efa29fb 100644 |
| --- a/internal/calendar/agent_authority_test.go |
| +++ b/internal/calendar/agent_authority_test.go |
| @@ -15,7 +15,7 @@ import ( |
| ) |
| func TestAgentEventPrecommitAuthority(t *testing.T) { |
| - for _, mode := range []string{"reserved-revoke", "final-revoke", "unlink", "grant"} { |
| + for _, mode := range []string{"reserved-revoke", "final-revoke", "binding", "unlink", "grant"} { |
| t.Run(mode, func(t *testing.T) { |
| f, p, _, cal := linkedCalendarAgent(t) |
| var checks atomic.Int64 |
| @@ -34,6 +34,9 @@ func TestAgentEventPrecommitAuthority(t *testing.T) { |
| } |
| } |
| change := "" |
| + if mode == "binding" { |
| + change = "UPDATE home_identity_links SET person_binding='broken'" |
| + } |
| if mode == "unlink" { |
| change = "DELETE FROM home_identity_links" |
| } |