[PATCH go-jmap] request: include the core capability for all method calls
Export this patch
The RFCs 8620 and 8621 have been updated with an errata:
> The "urn:ietf:params:jmap:core" capability represents this document
> and MUST be included in the "using" list.
All method calls MUST include the core capability. Some server
implementations reject the requests performed with go-jmap when it is
missing.
To avoid updating all methods, forcefully add the capability when
performing a request in Client.Do() if it is missing. Move the constant
definition to the root module to avoid import cycles.
Link: https://www.rfc-editor.org/errata/eid6606
Reported-by: Benoit Tellier <btellier@linagora.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
---
Applied. Thanks! I'll tag a release and send an update for aerc.
client.go | 14 ++++++++++++++
core/blob/copy.go | 3 + --
core/core.go | 4 + ---
core/echo.go | 2 + -
core/echo_test.go | 2 + -
core/push/subscription/get.go | 3 + --
core/push/subscription/set.go | 3 + --
7 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/client.go b/client.go
index b0c461f2db9e..06e7891ce64b 100644
--- a/client.go
+++ b/client.go
@@ -103,6 +103,9 @@ func (c *Client) Authenticate() error {
return nil
}
+ // The core capabilty must be included in all method calls
+ const CoreURI URI = "urn:ietf:params:jmap:core"
+
// Do performs a JMAP request and returns the response
func (c *Client) Do(req *Request) (*Response, error) {
c.Lock()
@@ -115,6 +118,17 @@ func (c *Client) Do(req *Request) (*Response, error) {
} else {
c.Unlock()
}
+ // Ensure the core capability is always included
+ found := false
+ for _, uri := range req.Using {
+ if uri == CoreURI {
+ found = true
+ break
+ }
+ }
+ if !found {
+ req.Using = append(req.Using, CoreURI)
+ }
// Check the required capabilities before making the request
for _, uri := range req.Using {
c.Lock()
diff --git a/core/blob/copy.go b/core/blob/copy.go
index 5a380ff205ff..89dcd4203cc9 100644
--- a/core/blob/copy.go
+++ b/core/blob/copy.go
@@ -2,7 +2,6 @@ package blob
import (
"git.sr.ht/~rockorager/go-jmap"
- "git.sr.ht/~rockorager/go-jmap/core"
)
// Copy a binary blob from one account to another
@@ -17,7 +16,7 @@ type Copy struct {
func (m *Copy) Name() string { return "Blob/copy" }
- func (m *Copy) Requires() []jmap.URI { return []jmap.URI{core.URI} }
+ func (m *Copy) Requires() []jmap.URI { return nil }
type CopyResponse struct {
FromAccount jmap.ID `json:"fromAccountId,omitempty"`
diff --git a/core/core.go b/core/core.go
index 33752a6e743e..dfd1ee14890e 100644
--- a/core/core.go
+++ b/core/core.go
@@ -2,8 +2,6 @@ package core
import "git.sr.ht/~rockorager/go-jmap"
- const URI jmap.URI = "urn:ietf:params:jmap:core"
-
func init() {
jmap.RegisterCapability(&Core{})
jmap.RegisterMethod("Core/echo", newEcho)
@@ -26,6 +24,6 @@ type Core struct {
CollationAlgorithms []jmap.CollationAlgo `json:"collationAlgorithms"`
}
- func (c *Core) URI() jmap.URI { return URI }
+ func (c *Core) URI() jmap.URI { return jmap.CoreURI }
func (c *Core) New() jmap.Capability { return &Core{} }
diff --git a/core/echo.go b/core/echo.go
index f21c38aab069..466ce51291c7 100644
--- a/core/echo.go
+++ b/core/echo.go
@@ -11,7 +11,7 @@ func (e Echo) Name() string {
return "Core/echo"
}
- func (e Echo) Requires() []jmap.URI { return []jmap.URI{URI} }
+ func (e Echo) Requires() []jmap.URI { return nil }
func newEcho() jmap.MethodResponse {
return &Echo{}
diff --git a/core/echo_test.go b/core/echo_test.go
index c4cc4916c6bd..4766e8aff285 100644
--- a/core/echo_test.go
+++ b/core/echo_test.go
@@ -17,6 +17,6 @@ func TestEcho(t *testing.T) {
req.Invoke(echo)
data, err := json.Marshal(req)
assert.NoError(t, err)
- exp := `{"using":["urn:ietf:params:jmap:core"],"methodCalls":[["Core/echo",{"Hello":"world"},"0"]]}`
+ exp := `{"using":[],"methodCalls":[["Core/echo",{"Hello":"world"},"0"]]}`
assert.Equal(t, exp, string(data))
}
diff --git a/core/push/subscription/get.go b/core/push/subscription/get.go
index 84c0185bf59f..58d92fd47ab6 100644
--- a/core/push/subscription/get.go
+++ b/core/push/subscription/get.go
@@ -2,7 +2,6 @@ package subscription
import (
"git.sr.ht/~rockorager/go-jmap"
- "git.sr.ht/~rockorager/go-jmap/core"
)
// Get push subscription details
@@ -14,7 +13,7 @@ type Get struct {
func (m *Get) Name() string { return "PushSubscription/get" }
- func (m *Get) Requires() []jmap.URI { return []jmap.URI{core.URI} }
+ func (m *Get) Requires() []jmap.URI { return nil }
type GetResponse struct {
List []*PushSubscription `json:"list,omitempty"`
diff --git a/core/push/subscription/set.go b/core/push/subscription/set.go
index 02ad7763e497..eb1f1c92d958 100644
--- a/core/push/subscription/set.go
+++ b/core/push/subscription/set.go
@@ -2,7 +2,6 @@ package subscription
import (
"git.sr.ht/~rockorager/go-jmap"
- "git.sr.ht/~rockorager/go-jmap/core"
)
// Modify push subscription details
@@ -15,7 +14,7 @@ type Set struct {
func (m *Set) Name() string { return "PushSubscription/set" }
- func (m *Set) Requires() []jmap.URI { return []jmap.URI{core.URI} }
+ func (m *Set) Requires() []jmap.URI { return nil }
type SetResponse struct {
Created map[jmap.ID]*PushSubscription `json:"created,omitempty"`
--
2.48.1