Skip to content

Commit

Permalink
Merge pull request #107 from nats-io/port_nil_imp_exp_check
Browse files Browse the repository at this point in the history
[FIXED] Import/Export issue on validate
  • Loading branch information
kozlovic committed Oct 20, 2020
2 parents 8527407 + e74ae88 commit cbad961
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func (e *Export) IsStreamResponse() bool {

// Validate appends validation issues to the passed in results list
func (e *Export) Validate(vr *ValidationResults) {
if e == nil {
vr.AddError("null export is not allowed")
return
}
if !e.IsService() && !e.IsStream() {
vr.AddError("invalid export type: %q", e.Type)
}
Expand Down Expand Up @@ -199,6 +203,10 @@ func (e *Exports) Validate(vr *ValidationResults) error {
var streamSubjects []Subject

for _, v := range *e {
if v == nil {
vr.AddError("null export is not allowed")
continue
}
if v.IsService() {
serviceSubjects = append(serviceSubjects, v.Subject)
} else {
Expand Down
8 changes: 8 additions & 0 deletions imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (i *Import) IsStream() bool {

// Validate checks if an import is valid for the wrapping account
func (i *Import) Validate(actPubKey string, vr *ValidationResults) {
if i == nil {
vr.AddError("null import is not allowed")
return
}
if !i.IsService() && !i.IsStream() {
vr.AddError("invalid import type: %q", i.Type)
}
Expand Down Expand Up @@ -123,6 +127,10 @@ type Imports []*Import
func (i *Imports) Validate(acctPubKey string, vr *ValidationResults) {
toSet := make(map[Subject]bool, len(*i))
for _, v := range *i {
if v == nil {
vr.AddError("null import is not allowed")
continue
}
if v.Type == Service {
if _, ok := toSet[v.To]; ok {
vr.AddError("Duplicate To subjects for %q", v.To)
Expand Down

0 comments on commit cbad961

Please sign in to comment.