Drive: - Add context propagation to all API calls - Add path traversal security fix in download Gmail: - Add context propagation to labels and thread commands - Simplify MIME building (remove unused ReplyTo, BodyHTML) - Add --from flag for send-as aliases in send and drafts - Simplify base64 decoding - Add path traversal security fix in attachments Calendar: - Add needsAction status support to respond command - Add --comment flag for response comments - Add organizer check to prevent self-response Auth: - Add browser-based account management command (auth manage) - Add web UI for managing connected accounts Maintenance: - Update golangci-lint config for v2 compatibility
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"testing"
|
|
|
|
"google.golang.org/api/gmail/v1"
|
|
)
|
|
|
|
func TestCollectAttachments(t *testing.T) {
|
|
p := &gmail.MessagePart{
|
|
Parts: []*gmail.MessagePart{
|
|
{
|
|
Filename: "a.txt",
|
|
MimeType: "text/plain",
|
|
Body: &gmail.MessagePartBody{AttachmentId: "att1", Size: 123},
|
|
},
|
|
{
|
|
Parts: []*gmail.MessagePart{
|
|
{
|
|
Filename: "b.pdf",
|
|
MimeType: "application/pdf",
|
|
Body: &gmail.MessagePartBody{AttachmentId: "att2", Size: 456},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
atts := collectAttachments(p)
|
|
if len(atts) != 2 {
|
|
t.Fatalf("unexpected: %#v", atts)
|
|
}
|
|
if atts[0].AttachmentID == "" || atts[1].AttachmentID == "" {
|
|
t.Fatalf("missing attachment ids: %#v", atts)
|
|
}
|
|
}
|
|
|
|
func TestBestBodyTextPrefersPlain(t *testing.T) {
|
|
plain := base64.RawURLEncoding.EncodeToString([]byte("plain"))
|
|
html := base64.RawURLEncoding.EncodeToString([]byte("<b>html</b>"))
|
|
p := &gmail.MessagePart{
|
|
Parts: []*gmail.MessagePart{
|
|
{MimeType: "text/html", Body: &gmail.MessagePartBody{Data: html}},
|
|
{MimeType: "text/plain", Body: &gmail.MessagePartBody{Data: plain}},
|
|
},
|
|
}
|
|
if got := bestBodyText(p); got != "plain" {
|
|
t.Fatalf("unexpected: %q", got)
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64URL(t *testing.T) {
|
|
got, err := decodeBase64URL(base64.RawURLEncoding.EncodeToString([]byte("ok")))
|
|
if err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
if got != "ok" {
|
|
t.Fatalf("unexpected: %q", got)
|
|
}
|
|
if _, err := decodeBase64URL("!!!"); err == nil {
|
|
t.Fatalf("expected error")
|
|
}
|
|
}
|