mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 16:17:03 +00:00
Fix empty label name
This commit is contained in:
@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
package pmapi
|
package pmapi
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
// System labels
|
// System labels
|
||||||
const (
|
const (
|
||||||
@ -129,6 +132,10 @@ type LabelRes struct {
|
|||||||
|
|
||||||
// CreateLabel creates a new label.
|
// CreateLabel creates a new label.
|
||||||
func (c *client) CreateLabel(label *Label) (created *Label, err error) {
|
func (c *client) CreateLabel(label *Label) (created *Label, err error) {
|
||||||
|
if label.Name == "" {
|
||||||
|
return nil, errors.New("name is required")
|
||||||
|
}
|
||||||
|
|
||||||
labelReq := &LabelReq{label}
|
labelReq := &LabelReq{label}
|
||||||
req, err := c.NewJSONRequest("POST", "/labels", labelReq)
|
req, err := c.NewJSONRequest("POST", "/labels", labelReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -146,6 +153,10 @@ func (c *client) CreateLabel(label *Label) (created *Label, err error) {
|
|||||||
|
|
||||||
// UpdateLabel updates a label.
|
// UpdateLabel updates a label.
|
||||||
func (c *client) UpdateLabel(label *Label) (updated *Label, err error) {
|
func (c *client) UpdateLabel(label *Label) (updated *Label, err error) {
|
||||||
|
if label.Name == "" {
|
||||||
|
return nil, errors.New("name is required")
|
||||||
|
}
|
||||||
|
|
||||||
labelReq := &LabelReq{label}
|
labelReq := &LabelReq{label}
|
||||||
req, err := c.NewJSONRequest("PUT", "/labels/"+label.ID, labelReq)
|
req, err := c.NewJSONRequest("PUT", "/labels/"+label.ID, labelReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -147,6 +147,16 @@ func TestClient_CreateLabel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_CreateEmptyLabel(t *testing.T) {
|
||||||
|
s, c := newTestServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
|
||||||
|
r.Fail(t, "API should not be called")
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
_, err := c.CreateLabel(&Label{})
|
||||||
|
r.EqualError(t, err, "name is required")
|
||||||
|
}
|
||||||
|
|
||||||
func TestClient_UpdateLabel(t *testing.T) {
|
func TestClient_UpdateLabel(t *testing.T) {
|
||||||
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
Ok(t, checkMethodAndPath(r, "PUT", "/labels/"+testLabelCreated.ID))
|
Ok(t, checkMethodAndPath(r, "PUT", "/labels/"+testLabelCreated.ID))
|
||||||
@ -173,6 +183,16 @@ func TestClient_UpdateLabel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_UpdateLabelToEmptyName(t *testing.T) {
|
||||||
|
s, c := newTestServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
|
||||||
|
r.Fail(t, "API should not be called")
|
||||||
|
}))
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
_, err := c.UpdateLabel(&Label{ID: "label"})
|
||||||
|
r.EqualError(t, err, "name is required")
|
||||||
|
}
|
||||||
|
|
||||||
func TestClient_DeleteLabel(t *testing.T) {
|
func TestClient_DeleteLabel(t *testing.T) {
|
||||||
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
s, c := newTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
Ok(t, checkMethodAndPath(r, "DELETE", "/labels/"+testLabelCreated.ID))
|
Ok(t, checkMethodAndPath(r, "DELETE", "/labels/"+testLabelCreated.ID))
|
||||||
|
|||||||
@ -22,3 +22,4 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
|
|||||||
* GODT-389 Prefer `From` header instead of `MAIL FROM` address.
|
* GODT-389 Prefer `From` header instead of `MAIL FROM` address.
|
||||||
* GODT-898 Only set ContentID for inline attachments.
|
* GODT-898 Only set ContentID for inline attachments.
|
||||||
* GODT-773 Replace `INTERNALDATE` older than birthday of RFC822 by birthday of RFC822 to not crash Apple Mail.
|
* GODT-773 Replace `INTERNALDATE` older than birthday of RFC822 by birthday of RFC822 to not crash Apple Mail.
|
||||||
|
* GODT-927 Avoid to call API with empty label name.
|
||||||
|
|||||||
Reference in New Issue
Block a user