Skip to content

Commit

Permalink
Fix bug in port validation regular expression
Browse files Browse the repository at this point in the history
[#162082773]

Co-authored-by: Danny Joyce <djoyce@pivotal.io>
  • Loading branch information
kardolus and Danny Joyce committed Nov 20, 2018
1 parent bdf02d6 commit 98abf0d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/nginx/supply/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (s *Supplier) validateNginxConfHasPort() error {
return err
}

if portFound, err := regexp.Match(`{{\s+port\s+}}`, conf); err != nil {
if portFound, err := regexp.Match(`{{\s*port\s*}}`, conf); err != nil {
return err
} else if !portFound {
s.Log.Error("nginx.conf file must be configured to respect the value of `{{port}}`")
Expand Down
24 changes: 19 additions & 5 deletions src/nginx/supply/supply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,32 @@ var _ = Describe("Supply", func() {
})

Describe("nginx.conf validation", func() {
It("parses the port and ignores white spaces", func() {
buildDir, err := ioutil.TempDir("", "")
Expect(err).NotTo(HaveOccurred())
defer os.RemoveAll(buildDir)
var (
buildDir string
err error
)

ioutil.WriteFile(filepath.Join(buildDir, "nginx.conf"), []byte("{{ port }}"), 0666)
BeforeEach(func() {
buildDir, err = ioutil.TempDir("", "")
Expect(err).NotTo(HaveOccurred())

mockStager.EXPECT().BuildDir().Return(buildDir).AnyTimes()

mockCommand.EXPECT().Run(gomock.Any()).AnyTimes()
mockCommand.EXPECT().Execute(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
})

AfterEach(func() {
os.RemoveAll(buildDir)
})

It("parses the port", func() {
ioutil.WriteFile(filepath.Join(buildDir, "nginx.conf"), []byte("{{port}}"), 0666)
Expect(supplier.ValidateNginxConf()).To(Succeed())
})

It("parses the port and ignores white spaces", func() {
ioutil.WriteFile(filepath.Join(buildDir, "nginx.conf"), []byte("{{ port }}"), 0666)
Expect(supplier.ValidateNginxConf()).To(Succeed())
})
})
Expand Down

0 comments on commit 98abf0d

Please sign in to comment.