chore: checkpoint all working changes

This commit is contained in:
Alex Dunmow 2026-09-05 21:14:15 +08:00
parent f14846d758
commit 5f0cc20bbf
5 changed files with 20 additions and 21 deletions

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"slices"
"testing" "testing"
"github.com/google/uuid" "github.com/google/uuid"
@ -97,10 +98,8 @@ func TestCaptchaVerifiedReadsTrustedHeader(t *testing.T) {
} }
func TestAllTrustedHeadersIncludesCaptcha(t *testing.T) { func TestAllTrustedHeadersIncludesCaptcha(t *testing.T) {
for _, h := range AllTrustedHeaders() { if slices.Contains(AllTrustedHeaders(), HeaderVerifiedCaptcha) {
if h == HeaderVerifiedCaptcha {
return return
} }
}
t.Fatalf("AllTrustedHeaders() missing %s — hosts strip-then-stamp from this list, so omitting it makes the header client-forgeable", HeaderVerifiedCaptcha) t.Fatalf("AllTrustedHeaders() missing %s — hosts strip-then-stamp from this list, so omitting it makes the header client-forgeable", HeaderVerifiedCaptcha)
} }

View File

@ -166,12 +166,12 @@ func validHostname(h string) bool {
if len(h) > 253 { if len(h) > 253 {
return false return false
} }
for _, label := range strings.Split(h, ".") { for label := range strings.SplitSeq(h, ".") {
if label == "" || len(label) > 63 { if label == "" || len(label) > 63 {
return false return false
} }
for _, r := range label { for _, r := range label {
if !(r >= 'a' && r <= 'z') && !(r >= '0' && r <= '9') && r != '-' { if (r < 'a' || r > 'z') && (r < '0' || r > '9') && r != '-' {
return false return false
} }
} }

View File

@ -68,7 +68,7 @@ func checkRoutePath(r ModPublicRoute) string {
if strings.HasSuffix(p, "/") { if strings.HasSuffix(p, "/") {
return "no trailing slash; set prefix = true to claim the subtree" return "no trailing slash; set prefix = true to claim the subtree"
} }
for _, seg := range strings.Split(p[1:], "/") { for seg := range strings.SplitSeq(p[1:], "/") {
switch { switch {
case seg == "": case seg == "":
return "empty path segment" return "empty path segment"

View File

@ -74,8 +74,8 @@ func methodDocumentation(method protoreflect.MethodDescriptor) (description, doc
} }
paragraph = strings.TrimSpace(strings.ReplaceAll(paragraph, "\n", " ")) paragraph = strings.TrimSpace(strings.ReplaceAll(paragraph, "\n", " "))
methodName := string(method.Name()) methodName := string(method.Name())
if strings.HasPrefix(paragraph, methodName+" ") { if after, ok := strings.CutPrefix(paragraph, methodName+" "); ok {
paragraph = strings.TrimSpace(strings.TrimPrefix(paragraph, methodName+" ")) paragraph = strings.TrimSpace(after)
if paragraph != "" { if paragraph != "" {
runes := []rune(paragraph) runes := []rune(paragraph)
runes[0] = unicode.ToUpper(runes[0]) runes[0] = unicode.ToUpper(runes[0])

View File

@ -65,30 +65,30 @@ func registerMCPFixture(t *testing.T) {
return return
} }
file, err := protodesc.NewFile(&descriptorpb.FileDescriptorProto{ file, err := protodesc.NewFile(&descriptorpb.FileDescriptorProto{
Name: proto.String("test/mcpfixture.proto"), Name: new("test/mcpfixture.proto"),
Package: proto.String("mcpfixture.v1"), Package: new("mcpfixture.v1"),
Syntax: proto.String("proto3"), Syntax: new("proto3"),
Dependency: []string{"google/protobuf/timestamp.proto"}, Dependency: []string{"google/protobuf/timestamp.proto"},
MessageType: []*descriptorpb.DescriptorProto{{ MessageType: []*descriptorpb.DescriptorProto{{
Name: proto.String("ListArticlesRequest"), Name: new("ListArticlesRequest"),
Field: []*descriptorpb.FieldDescriptorProto{ Field: []*descriptorpb.FieldDescriptorProto{
{Name: proto.String("search"), Number: proto.Int32(1), Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), Type: descriptorpb.FieldDescriptorProto_TYPE_STRING.Enum()}, {Name: new("search"), Number: proto.Int32(1), Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), Type: descriptorpb.FieldDescriptorProto_TYPE_STRING.Enum()},
{Name: proto.String("page"), Number: proto.Int32(2), Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), Type: descriptorpb.FieldDescriptorProto_TYPE_INT32.Enum()}, {Name: new("page"), Number: proto.Int32(2), Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), Type: descriptorpb.FieldDescriptorProto_TYPE_INT32.Enum()},
{Name: proto.String("published_after"), Number: proto.Int32(3), Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(), TypeName: proto.String(".google.protobuf.Timestamp")}, {Name: new("published_after"), Number: proto.Int32(3), Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(), TypeName: new(".google.protobuf.Timestamp")},
}, },
}, { }, {
Name: proto.String("ListArticlesResponse"), Name: new("ListArticlesResponse"),
}}, }},
Service: []*descriptorpb.ServiceDescriptorProto{{ Service: []*descriptorpb.ServiceDescriptorProto{{
Name: proto.String("WikiService"), Name: new("WikiService"),
Method: []*descriptorpb.MethodDescriptorProto{{ Method: []*descriptorpb.MethodDescriptorProto{{
Name: proto.String("ListArticles"), InputType: proto.String(".mcpfixture.v1.ListArticlesRequest"), OutputType: proto.String(".mcpfixture.v1.ListArticlesResponse"), Name: new("ListArticles"), InputType: new(".mcpfixture.v1.ListArticlesRequest"), OutputType: new(".mcpfixture.v1.ListArticlesResponse"),
}, { }, {
Name: proto.String("StreamArticles"), InputType: proto.String(".mcpfixture.v1.ListArticlesRequest"), OutputType: proto.String(".mcpfixture.v1.ListArticlesResponse"), ServerStreaming: proto.Bool(true), Name: new("StreamArticles"), InputType: new(".mcpfixture.v1.ListArticlesRequest"), OutputType: new(".mcpfixture.v1.ListArticlesResponse"), ServerStreaming: new(true),
}}, }},
}}, }},
SourceCodeInfo: &descriptorpb.SourceCodeInfo{Location: []*descriptorpb.SourceCodeInfo_Location{{ SourceCodeInfo: &descriptorpb.SourceCodeInfo{Location: []*descriptorpb.SourceCodeInfo_Location{{
Path: []int32{6, 0, 2, 0}, Span: []int32{1, 0, 1, 1}, LeadingComments: proto.String("ListArticles lists Wiki articles.\n\nSupports pagination."), Path: []int32{6, 0, 2, 0}, Span: []int32{1, 0, 1, 1}, LeadingComments: new("ListArticles lists Wiki articles.\n\nSupports pagination."),
}}}, }}},
}, protoregistry.GlobalFiles) }, protoregistry.GlobalFiles)
if err != nil { if err != nil {