Check complete Home binding within meeting transactions
4 files changed,
+15
−9
go.mod+1 −1go.sum+2 −0internal/calls/delegated_authority.go+9 −7internal/calls/delegated_authority_test.go+3 −1
CI passed — run details
diff --git a/go.mod b/go.mod| index 75cfee9..aeab612 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -5,7 +5,7 @@ go 1.26.0 |
| require ( |
| amadan.net/oficina/agent-access.git v0.0.0-20261024232549-8ed8ba826000 |
| amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768 |
| - 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/go-chi/chi/v5 v5.3.2 |
diff --git a/go.sum b/go.sum| index 69d2119..0749a50 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/rastrillo v0.27.1-0.20261006204347-fb806a287060 h1:K2PXcCKfm+AYrqgH1ea6cNsFs4sN7MKLvq+uBY11NZE= |
diff --git a/internal/calls/delegated_authority.go b/internal/calls/delegated_authority.go| index 8e23dc4..e4f2966 100644 |
| --- a/internal/calls/delegated_authority.go |
| +++ b/internal/calls/delegated_authority.go |
| @@ -3,13 +3,13 @@ package calls |
| 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) checkDelegatedWriter(ctx context.Context, tx *gorm.DB, p access.Pr |
| if e := check(ctx, p); e != nil { |
| return 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 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 access.Fail("forbidden", "The linked identity is unavailable.") |
| + } |
| + if e != nil { |
| return e |
| } |
| - if id != expected.ID { |
| + if person.ID != expected.ID || person.Label != expected.Email { |
| return access.Fail("forbidden", "The linked identity changed.") |
| } |
| + id := person.ID |
| + |
| currentStore := *a.store |
| currentStore.g = tx |
| current, exists, e := currentStore.personByID(ctx, id) |
diff --git a/internal/calls/delegated_authority_test.go b/internal/calls/delegated_authority_test.go| index 2440639..e334380 100644 |
| --- a/internal/calls/delegated_authority_test.go |
| +++ b/internal/calls/delegated_authority_test.go |
| @@ -16,7 +16,7 @@ import ( |
| ) |
| func TestDelegatedPrecommitAuthority(t *testing.T) { |
| - for _, mode := range []string{"reserved-revoke", "final-revoke", "unlink", "member"} { |
| + for _, mode := range []string{"reserved-revoke", "final-revoke", "binding", "unlink", "member"} { |
| t.Run(mode, func(t *testing.T) { |
| f, p := linkedDelegated(t) |
| var checks atomic.Int64 |
| @@ -35,6 +35,8 @@ func TestDelegatedPrecommitAuthority(t *testing.T) { |
| trigger = "CREATE TRIGGER body_must_not_run BEFORE INSERT ON meetings BEGIN SELECT RAISE(ABORT,'body attempted'); END" |
| case "unlink": |
| trigger = "CREATE TRIGGER lose_authority AFTER UPDATE OF meeting_id ON calls_agent_meetings BEGIN DELETE FROM home_identity_links; END" |
| + case "binding": |
| + trigger = "CREATE TRIGGER lose_binding AFTER INSERT ON meetings BEGIN UPDATE home_identity_links SET person_binding='broken'; END" |
| case "member": |
| trigger = "CREATE TRIGGER lose_authority AFTER UPDATE OF meeting_id ON calls_agent_meetings BEGIN UPDATE persons SET anonymous=1; END" |
| } |