Skip to content

Commit

Permalink
Only return error when strict is on or when the addr is not loopback
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku committed Jun 17, 2019
1 parent b33fb96 commit c683fb3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 6 additions & 2 deletions drainer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,12 @@ func validateAddr(addr string, strict bool) error {
}

if !util.IsValidateListenHost(host) {
if !(strict && host == "127.0.0.1") {
return errors.Errorf("pump may not be able to access drainer using this addr %s", addr)
err := errors.Errorf("pump may not be able to access drainer using this addr %s", addr)
if strict {
return err
}
if host != "127.0.0.1" && host != "localhost" {
return err
}
}
return nil
Expand Down
17 changes: 15 additions & 2 deletions drainer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ type testDrainerSuite struct{}

func (t *testDrainerSuite) TestConfig(c *C) {
args := []string{
"-metrics-addr", "127.0.0.1:9091",
"-metrics-addr", "192.168.15.10:9091",
"-txn-batch", "1",
"-data-dir", "data.drainer",
"-dest-db-type", "mysql",
"-config", "../cmd/drainer/drainer.toml",
"-addr", "192.168.15.10:8257",
"-advertise-addr", "192.168.15.10:8257",
}

cfg := NewConfig()
err := cfg.Parse(args)
c.Assert(err, IsNil)
c.Assert(cfg.MetricsAddr, Equals, "127.0.0.1:9091")
c.Assert(cfg.MetricsAddr, Equals, "192.168.15.10:9091")
c.Assert(cfg.DataDir, Equals, "data.drainer")
c.Assert(cfg.SyncerCfg.TxnBatch, Equals, 1)
c.Assert(cfg.SyncerCfg.DestDBType, Equals, "mysql")
Expand Down Expand Up @@ -101,3 +103,14 @@ func (t *testDrainerSuite) TestAdjustConfig(c *C) {
c.Assert(cfg.SyncerCfg.WorkerCount, Equals, 1)
c.Assert(cfg.SyncerCfg.DisableDispatch, IsTrue)
}

type validateAddrSuite struct{}

var _ = Suite(&validateAddrSuite{})

func (s *validateAddrSuite) TestStrictOrNot(c *C) {
err := validateAddr("http://127.0.0.1:9090", true)
c.Assert(err, NotNil)
err = validateAddr("http://127.0.0.1:9090", false)
c.Assert(err, IsNil)
}

0 comments on commit c683fb3

Please sign in to comment.