Add receipt_format to stamp and verify. Omitted → text; receipt|PDF-Receipt → PDF; JSON-Receipt → JSON; MD|MD-Receipt; CSV|CSV-Receipt; TSV|TSV-Receipt. Stamp always returns receipts[] and adds artifacts[] in the chosen format. Stdio writes ~/.verae/receipts (0600); public MCP returns content_text/content_base64 only. Verify accepts inline receipt or receipt_path (stdio), parses id, and re-emits an artifact. Vendors pdfcert (+ slim statuslang, gofpdf) for CERT-01 PDF. Also lands welcome tool and email-username helpers already wired into register/public paths.
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package tools
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
func TestLooksLikeCID(t *testing.T) {
|
|
t.Parallel()
|
|
cases := []struct {
|
|
id string
|
|
want bool
|
|
}{
|
|
{"", false},
|
|
{"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", false},
|
|
{"bafyreigdyrzt5sfp7udm7hu76uh7b314167c576e3mgkudqjceaaeeooma", true},
|
|
{"QmYwAPJzv5CZsnA625s3Xf2nemtYkPpHdWQz79JREaLEkF", true},
|
|
{"not-a-local-receipt", true},
|
|
}
|
|
for _, tc := range cases {
|
|
if got := looksLikeCID(tc.id); got != tc.want {
|
|
t.Fatalf("looksLikeCID(%q)=%v want %v", tc.id, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBearerFromRequest(t *testing.T) {
|
|
t.Parallel()
|
|
req := &mcp.CallToolRequest{Extra: &mcp.RequestExtra{Header: http.Header{}}}
|
|
if got := BearerFromRequest(req); got != "" {
|
|
t.Fatalf("empty headers: %q", got)
|
|
}
|
|
req.Extra.Header.Set("Authorization", "Bearer jwt-one")
|
|
if got := BearerFromRequest(req); got != "jwt-one" {
|
|
t.Fatalf("Authorization: %q", got)
|
|
}
|
|
req.Extra.Header = http.Header{}
|
|
req.Extra.Header.Set("X-Api-Key", "key-two")
|
|
if got := BearerFromRequest(req); got != "key-two" {
|
|
t.Fatalf("X-Api-Key: %q", got)
|
|
}
|
|
req.Extra.Header = http.Header{}
|
|
req.Extra.Header.Set("Authorization", "bearer spaced ")
|
|
if got := BearerFromRequest(req); got != "spaced" {
|
|
t.Fatalf("case/space: %q", got)
|
|
}
|
|
}
|
|
|
|
func TestErrWriteNeedsKeyMentionsJWTAndGrok(t *testing.T) {
|
|
t.Parallel()
|
|
msg := ErrWriteNeedsKey.Error()
|
|
for _, want := range []string{"account and auth are required", "Authorization: Bearer", "JWT", "bearer_token_file", "stdio", "signup", "login"} {
|
|
if !strings.Contains(msg, want) {
|
|
t.Fatalf("ErrWriteNeedsKey missing %q: %s", want, msg)
|
|
}
|
|
}
|
|
}
|