Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/news/nntpd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ func handleIHave(args []string, s *session, c *textproto.Conn) error {
if !s.backend.AllowPost() {
return ErrNotWanted
}
if len(args) < 1 {
return ErrSyntax
}
article, err := s.backend.GetArticle(nil, args[0])
if article != nil {
return ErrNotWanted
Expand Down
46 changes: 44 additions & 2 deletions internal/news/nntpd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
)

type whitespaceBackend struct {
group *nntp.Group
group *nntp.Group
allowPost bool
}

func (b *whitespaceBackend) ListGroups(max int) ([]*nntp.Group, error) {
Expand Down Expand Up @@ -40,7 +41,7 @@ func (b *whitespaceBackend) Authenticate(user, pass string) (Backend, error) {
return b, nil
}

func (b *whitespaceBackend) AllowPost() bool { return false }
func (b *whitespaceBackend) AllowPost() bool { return b.allowPost }

func (b *whitespaceBackend) Post(article *nntp.Article) error {
return errors.New("posting disabled")
Expand Down Expand Up @@ -85,3 +86,44 @@ func TestProcessCollapsesRepeatedCommandWhitespace(t *testing.T) {
t.Fatal("server did not close after QUIT")
}
}

func TestIHaveWithoutMessageIDReturnsSyntaxError(t *testing.T) {
backend := &whitespaceBackend{
group: &nntp.Group{Name: "pfs.general", Posting: nntp.PostingPermitted},
allowPost: true,
}
server := NewServer(backend)
clientConn, serverConn := net.Pipe()
defer clientConn.Close()

done := make(chan struct{})
go func() {
server.Process(serverConn)
close(done)
}()

client := textproto.NewConn(clientConn)
defer client.Close()

if line, err := client.ReadLine(); err != nil || !strings.HasPrefix(line, "200 ") {
t.Fatalf("greeting = %q, %v", line, err)
}
if err := client.PrintfLine("IHAVE"); err != nil {
t.Fatalf("send IHAVE: %v", err)
}
if line, err := client.ReadLine(); err != nil || !strings.HasPrefix(line, "501 ") {
t.Fatalf("IHAVE without message-id = %q, %v; want 501", line, err)
}
if err := client.PrintfLine("QUIT"); err != nil {
t.Fatalf("send QUIT: %v", err)
}
if line, err := client.ReadLine(); err != nil || !strings.HasPrefix(line, "205 ") {
t.Fatalf("QUIT = %q, %v; want 205", line, err)
}

select {
case <-done:
case <-time.After(time.Second):
t.Fatal("server did not close after QUIT")
}
}
Loading