Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block imports with wildcards #58

Merged
merged 1 commit into from
Oct 16, 2019
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
2 changes: 1 addition & 1 deletion header.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

const (
// Version is semantic version.
Version = "0.3.0"
Version = "0.3.1"

// TokenTypeJwt is the JWT token type supported JWT tokens
// encoded and decoded by this library
Expand Down
9 changes: 5 additions & 4 deletions imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ func (i *Import) Validate(actPubKey string, vr *ValidationResults) {

i.Subject.Validate(vr)

if i.IsService() {
if i.Subject.HasWildCards() {
vr.AddWarning("services cannot have wildcard subject: %q", i.Subject)
}
if i.IsService() && i.Subject.HasWildCards() {
vr.AddError("services cannot have wildcard subject: %q", i.Subject)
}
if i.IsStream() && i.To.HasWildCards() {
vr.AddError("streams cannot have wildcard to subject: %q", i.Subject)
}

var act *ActivationClaims
Expand Down
23 changes: 19 additions & 4 deletions imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,23 @@ func TestServiceImportWithWildcard(t *testing.T) {
t.Errorf("imports without token or url should warn the caller, as should wildcard service")
}

if vr.IsBlocking(true) {
t.Errorf("imports without token or url should not be blocking")
if !vr.IsBlocking(true) {
t.Errorf("expected service import with a wildcard subject to be a blocking error")
}
}

func TestStreamImportWithWildcardPrefix(t *testing.T) {
i := &Import{Subject: "foo", To: "bar.>", Type: Stream}

vr := CreateValidationResults()
i.Validate("", vr)

if len(vr.Issues) != 3 {
t.Errorf("should have registered 3 issues with this import, got %d", len(vr.Issues))
}

if !vr.IsBlocking(true) {
t.Fatalf("expected stream import prefix with a wildcard to produce a blocking error")
}
}

Expand All @@ -235,8 +250,8 @@ func TestImportsValidation(t *testing.T) {
t.Errorf("imports without token or url should warn the caller x2, wildcard service as well")
}

if vr.IsBlocking(true) {
t.Errorf("imports without token or url should not be blocking")
if !vr.IsBlocking(true) {
t.Errorf("expected service import with a wildcard subject to be a blocking error")
}
}

Expand Down