Skip to content

Commit

Permalink
Add error for both consumer filter fields specified
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
  • Loading branch information
Jarema committed Feb 13, 2023
1 parent b390163 commit 6493ac6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/consumer.go
Expand Up @@ -495,6 +495,13 @@ func checkConsumerCfg(
}
}

// Do not allow specifying both FilterSubject and FilterSubjects,
// as that's probably unintentional wihout any difference from passing
// all filters in FilterSubjects.
if config.FilterSubject != _EMPTY_ && len(config.FilterSubjects) > 0 {
return NewJSConsumerDuplicateFilterSubjectsError()
}

if config.FilterSubject != _EMPTY_ && !IsValidSubject(config.FilterSubject) {
return NewJSStreamInvalidConfigError(ErrBadSubject)
}
Expand Down
25 changes: 25 additions & 0 deletions server/jetstream_test.go
Expand Up @@ -19228,6 +19228,31 @@ func TestJetStreamConsumerOverlappingSubjects(t *testing.T) {
}
}

func TestJetStreamBothFiltersSet(t *testing.T) {
s := RunBasicJetStreamServer(t)
if config := s.JetStreamConfig(); config != nil {
defer removeDir(t, config.StoreDir)
}
defer s.Shutdown()

nc, _ := jsClientConnect(t, s)
defer nc.Close()
acc := s.GlobalAccount()

_, err := acc.addStream(&StreamConfig{
Subjects: []string{"events.>"},
Name: "deliver",
})
require_NoError(t, err)

resp := createConsumer(t, nc, "deliver", ConsumerConfig{
FilterSubjects: []string{"events.one", "events.two"},
FilterSubject: "events.three",
Durable: "name",
})
require_True(t, resp.Error.ErrCode == 10136)
}

func TestJetStreamMultipleSubjectsPushBasic(t *testing.T) {
s := RunBasicJetStreamServer(t)
if config := s.JetStreamConfig(); config != nil {
Expand Down

0 comments on commit 6493ac6

Please sign in to comment.