From 14e39fa22fcaa6ed426f32cd1708c435fc8aee25 Mon Sep 17 00:00:00 2001 From: DrmagicE <379342542@qq.com> Date: Sat, 18 Dec 2021 14:13:47 +0800 Subject: [PATCH] fix: fix validation issue in admin plugin --- pkg/packets/packets.go | 6 ------ plugin/admin/publish.go | 2 +- plugin/admin/publish_test.go | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/packets/packets.go b/pkg/packets/packets.go index 3b04732e..113b3cce 100644 --- a/pkg/packets/packets.go +++ b/pkg/packets/packets.go @@ -345,10 +345,6 @@ func readUint32(r *bytes.Buffer) (uint32, error) { return binary.BigEndian.Uint32(r.Next(4)), nil } -func readBinary(r *bytes.Buffer) (b []byte, err error) { - return readUTF8String(false, r) -} - func readUTF8String(mustUTF8 bool, r *bytes.Buffer) (b []byte, err error) { if r.Len() < 2 { return nil, codes.ErrMalformed @@ -553,8 +549,6 @@ func ValidTopicFilter(mustUTF8 bool, p []byte) bool { return true } -// TopicMatch 返回topic和topic filter是否 -// // TopicMatch returns whether the topic and topic filter is matched. func TopicMatch(topic []byte, topicFilter []byte) bool { var spos int diff --git a/plugin/admin/publish.go b/plugin/admin/publish.go index 44c53480..ffc0b429 100644 --- a/plugin/admin/publish.go +++ b/plugin/admin/publish.go @@ -19,7 +19,7 @@ func (p *publisher) mustEmbedUnimplementedPublishServiceServer() { // Publish publishes a message into broker. func (p *publisher) Publish(ctx context.Context, req *PublishRequest) (resp *empty.Empty, err error) { - if !packets.ValidV5Topic([]byte(req.TopicName)) { + if !packets.ValidTopicName(false, []byte(req.TopicName)) { return nil, ErrInvalidArgument("topic_name", "") } if req.Qos > uint32(packets.Qos2) { diff --git a/plugin/admin/publish_test.go b/plugin/admin/publish_test.go index a5d6f8de..495da642 100644 --- a/plugin/admin/publish_test.go +++ b/plugin/admin/publish_test.go @@ -72,7 +72,7 @@ func TestPublisher_Publish_InvalidArgument(t *testing.T) { name: "invalid_topic_name", field: "topic_name", req: &PublishRequest{ - TopicName: "$share/a", + TopicName: "/a/b/+", Qos: 2, }, },