diff --git a/conf/lex.go b/conf/lex.go index 3570057b..f9603a99 100644 --- a/conf/lex.go +++ b/conf/lex.go @@ -1031,7 +1031,7 @@ func lexFloat(lx *lexer) stateFn { // lexIPAddr consumes IP addrs, like 127.0.0.1:4222 func lexIPAddr(lx *lexer) stateFn { r := lx.next() - if unicode.IsDigit(r) || r == '.' || r == ':' { + if unicode.IsDigit(r) || r == '.' || r == ':' || r == '-' { return lexIPAddr } lx.backup() diff --git a/conf/lex_test.go b/conf/lex_test.go index bba9c0c1..28cce804 100644 --- a/conf/lex_test.go +++ b/conf/lex_test.go @@ -955,6 +955,30 @@ func TestUnquotedIPAddr(t *testing.T) { lx = lex("listen: apcera.me:80") expect(t, lx, expectedItems) + expectedItems = []item{ + {itemKey, "listen", 1}, + {itemString, "nats.io:-1", 1}, + {itemEOF, "", 1}, + } + lx = lex("listen: nats.io:-1") + expect(t, lx, expectedItems) + + expectedItems = []item{ + {itemKey, "listen", 1}, + {itemInteger, "-1", 1}, + {itemEOF, "", 1}, + } + lx = lex("listen: -1") + expect(t, lx, expectedItems) + + expectedItems = []item{ + {itemKey, "listen", 1}, + {itemString, ":-1", 1}, + {itemEOF, "", 1}, + } + lx = lex("listen: :-1") + expect(t, lx, expectedItems) + expectedItems = []item{ {itemKey, "listen", 1}, {itemString, ":80", 1}, diff --git a/server/configs/certs/cert.new.pem b/server/configs/certs/cert.new.pem index 123a3822..ba38d087 100644 --- a/server/configs/certs/cert.new.pem +++ b/server/configs/certs/cert.new.pem @@ -1,21 +1,22 @@ -----BEGIN CERTIFICATE----- -MIIDZDCCAkwCCQDDwJyfUJu3NTANBgkqhkiG9w0BAQsFADB0MQswCQYDVQQGEwJV -UzELMAkGA1UECAwCQ0ExFDASBgNVBAcMC0xvcyBBbmdlbGVzMRAwDgYDVQQKDAdT -eW5hZGlhMRIwEAYDVQQDDAlsb2NhbGhvc3QxHDAaBgkqhkiG9w0BCQEWDWRlcmVr -QG5hdHMuaW8wHhcNMTgwNjA4MTcyMjE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L3/OV0Qm7XwVP0u5w8mqJIYWdxS648GVvsP1RtU16oM2jPaOiqVvyxS +DivxiOQE33JCcz2LcX3uIcMu -----END CERTIFICATE----- diff --git a/server/configs/certs/key.new.pem b/server/configs/certs/key.new.pem index 13a0701b..eed47788 100644 --- a/server/configs/certs/key.new.pem +++ b/server/configs/certs/key.new.pem @@ -1,28 +1,28 @@ -----BEGIN PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCxRP1Timb8VpCS -p2uIifpYscSVUH90x0SpHJL/zmcEZ6Fld4iA1qz5M8/nI7r0NvIufiwsIIhSK4aH -rFaRY6mTbmDiDP4TwLxcSSOatgQ0DwmsRNpUxxRQ0iuD+4HxPNJFQ8vZJU9s4oL2 -itBtfY4oKYwCkbhQO7zB6dWHHken4mD9qaFxKPwW/VN7TbB3H+E0KwOf/oyf/hVl -DPVbeIQXYHBZbkp1Sv4jayEAjgPqFvgGYvt5ea55lvg64jbTdK3fx3uhfIjPENGn -zJhS0r8cnom6kwfA1mZJevcRJOX1W/OaM5civKcd4Z3QDypknCwSXV+IkGD7Js29 -tmcdignjAgMBAAECggEAHTqY4otxi63iTKwaSPsnMjSti0komuK4aYHyowcvaUSF -Eivxb/z1rGlkoGH904Kz0AKx2dzLXXEbz4cVBwf9z/dlNiCaTDt9U2Ij4sCcVNEd -8S+xKEVjDih5UFvKAzLaIN2a4QUL4ZI/sdMVptgK9ohTM6E/WMtgxkB+GrddbUra -Elr6aXm9uI2CbxBquEZVQLFBH4tl8+sVKD0aBEh8ihIcT5Ade70ednMDhpgUvBSQ -TPK6vfIKZuFSu+6aBkp/tkDHeKX+0nnE9etIGyJ/tooBeQYBFZ5j6qC9aCwBj6yL -5L2Oe4ztj5iQY9rnfBNpCbiBMKGZ27ycq77ryhNLoQKBgQDdKfbqbHLS0+AT0KLh -06yIKKMk7TEIzO/4Dkl5X066l/kGUkqm+XhfplTfhX+AeUVzDCovX63msgvg+tVU -3atg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0Kf42IIUQFF31tafRND5ASZxqF4GfHliwDSFC4xGWL +BgGnZqzQz6Eh6q5h6uLpj7udCmAd5KyH+4VlKDYnvvSiO2ryJ/BLMHwDeKXt4MmS +q/ANyqCcYPY4nEfnbi8FdbmRi+iYM0OX5Q8PwAxlAoGBAOcKMlLwvwc7L+v3WrOS +iRimKwHleIE6gGVuZuix/50vInsi/7/JM//PEjvAHZsNYyWT9cKAZ1UcKxq+4+dC +ecRGg8E2AonHGJt3RRxHIuctm1JrVB9NBxKAa9LUvYmRKNBB1Pkt64Jw7kN2Y0ij +n4wF0N3xnyZRv8EFVYBld32s -----END PRIVATE KEY----- diff --git a/server/configs/cluster.conf b/server/configs/cluster.conf index a1f0ebcf..30833c1c 100644 --- a/server/configs/cluster.conf +++ b/server/configs/cluster.conf @@ -1,7 +1,7 @@ # Cluster config file port: 4242 -net: localhost +net: 127.0.0.1 authorization { user: derek @@ -26,8 +26,8 @@ cluster { # in their routes definitions from above. routes = [ - nats-route://foo:bar@localhost:4245 - nats-route://foo:bar@localhost:4246 + nats-route://foo:bar@127.0.0.1:4245 + nats-route://foo:bar@127.0.0.1:4246 ] no_advertise: true diff --git a/server/configs/listen-1.conf b/server/configs/listen-1.conf new file mode 100644 index 00000000..cf37df73 --- /dev/null +++ b/server/configs/listen-1.conf @@ -0,0 +1,5 @@ +# Make sure -1 works in listen directives too. +listen: 10.0.1.22:-1 + +http: -1 +https: :-1 diff --git a/server/configs/multiple_users.conf b/server/configs/multiple_users.conf index 42dc107e..53e6c2bc 100644 --- a/server/configs/multiple_users.conf +++ b/server/configs/multiple_users.conf @@ -1,4 +1,4 @@ -listen: localhost:4443 +listen: 127.0.0.1:4443 authorization { users = [ diff --git a/server/configs/reload/authorization_1.conf b/server/configs/reload/authorization_1.conf index 753b3b77..b1f6a1f0 100644 --- a/server/configs/reload/authorization_1.conf +++ b/server/configs/reload/authorization_1.conf @@ -1,4 +1,4 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 authorization { # Our role based permissions. diff --git a/server/configs/reload/authorization_2.conf b/server/configs/reload/authorization_2.conf index 92b61125..1b33ad8a 100644 --- a/server/configs/reload/authorization_2.conf +++ b/server/configs/reload/authorization_2.conf @@ -1,4 +1,4 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 authorization { # Our role based permissions. diff --git a/server/configs/reload/basic.conf b/server/configs/reload/basic.conf index 6f506dff..c7f21e7f 100644 --- a/server/configs/reload/basic.conf +++ b/server/configs/reload/basic.conf @@ -1 +1 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 diff --git a/server/configs/reload/file_rotate.conf b/server/configs/reload/file_rotate.conf index 4fb632c6..ea082729 100644 --- a/server/configs/reload/file_rotate.conf +++ b/server/configs/reload/file_rotate.conf @@ -1,3 +1,3 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 logfile: "log.txt" pid_file: "gnatsd.pid" diff --git a/server/configs/reload/file_rotate1.conf b/server/configs/reload/file_rotate1.conf index 4504ba54..b7c2dc61 100644 --- a/server/configs/reload/file_rotate1.conf +++ b/server/configs/reload/file_rotate1.conf @@ -1,3 +1,3 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 logfile: "log1.txt" pid_file: "gnatsd1.pid" diff --git a/server/configs/reload/max_connections.conf b/server/configs/reload/max_connections.conf index b839ae9b..f916d439 100644 --- a/server/configs/reload/max_connections.conf +++ b/server/configs/reload/max_connections.conf @@ -1,3 +1,3 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 max_connections: 1 diff --git a/server/configs/reload/max_payload.conf b/server/configs/reload/max_payload.conf index df9c26cd..8288e9a7 100644 --- a/server/configs/reload/max_payload.conf +++ b/server/configs/reload/max_payload.conf @@ -1,3 +1,3 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 max_payload: 1 diff --git a/server/configs/reload/multiple_users_1.conf b/server/configs/reload/multiple_users_1.conf index e0025339..9f51a9cd 100644 --- a/server/configs/reload/multiple_users_1.conf +++ b/server/configs/reload/multiple_users_1.conf @@ -1,4 +1,4 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 authorization { users = [ diff --git a/server/configs/reload/multiple_users_2.conf b/server/configs/reload/multiple_users_2.conf index 44663cc7..cf7dae5b 100644 --- a/server/configs/reload/multiple_users_2.conf +++ b/server/configs/reload/multiple_users_2.conf @@ -1,4 +1,4 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 authorization { users = [ diff --git a/server/configs/reload/reload.conf b/server/configs/reload/reload.conf index 7785093e..386b34e5 100644 --- a/server/configs/reload/reload.conf +++ b/server/configs/reload/reload.conf @@ -31,6 +31,6 @@ authorization { } cluster { - listen: localhost:-1 + listen: 127.0.0.1:-1 no_advertise: true # enable on reload } diff --git a/server/configs/reload/single_user_authentication_1.conf b/server/configs/reload/single_user_authentication_1.conf index 8d576d8e..db57f1d4 100644 --- a/server/configs/reload/single_user_authentication_1.conf +++ b/server/configs/reload/single_user_authentication_1.conf @@ -1,4 +1,4 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 authorization { user: tyler diff --git a/server/configs/reload/single_user_authentication_2.conf b/server/configs/reload/single_user_authentication_2.conf index 7b6940cd..c52da733 100644 --- a/server/configs/reload/single_user_authentication_2.conf +++ b/server/configs/reload/single_user_authentication_2.conf @@ -1,4 +1,4 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 authorization { user: derek diff --git a/server/configs/reload/srv_a_1.conf b/server/configs/reload/srv_a_1.conf index 4bcdf04e..f915c8b9 100644 --- a/server/configs/reload/srv_a_1.conf +++ b/server/configs/reload/srv_a_1.conf @@ -1,6 +1,6 @@ # Cluster Server A -listen: localhost:-1 +listen: 127.0.0.1:-1 cluster { listen: 127.0.0.1:7244 diff --git a/server/configs/reload/srv_a_2.conf b/server/configs/reload/srv_a_2.conf index a8d19e92..373ae0d8 100644 --- a/server/configs/reload/srv_a_2.conf +++ b/server/configs/reload/srv_a_2.conf @@ -1,6 +1,6 @@ # Cluster Server A -listen: localhost:-1 +listen: 127.0.0.1:-1 cluster { listen: 127.0.0.1:7244 diff --git a/server/configs/reload/srv_a_3.conf b/server/configs/reload/srv_a_3.conf index 5d51aab3..391062c9 100644 --- a/server/configs/reload/srv_a_3.conf +++ b/server/configs/reload/srv_a_3.conf @@ -1,6 +1,6 @@ # Cluster Server A -listen: localhost:-1 +listen: 127.0.0.1:-1 cluster { listen: 127.0.0.1:7244 diff --git a/server/configs/reload/srv_a_4.conf b/server/configs/reload/srv_a_4.conf index 4b63643a..77258f3d 100644 --- a/server/configs/reload/srv_a_4.conf +++ b/server/configs/reload/srv_a_4.conf @@ -1,6 +1,6 @@ # Cluster Server A -listen: localhost:-1 +listen: 127.0.0.1:-1 cluster { listen: 127.0.0.1:7244 diff --git a/server/configs/reload/srv_b_1.conf b/server/configs/reload/srv_b_1.conf index 3c104a28..426e2dab 100644 --- a/server/configs/reload/srv_b_1.conf +++ b/server/configs/reload/srv_b_1.conf @@ -1,6 +1,6 @@ # Cluster Server B -listen: localhost:-1 +listen: 127.0.0.1:-1 cluster { listen: 127.0.0.1:7246 diff --git a/server/configs/reload/srv_b_2.conf b/server/configs/reload/srv_b_2.conf index b99f7314..f16d5baf 100644 --- a/server/configs/reload/srv_b_2.conf +++ b/server/configs/reload/srv_b_2.conf @@ -1,6 +1,6 @@ # Cluster Server B -listen: localhost:-1 +listen: 127.0.0.1:-1 cluster { listen: 127.0.0.1:7246 diff --git a/server/configs/reload/srv_c_1.conf b/server/configs/reload/srv_c_1.conf index 61ab4d07..4bfb7ffb 100644 --- a/server/configs/reload/srv_c_1.conf +++ b/server/configs/reload/srv_c_1.conf @@ -1,6 +1,6 @@ # Cluster Server C -listen: localhost:-1 +listen: 127.0.0.1:-1 cluster { listen: 127.0.0.1:7247 diff --git a/server/configs/reload/test.conf b/server/configs/reload/test.conf index c47f321e..d818b6bb 100644 --- a/server/configs/reload/test.conf +++ b/server/configs/reload/test.conf @@ -6,6 +6,6 @@ trace: false logtime: false cluster { - listen: localhost:-1 + listen: 127.0.0.1:-1 no_advertise: false } diff --git a/server/configs/reload/tls_test.conf b/server/configs/reload/tls_test.conf index 3adc125c..a6fa7e21 100644 --- a/server/configs/reload/tls_test.conf +++ b/server/configs/reload/tls_test.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:-1 +listen: 127.0.0.1:-1 tls { cert_file: "./configs/certs/server.pem" diff --git a/server/configs/reload/tls_verify_test.conf b/server/configs/reload/tls_verify_test.conf index 167c6d26..0756bdd1 100644 --- a/server/configs/reload/tls_verify_test.conf +++ b/server/configs/reload/tls_verify_test.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:-1 +listen: 127.0.0.1:-1 tls { cert_file: "./configs/certs/cert.new.pem" diff --git a/server/configs/reload/token_authentication_1.conf b/server/configs/reload/token_authentication_1.conf index a3a46792..e2ffbd85 100644 --- a/server/configs/reload/token_authentication_1.conf +++ b/server/configs/reload/token_authentication_1.conf @@ -1,4 +1,4 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 authorization { token: T0pS3cr3t diff --git a/server/configs/reload/token_authentication_2.conf b/server/configs/reload/token_authentication_2.conf index 7190869b..2b965fca 100644 --- a/server/configs/reload/token_authentication_2.conf +++ b/server/configs/reload/token_authentication_2.conf @@ -1,4 +1,4 @@ -listen: localhost:-1 +listen: 127.0.0.1:-1 authorization { token: passw0rd diff --git a/server/configs/test.conf b/server/configs/test.conf index 491244a1..7d2814b1 100644 --- a/server/configs/test.conf +++ b/server/configs/test.conf @@ -1,6 +1,6 @@ # Simple config file -listen: localhost:4242 +listen: 127.0.0.1:4242 http: 8222 diff --git a/server/configs/tls.conf b/server/configs/tls.conf index 3540803c..0982ec08 100644 --- a/server/configs/tls.conf +++ b/server/configs/tls.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:4443 +listen: 127.0.0.1:4443 tls { cert_file: "./configs/certs/server.pem" diff --git a/server/configs/tls_bad_cipher.conf b/server/configs/tls_bad_cipher.conf index f1e224b3..a312bb81 100644 --- a/server/configs/tls_bad_cipher.conf +++ b/server/configs/tls_bad_cipher.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:4443 +listen: 127.0.0.1:4443 tls { cert_file: "./configs/certs/server.pem" diff --git a/server/configs/tls_bad_curve_prefs.conf b/server/configs/tls_bad_curve_prefs.conf index 89b77e34..80247851 100644 --- a/server/configs/tls_bad_curve_prefs.conf +++ b/server/configs/tls_bad_curve_prefs.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:4443 +listen: 127.0.0.1:4443 tls { cert_file: "./configs/certs/server.pem" diff --git a/server/configs/tls_ciphers.conf b/server/configs/tls_ciphers.conf index df907080..18868f30 100644 --- a/server/configs/tls_ciphers.conf +++ b/server/configs/tls_ciphers.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:4443 +listen: 127.0.0.1:4443 tls { cert_file: "./configs/certs/server.pem" diff --git a/server/configs/tls_curve_prefs.conf b/server/configs/tls_curve_prefs.conf index 481f1800..a1c7428a 100644 --- a/server/configs/tls_curve_prefs.conf +++ b/server/configs/tls_curve_prefs.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:4443 +listen: 127.0.0.1:4443 tls { cert_file: "./configs/certs/server.pem" diff --git a/server/configs/tls_empty_cipher.conf b/server/configs/tls_empty_cipher.conf index b58f6ba1..f8296030 100644 --- a/server/configs/tls_empty_cipher.conf +++ b/server/configs/tls_empty_cipher.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:4443 +listen: 127.0.0.1:4443 tls { cert_file: "./configs/certs/server.pem" diff --git a/server/configs/tls_empty_curve_prefs.conf b/server/configs/tls_empty_curve_prefs.conf index e790a805..eccc5548 100644 --- a/server/configs/tls_empty_curve_prefs.conf +++ b/server/configs/tls_empty_curve_prefs.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:4443 +listen: 127.0.0.1:4443 tls { cert_file: "./configs/certs/server.pem" diff --git a/server/monitor_test.go b/server/monitor_test.go index 47e7ef34..6139912d 100644 --- a/server/monitor_test.go +++ b/server/monitor_test.go @@ -37,7 +37,7 @@ const CLUSTER_PORT = -1 func DefaultMonitorOptions() *Options { return &Options{ - Host: "localhost", + Host: "127.0.0.1", Port: CLIENT_PORT, HTTPHost: "127.0.0.1", HTTPPort: MONITOR_PORT, @@ -101,7 +101,7 @@ func TestNoMonitorPort(t *testing.T) { defer s.Shutdown() // this test might be meaningless now that we're testing with random ports? - url := fmt.Sprintf("http://localhost:%d/", 11245) + url := fmt.Sprintf("http://127.0.0.1:%d/", 11245) if resp, err := http.Get(url + "varz"); err == nil { t.Fatalf("Expected error: Got %+v\n", resp) } @@ -160,7 +160,7 @@ func TestHandleVarz(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { v := pollVarz(t, s, mode, url+"varz", nil) @@ -226,7 +226,7 @@ func TestConnz(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) testConnz := func(mode int) { c := pollConz(t, s, mode, url+"connz", nil) @@ -331,7 +331,7 @@ func TestConnzBadParams(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/connz?", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/connz?", s.MonitorAddr().Port) readBodyEx(t, url+"auth=xxx", http.StatusBadRequest, textPlain) readBodyEx(t, url+"subs=xxx", http.StatusBadRequest, textPlain) readBodyEx(t, url+"offset=xxx", http.StatusBadRequest, textPlain) @@ -349,7 +349,7 @@ func TestConnzWithSubs(t *testing.T) { nc.Subscribe("hello.foo", func(m *nats.Msg) {}) ensureServerActivityRecorded(t, nc) - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz?subs=1", &ConnzOptions{Subscriptions: true}) // Test inside details of each connection @@ -379,7 +379,7 @@ func TestConnzWithCID(t *testing.T) { } } - url := fmt.Sprintf("http://localhost:%d/connz?cid=%d", s.MonitorAddr().Port, cid) + url := fmt.Sprintf("http://127.0.0.1:%d/connz?cid=%d", s.MonitorAddr().Port, cid) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url, &ConnzOptions{CID: uint64(cid)}) // Test inside details of each connection @@ -397,7 +397,7 @@ func TestConnzWithCID(t *testing.T) { t.Fatalf("Expected to receive connection with %d subs, but received %d\n", 2, ci.NumSubs) } // Now test a miss - badUrl := fmt.Sprintf("http://localhost:%d/connz?cid=%d", s.MonitorAddr().Port, 100) + badUrl := fmt.Sprintf("http://127.0.0.1:%d/connz?cid=%d", s.MonitorAddr().Port, 100) c = pollConz(t, s, mode, badUrl, &ConnzOptions{CID: uint64(100)}) if len(c.Conns) != 0 { t.Fatalf("Expected no connections, got %d\n", len(c.Conns)) @@ -433,7 +433,7 @@ func TestConnzRTT(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) testRTT := func(mode int) { // Test with connections. @@ -487,7 +487,7 @@ func TestConnzLastActivity(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) url += "connz?subs=1" opts := &ConnzOptions{Subscriptions: true} @@ -571,7 +571,7 @@ func TestConnzWithOffsetAndLimit(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz?offset=1&limit=1", &ConnzOptions{Offset: 1, Limit: 1}) @@ -651,7 +651,7 @@ func TestConnzDefaultSorted(t *testing.T) { defer clients[i].Close() } - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz", nil) if c.Conns[0].Cid > c.Conns[1].Cid || @@ -672,7 +672,7 @@ func TestConnzSortedByCid(t *testing.T) { defer clients[i].Close() } - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz?sort=cid", &ConnzOptions{Sort: ByCid}) if c.Conns[0].Cid > c.Conns[1].Cid || @@ -701,7 +701,7 @@ func TestConnzSortedByBytesAndMsgs(t *testing.T) { defer clients[i].Close() } - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz?sort=bytes_to", &ConnzOptions{Sort: ByOutBytes}) if c.Conns[0].OutBytes < c.Conns[1].OutBytes || @@ -750,7 +750,7 @@ func TestConnzSortedByPending(t *testing.T) { } defer firstClient.Close() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz?sort=pending", &ConnzOptions{Sort: ByPending}) if c.Conns[0].Pending < c.Conns[1].Pending || @@ -776,7 +776,7 @@ func TestConnzSortedBySubs(t *testing.T) { defer clients[i].Close() } - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz?sort=subs", &ConnzOptions{Sort: BySubs}) if c.Conns[0].NumSubs < c.Conns[1].NumSubs || @@ -805,7 +805,7 @@ func TestConnzSortedByLast(t *testing.T) { clients[i].Flush() } - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz?sort=last", &ConnzOptions{Sort: ByLast}) if c.Conns[0].LastActivity.UnixNano() < c.Conns[1].LastActivity.UnixNano() || @@ -828,7 +828,7 @@ func TestConnzSortedByUptime(t *testing.T) { time.Sleep(250 * time.Millisecond) } - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz?sort=uptime", &ConnzOptions{Sort: ByUptime}) // uptime is generated by Conn.Start @@ -845,7 +845,7 @@ func TestConnzSortedByIdle(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) testIdle := func(mode int) { firstClient := createClientConnSubscribeAndPublish(t, s) @@ -905,7 +905,7 @@ func TestConnzSortBadRequest(t *testing.T) { } defer firstClient.Close() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) readBodyEx(t, url+"connz?sort=foo", http.StatusBadRequest, textPlain) if _, err := s.Connz(&ConnzOptions{Sort: "foo"}); err == nil { @@ -929,17 +929,17 @@ func pollRoutez(t *testing.T, s *Server, mode int, url string, opts *RoutezOptio func TestConnzWithRoutes(t *testing.T) { opts := DefaultMonitorOptions() - opts.Cluster.Host = "localhost" + opts.Cluster.Host = "127.0.0.1" opts.Cluster.Port = CLUSTER_PORT s := RunServer(opts) defer s.Shutdown() opts = &Options{ - Host: "localhost", + Host: "127.0.0.1", Port: -1, Cluster: ClusterOpts{ - Host: "localhost", + Host: "127.0.0.1", Port: -1, }, NoLog: true, @@ -953,7 +953,7 @@ func TestConnzWithRoutes(t *testing.T) { checkClusterFormed(t, s, sc) - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { c := pollConz(t, s, mode, url+"connz", nil) // Test contents.. @@ -1014,7 +1014,7 @@ func TestRoutezWithBadParams(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/routez?", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/routez?", s.MonitorAddr().Port) readBodyEx(t, url+"subs=xxx", http.StatusBadRequest, textPlain) } @@ -1038,7 +1038,7 @@ func TestSubsz(t *testing.T) { nc := createClientConnSubscribeAndPublish(t, s) defer nc.Close() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { sl := pollSubsz(t, s, mode, url+"subscriptionsz", nil) @@ -1065,7 +1065,7 @@ func TestHandleRoot(t *testing.T) { nc := createClientConnSubscribeAndPublish(t, s) defer nc.Close() - resp, err := http.Get(fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port)) + resp, err := http.Get(fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port)) if err != nil { t.Fatalf("Expected no error: Got %v\n", err) } @@ -1098,7 +1098,7 @@ func TestConnzWithNamedClient(t *testing.T) { nc := createClientConnWithName(t, clientName, s) defer nc.Close() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { // Confirm server is exposing client name in monitoring endpoint. c := pollConz(t, s, mode, url+"connz", nil) @@ -1130,7 +1130,7 @@ func TestConnzWithStateForClosedConns(t *testing.T) { defer nc.Close() } - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { // Look at all open @@ -1211,7 +1211,7 @@ func TestConnzClosedConnsRace(t *testing.T) { nc.Close() } - urlWithoutSubs := fmt.Sprintf("http://localhost:%d/connz?state=closed", s.MonitorAddr().Port) + urlWithoutSubs := fmt.Sprintf("http://127.0.0.1:%d/connz?state=closed", s.MonitorAddr().Port) urlWithSubs := urlWithoutSubs + "&subs=true" checkClosedConns(t, s, 100, 2*time.Second) @@ -1237,7 +1237,7 @@ func TestConnzClosedConnsRace(t *testing.T) { // Create a connection to test ConnInfo func createClientConnSubscribeAndPublish(t *testing.T, s *Server) *nats.Conn { - natsURL := fmt.Sprintf("nats://localhost:%d", s.Addr().(*net.TCPAddr).Port) + natsURL := fmt.Sprintf("nats://127.0.0.1:%d", s.Addr().(*net.TCPAddr).Port) client := nats.DefaultOptions client.Servers = []string{natsURL} nc, err := client.Connect() @@ -1261,7 +1261,7 @@ func createClientConnSubscribeAndPublish(t *testing.T, s *Server) *nats.Conn { } func createClientConnWithName(t *testing.T, name string, s *Server) *nats.Conn { - natsURI := fmt.Sprintf("nats://localhost:%d", s.Addr().(*net.TCPAddr).Port) + natsURI := fmt.Sprintf("nats://127.0.0.1:%d", s.Addr().(*net.TCPAddr).Port) client := nats.DefaultOptions client.Servers = []string{natsURI} @@ -1277,7 +1277,7 @@ func TestStacksz(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + url := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) body := readBody(t, url+"stacksz") // Check content str := string(body) @@ -1440,7 +1440,7 @@ func TestServerIDs(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - murl := fmt.Sprintf("http://localhost:%d/", s.MonitorAddr().Port) + murl := fmt.Sprintf("http://127.0.0.1:%d/", s.MonitorAddr().Port) for mode := 0; mode < 2; mode++ { v := pollVarz(t, s, mode, murl+"varz", nil) @@ -1486,7 +1486,7 @@ func TestClusterEmptyWhenNotDefined(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - body := readBody(t, fmt.Sprintf("http://localhost:%d/varz", s.MonitorAddr().Port)) + body := readBody(t, fmt.Sprintf("http://127.0.0.1:%d/varz", s.MonitorAddr().Port)) var v map[string]interface{} if err := json.Unmarshal(body, &v); err != nil { stackFatalf(t, "Got an error unmarshalling the body: %v\n", err) diff --git a/server/opts.go b/server/opts.go index 59cbf019..b9619ca1 100644 --- a/server/opts.go +++ b/server/opts.go @@ -1021,8 +1021,8 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp, fs.StringVar(&opts.LogFile, "log", "", "File to store logging output.") fs.BoolVar(&opts.Syslog, "s", false, "Enable syslog as log method.") fs.BoolVar(&opts.Syslog, "syslog", false, "Enable syslog as log method..") - fs.StringVar(&opts.RemoteSyslog, "r", "", "Syslog server addr (udp://localhost:514).") - fs.StringVar(&opts.RemoteSyslog, "remote_syslog", "", "Syslog server addr (udp://localhost:514).") + fs.StringVar(&opts.RemoteSyslog, "r", "", "Syslog server addr (udp://127.0.0.1:514).") + fs.StringVar(&opts.RemoteSyslog, "remote_syslog", "", "Syslog server addr (udp://127.0.0.1:514).") fs.BoolVar(&showVersion, "version", false, "Print version information.") fs.BoolVar(&showVersion, "v", false, "Print version information.") fs.IntVar(&opts.ProfPort, "profile", 0, "Profiling HTTP port") diff --git a/server/opts_test.go b/server/opts_test.go index 55d37738..8fd3eb12 100644 --- a/server/opts_test.go +++ b/server/opts_test.go @@ -66,7 +66,7 @@ func TestOptions_RandomPort(t *testing.T) { func TestConfigFile(t *testing.T) { golden := &Options{ ConfigFile: "./configs/test.conf", - Host: "localhost", + Host: "127.0.0.1", Port: 4242, Username: "derek", Password: "porkchop", @@ -102,7 +102,7 @@ func TestConfigFile(t *testing.T) { func TestTLSConfigFile(t *testing.T) { golden := &Options{ ConfigFile: "./configs/tls.conf", - Host: "localhost", + Host: "127.0.0.1", Port: 4443, Username: "derek", Password: "foo", @@ -139,7 +139,7 @@ func TestTLSConfigFile(t *testing.T) { t.Fatal("Expected 1 certificate") } cert := tlsConfig.Certificates[0].Leaf - if err := cert.VerifyHostname("localhost"); err != nil { + if err := cert.VerifyHostname("127.0.0.1"); err != nil { t.Fatalf("Could not verify hostname in certificate: %v\n", err) } @@ -222,7 +222,7 @@ func TestTLSConfigFile(t *testing.T) { func TestMergeOverrides(t *testing.T) { golden := &Options{ ConfigFile: "./configs/test.conf", - Host: "localhost", + Host: "127.0.0.1", Port: 2222, Username: "derek", Password: "porkchop", @@ -274,7 +274,7 @@ func TestMergeOverrides(t *testing.T) { func TestRemoveSelfReference(t *testing.T) { url1, _ := url.Parse("nats-route://user:password@10.4.5.6:4223") - url2, _ := url.Parse("nats-route://user:password@localhost:4223") + url2, _ := url.Parse("nats-route://user:password@127.0.0.1:4223") url3, _ := url.Parse("nats-route://user:password@127.0.0.1:4223") routes := []*url.URL{url1, url2, url3} @@ -423,6 +423,22 @@ func TestRouteFlagOverrideWithMultiple(t *testing.T) { } } +func TestDynamicPortOnListen(t *testing.T) { + opts, err := ProcessConfigFile("./configs/listen-1.conf") + if err != nil { + t.Fatalf("Received an error reading config file: %v\n", err) + } + if opts.Port != -1 { + t.Fatalf("Received incorrect port %v, expected -1\n", opts.Port) + } + if opts.HTTPPort != -1 { + t.Fatalf("Received incorrect monitoring port %v, expected -1\n", opts.HTTPPort) + } + if opts.HTTPSPort != -1 { + t.Fatalf("Received incorrect secure monitoring port %v, expected -1\n", opts.HTTPSPort) + } +} + func TestListenConfig(t *testing.T) { opts, err := ProcessConfigFile("./configs/listen.conf") if err != nil { @@ -716,7 +732,7 @@ func TestParseWriteDeadline(t *testing.T) { func TestOptionsClone(t *testing.T) { opts := &Options{ ConfigFile: "./configs/test.conf", - Host: "localhost", + Host: "127.0.0.1", Port: 2222, Username: "derek", Password: "porkchop", @@ -947,15 +963,15 @@ func TestConfigureOptions(t *testing.T) { } // This should fail since -cluster is missing - expectedURL, _ := url.Parse("nats://localhost:6223") + expectedURL, _ := url.Parse("nats://127.0.0.1:6223") expectToFail([]string{"-routes", expectedURL.String()}, "solicited routes") // Ensure that we can set cluster and routes from command line - opts = mustNotFail([]string{"-cluster", "nats://localhost:6222", "-routes", expectedURL.String()}) - if opts.Cluster.ListenStr != "nats://localhost:6222" { + opts = mustNotFail([]string{"-cluster", "nats://127.0.0.1:6222", "-routes", expectedURL.String()}) + if opts.Cluster.ListenStr != "nats://127.0.0.1:6222" { t.Fatalf("Unexpected Cluster.ListenStr=%q", opts.Cluster.ListenStr) } - if opts.RoutesStr != "nats://localhost:6223" || len(opts.Routes) != 1 || opts.Routes[0].String() != expectedURL.String() { + if opts.RoutesStr != "nats://127.0.0.1:6223" || len(opts.Routes) != 1 || opts.Routes[0].String() != expectedURL.String() { t.Fatalf("Unexpected RoutesStr: %q and Routes: %v", opts.RoutesStr, opts.Routes) } @@ -968,7 +984,7 @@ func TestConfigureOptions(t *testing.T) { // Use a config with cluster configuration and override cluster listen string expectedURL, _ = url.Parse("nats-route://ruser:top_secret@127.0.0.1:7246") - opts = mustNotFail([]string{"-c", "./configs/srv_a.conf", "-cluster", "nats://ivan:pwd@localhost:6222"}) + opts = mustNotFail([]string{"-c", "./configs/srv_a.conf", "-cluster", "nats://ivan:pwd@127.0.0.1:6222"}) if opts.Cluster.Username != "ivan" || opts.Cluster.Password != "pwd" || opts.Cluster.Port != 6222 || len(opts.Routes) != 1 || opts.Routes[0].String() != expectedURL.String() { t.Fatalf("Unexpected Cluster and/or Routes: %#v - %v", opts.Cluster, opts.Routes) @@ -984,10 +1000,10 @@ func TestConfigureOptions(t *testing.T) { // (adding -routes to have more than 1 set flag to check // that Visit() stops when an error is found). expectToFail([]string{"-cluster", ":", "-routes", ""}, "protocol") - expectToFail([]string{"-cluster", "nats://localhost", "-routes", ""}, "port") - expectToFail([]string{"-cluster", "nats://localhost:xxx", "-routes", ""}, "integer") - expectToFail([]string{"-cluster", "nats://ivan:localhost:6222", "-routes", ""}, "colons") - expectToFail([]string{"-cluster", "nats://ivan@localhost:6222", "-routes", ""}, "password") + expectToFail([]string{"-cluster", "nats://127.0.0.1", "-routes", ""}, "port") + expectToFail([]string{"-cluster", "nats://127.0.0.1:xxx", "-routes", ""}, "integer") + expectToFail([]string{"-cluster", "nats://ivan:127.0.0.1:6222", "-routes", ""}, "colons") + expectToFail([]string{"-cluster", "nats://ivan@127.0.0.1:6222", "-routes", ""}, "password") // Override config file's TLS configuration from command line, and completely disable TLS opts = mustNotFail([]string{"-c", "./configs/tls.conf", "-tls=false"}) diff --git a/server/ping_test.go b/server/ping_test.go index f8abf5ef..aa56f6b4 100644 --- a/server/ping_test.go +++ b/server/ping_test.go @@ -24,7 +24,7 @@ import ( const PING_CLIENT_PORT = 11228 var DefaultPingOptions = Options{ - Host: "localhost", + Host: "127.0.0.1", Port: PING_CLIENT_PORT, NoLog: true, NoSigs: true, @@ -35,7 +35,7 @@ func TestPing(t *testing.T) { s := RunServer(&DefaultPingOptions) defer s.Shutdown() - nc, err := nats.Connect(fmt.Sprintf("nats://localhost:%d", PING_CLIENT_PORT)) + nc, err := nats.Connect(fmt.Sprintf("nats://127.0.0.1:%d", PING_CLIENT_PORT)) if err != nil { t.Fatalf("Error creating client: %v\n", err) } diff --git a/server/reload_test.go b/server/reload_test.go index 1990c58f..b062bd24 100644 --- a/server/reload_test.go +++ b/server/reload_test.go @@ -66,7 +66,7 @@ func TestConfigReloadUnsupported(t *testing.T) { MaxPingsOut: 2, WriteDeadline: 2 * time.Second, Cluster: ClusterOpts{ - Host: "localhost", + Host: "127.0.0.1", Port: -1, }, NoSigs: true, @@ -105,10 +105,10 @@ func TestConfigReloadUnsupportedHotSwapping(t *testing.T) { newConfig := "tmp_b.conf" defer os.Remove(orgConfig) defer os.Remove(newConfig) - if err := ioutil.WriteFile(orgConfig, []byte("listen: localhost:-1"), 0666); err != nil { + if err := ioutil.WriteFile(orgConfig, []byte("listen: 127.0.0.1:-1"), 0666); err != nil { t.Fatalf("Error creating config file: %v", err) } - if err := ioutil.WriteFile(newConfig, []byte("listen: localhost:9999"), 0666); err != nil { + if err := ioutil.WriteFile(newConfig, []byte("listen: 127.0.0.1:9999"), 0666); err != nil { t.Fatalf("Error creating config file: %v", err) } @@ -156,7 +156,7 @@ func TestConfigReloadInvalidConfig(t *testing.T) { MaxPingsOut: 2, WriteDeadline: 2 * time.Second, Cluster: ClusterOpts{ - Host: "localhost", + Host: "127.0.0.1", Port: -1, }, NoSigs: true, @@ -192,7 +192,7 @@ func TestConfigReload(t *testing.T) { var content []byte if runtime.GOOS != "windows" { content = []byte(` - remote_syslog: "udp://localhost:514" # change on reload + remote_syslog: "udp://127.0.0.1:514" # change on reload log_file: "/tmp/gnatsd-2.log" # change on reload `) } @@ -223,7 +223,7 @@ func TestConfigReload(t *testing.T) { MaxPingsOut: 2, WriteDeadline: 2 * time.Second, Cluster: ClusterOpts{ - Host: "localhost", + Host: "127.0.0.1", Port: server.ClusterAddr().Port, }, NoSigs: true, @@ -257,8 +257,8 @@ func TestConfigReload(t *testing.T) { t.Fatal("Expected Syslog to be true") } if runtime.GOOS != "windows" { - if updated.RemoteSyslog != "udp://localhost:514" { - t.Fatalf("RemoteSyslog is incorrect.\nexpected: udp://localhost:514\ngot: %s", updated.RemoteSyslog) + if updated.RemoteSyslog != "udp://127.0.0.1:514" { + t.Fatalf("RemoteSyslog is incorrect.\nexpected: udp://127.0.0.1:514\ngot: %s", updated.RemoteSyslog) } if updated.LogFile != "/tmp/gnatsd-2.log" { t.Fatalf("LogFile is incorrect.\nexpected: /tmp/gnatsd-2.log\ngot: %s", updated.LogFile) @@ -323,6 +323,7 @@ func TestConfigReloadRotateTLS(t *testing.T) { // Ensure we can connect as a sanity check. addr := fmt.Sprintf("nats://%s:%d", opts.Host, server.Addr().(*net.TCPAddr).Port) + nc, err := nats.Connect(addr, nats.Secure()) if err != nil { t.Fatalf("Error creating client: %v", err) @@ -1843,6 +1844,7 @@ func TestConfigReloadRotateFiles(t *testing.T) { } func runServerWithSymlinkConfig(t *testing.T, symlinkName, configName string) (*Server, *Options, string) { + t.Helper() opts, config := newOptionsWithSymlinkConfig(t, symlinkName, configName) opts.NoLog = true opts.NoSigs = true @@ -1850,11 +1852,13 @@ func runServerWithSymlinkConfig(t *testing.T, symlinkName, configName string) (* } func newServerWithSymlinkConfig(t *testing.T, symlinkName, configName string) (*Server, *Options, string) { + t.Helper() opts, config := newOptionsWithSymlinkConfig(t, symlinkName, configName) return New(opts), opts, config } func newOptionsWithSymlinkConfig(t *testing.T, symlinkName, configName string) (*Options, string) { + t.Helper() dir, err := os.Getwd() if err != nil { t.Fatalf("Error getting working directory: %v", err) @@ -1870,6 +1874,7 @@ func newOptionsWithSymlinkConfig(t *testing.T, symlinkName, configName string) ( } func createSymlink(t *testing.T, symlinkName, fileName string) { + t.Helper() os.Remove(symlinkName) if err := os.Symlink(fileName, symlinkName); err != nil { t.Fatalf("Error creating symlink: %v (ensure you have privileges)", err) diff --git a/server/routes_test.go b/server/routes_test.go index 2b40438a..3fd43477 100644 --- a/server/routes_test.go +++ b/server/routes_test.go @@ -46,7 +46,7 @@ func TestRouteConfig(t *testing.T) { golden := &Options{ ConfigFile: "./configs/cluster.conf", - Host: "localhost", + Host: "127.0.0.1", Port: 4242, Username: "derek", Password: "porkchop", @@ -64,8 +64,8 @@ func TestRouteConfig(t *testing.T) { } // Setup URLs - r1, _ := url.Parse("nats-route://foo:bar@localhost:4245") - r2, _ := url.Parse("nats-route://foo:bar@localhost:4246") + r1, _ := url.Parse("nats-route://foo:bar@127.0.0.1:4245") + r2, _ := url.Parse("nats-route://foo:bar@127.0.0.1:4246") golden.Routes = []*url.URL{r1, r2} @@ -76,7 +76,7 @@ func TestRouteConfig(t *testing.T) { } func TestClusterAdvertise(t *testing.T) { - lst, err := net.Listen("tcp", "localhost:0") + lst, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatalf("Error starting listener: %v", err) } @@ -628,9 +628,9 @@ func TestClientConnectToRoutePort(t *testing.T) { opts := DefaultOptions() // Since client will first connect to the route listen port, set the - // cluster's Host to localhost so it works on Windows too, since on + // cluster's Host to 127.0.0.1 so it works on Windows too, since on // Windows, a client can't use 0.0.0.0 in a connect. - opts.Cluster.Host = "localhost" + opts.Cluster.Host = "127.0.0.1" s := RunServer(opts) defer s.Shutdown() diff --git a/server/server_test.go b/server/server_test.go index bd5c59a4..fe501e30 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -43,7 +43,7 @@ func checkFor(t *testing.T, totalWait, sleepDur time.Duration, f func() error) { func DefaultOptions() *Options { return &Options{ - Host: "localhost", + Host: "127.0.0.1", Port: -1, HTTPPort: -1, Cluster: ClusterOpts{Port: -1}, @@ -353,7 +353,7 @@ func TestNoDeadlockOnStartFailure(t *testing.T) { opts.Host = "x.x.x.x" // bad host opts.Port = 4222 opts.HTTPHost = opts.Host - opts.Cluster.Host = "localhost" + opts.Cluster.Host = "127.0.0.1" opts.Cluster.Port = -1 opts.ProfPort = -1 s := New(opts) diff --git a/server/signal_test.go b/server/signal_test.go index 56cabe1b..3fa27559 100644 --- a/server/signal_test.go +++ b/server/signal_test.go @@ -34,7 +34,7 @@ func TestSignalToReOpenLogFile(t *testing.T) { defer os.Remove(logFile) defer os.Remove(logFile + ".bak") opts := &Options{ - Host: "localhost", + Host: "127.0.0.1", Port: -1, NoSigs: false, LogFile: logFile, diff --git a/test/auth_test.go b/test/auth_test.go index 75216202..ed391b25 100644 --- a/test/auth_test.go +++ b/test/auth_test.go @@ -62,7 +62,7 @@ func runAuthServerWithToken() *server.Server { func TestNoAuthClient(t *testing.T) { s := runAuthServerWithToken() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, "", "", "") @@ -72,7 +72,7 @@ func TestNoAuthClient(t *testing.T) { func TestAuthClientBadToken(t *testing.T) { s := runAuthServerWithToken() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, "ZZZ", "", "") @@ -82,7 +82,7 @@ func TestAuthClientBadToken(t *testing.T) { func TestAuthClientNoConnect(t *testing.T) { s := runAuthServerWithToken() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) // This is timing dependent.. @@ -93,7 +93,7 @@ func TestAuthClientNoConnect(t *testing.T) { func TestAuthClientGoodConnect(t *testing.T) { s := runAuthServerWithToken() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, AUTH_TOKEN, "", "") @@ -103,7 +103,7 @@ func TestAuthClientGoodConnect(t *testing.T) { func TestAuthClientFailOnEverythingElse(t *testing.T) { s := runAuthServerWithToken() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) sendProto(t, c, "PUB foo 2\r\nok\r\n") @@ -128,7 +128,7 @@ func runAuthServerWithUserPass() *server.Server { func TestNoUserOrPasswordClient(t *testing.T) { s := runAuthServerWithUserPass() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, "", "", "") @@ -138,7 +138,7 @@ func TestNoUserOrPasswordClient(t *testing.T) { func TestBadUserClient(t *testing.T) { s := runAuthServerWithUserPass() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, "", "derekzz", AUTH_PASS) @@ -148,7 +148,7 @@ func TestBadUserClient(t *testing.T) { func TestBadPasswordClient(t *testing.T) { s := runAuthServerWithUserPass() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, "", AUTH_USER, "ZZ") @@ -158,7 +158,7 @@ func TestBadPasswordClient(t *testing.T) { func TestPasswordClientGoodConnect(t *testing.T) { s := runAuthServerWithUserPass() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, "", AUTH_USER, AUTH_PASS) @@ -184,7 +184,7 @@ func runAuthServerWithBcryptUserPass() *server.Server { func TestBadBcryptPassword(t *testing.T) { s := runAuthServerWithBcryptUserPass() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, "", AUTH_USER, BCRYPT_AUTH_HASH) @@ -194,7 +194,7 @@ func TestBadBcryptPassword(t *testing.T) { func TestGoodBcryptPassword(t *testing.T) { s := runAuthServerWithBcryptUserPass() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, "", AUTH_USER, BCRYPT_AUTH_PASS) @@ -218,7 +218,7 @@ func runAuthServerWithBcryptToken() *server.Server { func TestBadBcryptToken(t *testing.T) { s := runAuthServerWithBcryptToken() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, BCRYPT_AUTH_TOKEN_HASH, "", "") @@ -228,7 +228,7 @@ func TestBadBcryptToken(t *testing.T) { func TestGoodBcryptToken(t *testing.T) { s := runAuthServerWithBcryptToken() defer s.Shutdown() - c := createClientConn(t, "localhost", AUTH_PORT) + c := createClientConn(t, "127.0.0.1", AUTH_PORT) defer c.Close() expectAuthRequired(t, c) doAuthConnect(t, c, BCRYPT_AUTH_TOKEN, "", "") diff --git a/test/bench_test.go b/test/bench_test.go index 47b0dd01..4f90b411 100644 --- a/test/bench_test.go +++ b/test/bench_test.go @@ -53,7 +53,7 @@ func flushConnection(b *testing.B, c net.Conn) { func benchPub(b *testing.B, subject, payload string) { b.StopTimer() s := runBenchServer() - c := createClientConn(b, "localhost", PERF_PORT) + c := createClientConn(b, "127.0.0.1", PERF_PORT) doDefaultConnect(b, c) bw := bufio.NewWriterSize(c, defaultSendBufSize) sendOp := []byte(fmt.Sprintf("PUB %s %d\r\n%s\r\n", subject, len(payload), payload)) @@ -189,7 +189,7 @@ func Benchmark__AuthPub0b_Payload(b *testing.B) { func Benchmark_____________PubSub(b *testing.B) { b.StopTimer() s := runBenchServer() - c := createClientConn(b, "localhost", PERF_PORT) + c := createClientConn(b, "127.0.0.1", PERF_PORT) doDefaultConnect(b, c) sendProto(b, c, "SUB foo 1\r\n") bw := bufio.NewWriterSize(c, defaultSendBufSize) @@ -221,11 +221,11 @@ func Benchmark_____________PubSub(b *testing.B) { func Benchmark_____PubSubTwoConns(b *testing.B) { b.StopTimer() s := runBenchServer() - c := createClientConn(b, "localhost", PERF_PORT) + c := createClientConn(b, "127.0.0.1", PERF_PORT) doDefaultConnect(b, c) bw := bufio.NewWriterSize(c, defaultSendBufSize) - c2 := createClientConn(b, "localhost", PERF_PORT) + c2 := createClientConn(b, "127.0.0.1", PERF_PORT) doDefaultConnect(b, c2) sendProto(b, c2, "SUB foo 1\r\n") flushConnection(b, c2) @@ -257,11 +257,11 @@ func Benchmark_____PubSubTwoConns(b *testing.B) { func Benchmark_PubSub512kTwoConns(b *testing.B) { b.StopTimer() s := runBenchServer() - c := createClientConn(b, "localhost", PERF_PORT) + c := createClientConn(b, "127.0.0.1", PERF_PORT) doDefaultConnect(b, c) bw := bufio.NewWriterSize(c, defaultSendBufSize) - c2 := createClientConn(b, "localhost", PERF_PORT) + c2 := createClientConn(b, "127.0.0.1", PERF_PORT) doDefaultConnect(b, c2) sendProto(b, c2, "SUB foo 1\r\n") flushConnection(b, c2) @@ -296,7 +296,7 @@ func Benchmark_PubSub512kTwoConns(b *testing.B) { func Benchmark_____PubTwoQueueSub(b *testing.B) { b.StopTimer() s := runBenchServer() - c := createClientConn(b, "localhost", PERF_PORT) + c := createClientConn(b, "127.0.0.1", PERF_PORT) doDefaultConnect(b, c) sendProto(b, c, "SUB foo group1 1\r\n") sendProto(b, c, "SUB foo group1 2\r\n") @@ -329,7 +329,7 @@ func Benchmark_____PubTwoQueueSub(b *testing.B) { func Benchmark____PubFourQueueSub(b *testing.B) { b.StopTimer() s := runBenchServer() - c := createClientConn(b, "localhost", PERF_PORT) + c := createClientConn(b, "127.0.0.1", PERF_PORT) doDefaultConnect(b, c) sendProto(b, c, "SUB foo group1 1\r\n") sendProto(b, c, "SUB foo group1 2\r\n") @@ -364,7 +364,7 @@ func Benchmark____PubFourQueueSub(b *testing.B) { func Benchmark___PubEightQueueSub(b *testing.B) { b.StopTimer() s := runBenchServer() - c := createClientConn(b, "localhost", PERF_PORT) + c := createClientConn(b, "127.0.0.1", PERF_PORT) doDefaultConnect(b, c) sendProto(b, c, "SUB foo group1 1\r\n") sendProto(b, c, "SUB foo group1 2\r\n") diff --git a/test/configs/tls.conf b/test/configs/tls.conf index 6d503b94..b5806386 100644 --- a/test/configs/tls.conf +++ b/test/configs/tls.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:5443 +listen: 127.0.0.1:5443 https: 11522 diff --git a/test/configs/tls_curve_pref.conf b/test/configs/tls_curve_pref.conf index c144b6e1..9e3149d2 100644 --- a/test/configs/tls_curve_pref.conf +++ b/test/configs/tls_curve_pref.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:5443 +listen: 127.0.0.1:5443 https: 11522 diff --git a/test/configs/tlsverify.conf b/test/configs/tlsverify.conf index d92119e0..31f5b9bb 100644 --- a/test/configs/tlsverify.conf +++ b/test/configs/tlsverify.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:5443 +listen: 127.0.0.1:5443 tls { # Server cert diff --git a/test/configs/tlsverify_noca.conf b/test/configs/tlsverify_noca.conf index 36421031..64af5339 100644 --- a/test/configs/tlsverify_noca.conf +++ b/test/configs/tlsverify_noca.conf @@ -1,6 +1,6 @@ # Simple TLS config file -listen: localhost:5443 +listen: 127.0.0.1:5443 tls { # Server cert diff --git a/test/gosrv_test.go b/test/gosrv_test.go index fc432089..c7940cad 100644 --- a/test/gosrv_test.go +++ b/test/gosrv_test.go @@ -40,7 +40,7 @@ func TestGoServerShutdownWithClients(t *testing.T) { s := RunServer(&opts) addr := s.Addr().(*net.TCPAddr) for i := 0; i < 50; i++ { - createClientConn(t, "localhost", addr.Port) + createClientConn(t, "127.0.0.1", addr.Port) } s.Shutdown() // Wait longer for client connections diff --git a/test/monitor_test.go b/test/monitor_test.go index 9bf4bf6f..a0851126 100644 --- a/test/monitor_test.go +++ b/test/monitor_test.go @@ -39,7 +39,7 @@ func runMonitorServer() *server.Server { opts := DefaultTestOptions opts.Port = CLIENT_PORT opts.HTTPPort = MONITOR_PORT - opts.HTTPHost = "localhost" + opts.HTTPHost = "127.0.0.1" return RunServer(&opts) } @@ -50,7 +50,7 @@ func runMonitorServerClusteredPair(t *testing.T) (*server.Server, *server.Server opts := DefaultTestOptions opts.Port = CLIENT_PORT opts.HTTPPort = MONITOR_PORT - opts.HTTPHost = "localhost" + opts.HTTPHost = "127.0.0.1" opts.Cluster = server.ClusterOpts{Host: "127.0.0.1", Port: 10223} opts.Routes = server.RoutesFromStr("nats-route://127.0.0.1:10222") @@ -59,7 +59,7 @@ func runMonitorServerClusteredPair(t *testing.T) (*server.Server, *server.Server opts2 := DefaultTestOptions opts2.Port = CLIENT_PORT + 1 opts2.HTTPPort = MONITOR_PORT + 1 - opts2.HTTPHost = "localhost" + opts2.HTTPHost = "127.0.0.1" opts2.Cluster = server.ClusterOpts{Host: "127.0.0.1", Port: 10222} opts2.Routes = server.RoutesFromStr("nats-route://127.0.0.1:10223") @@ -88,7 +88,7 @@ func TestNoMonitorPort(t *testing.T) { s := runMonitorServerNoHTTPPort() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", MONITOR_PORT) + url := fmt.Sprintf("http://127.0.0.1:%d/", MONITOR_PORT) if resp, err := http.Get(url + "varz"); err == nil { t.Fatalf("Expected error: Got %+v\n", resp) } @@ -166,7 +166,7 @@ func TestVarz(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", MONITOR_PORT) + url := fmt.Sprintf("http://127.0.0.1:%d/", MONITOR_PORT) resp, err := http.Get(url + "varz") if err != nil { t.Fatalf("Expected no error: Got %v\n", err) @@ -244,7 +244,7 @@ func TestConnz(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - url := fmt.Sprintf("http://localhost:%d/", MONITOR_PORT) + url := fmt.Sprintf("http://127.0.0.1:%d/", MONITOR_PORT) resp, err := http.Get(url + "connz") if err != nil { t.Fatalf("Expected no error: Got %v\n", err) @@ -365,7 +365,7 @@ func TestTLSConnz(t *testing.T) { // Wait for message <-ch - url := fmt.Sprintf("https://localhost:%d/", opts.HTTPSPort) + url := fmt.Sprintf("https://127.0.0.1:%d/", opts.HTTPSPort) tlsConfig := &tls.Config{} caCert, err := ioutil.ReadFile(rootCAFile) if err != nil { @@ -465,7 +465,7 @@ func TestConnzWithSubs(t *testing.T) { cl := createClientConnSubscribeAndPublish(t) defer cl.Close() - url := fmt.Sprintf("http://localhost:%d/", MONITOR_PORT) + url := fmt.Sprintf("http://127.0.0.1:%d/", MONITOR_PORT) resp, err := http.Get(url + "connz?subs=1") if err != nil { t.Fatalf("Expected no error: Got %v\n", err) @@ -510,7 +510,7 @@ func TestConnzWithAuth(t *testing.T) { // Wait for message <-ch - url := fmt.Sprintf("http://localhost:%d/", opts.HTTPPort) + url := fmt.Sprintf("http://127.0.0.1:%d/", opts.HTTPPort) resp, err := http.Get(url + "connz?auth=1") if err != nil { @@ -549,7 +549,7 @@ func TestConnzWithOffsetAndLimit(t *testing.T) { cl2 := createClientConnSubscribeAndPublish(t) defer cl2.Close() - url := fmt.Sprintf("http://localhost:%d/", MONITOR_PORT) + url := fmt.Sprintf("http://127.0.0.1:%d/", MONITOR_PORT) resp, err := http.Get(url + "connz?offset=1&limit=1") if err != nil { t.Fatalf("Expected no error: Got %v\n", err) @@ -588,7 +588,7 @@ func TestSubsz(t *testing.T) { cl := createClientConnSubscribeAndPublish(t) defer cl.Close() - url := fmt.Sprintf("http://localhost:%d/", MONITOR_PORT) + url := fmt.Sprintf("http://127.0.0.1:%d/", MONITOR_PORT) resp, err := http.Get(url + "subscriptionsz") if err != nil { t.Fatalf("Expected no error: Got %v\n", err) @@ -617,7 +617,7 @@ func TestHTTPHost(t *testing.T) { s := runMonitorServer() defer s.Shutdown() - // Grab non-localhost address and try to use that to connect. + // Grab non-127.0.0.1 address and try to use that to connect. // Should fail. var ip net.IP ifaces, _ := net.Interfaces() @@ -630,7 +630,7 @@ func TestHTTPHost(t *testing.T) { case *net.IPAddr: ip = v.IP } - // Skip loopback/localhost or any ipv6 for now. + // Skip loopback/127.0.0.1 or any ipv6 for now. if ip.IsLoopback() || ip.To4() == nil { ip = nil continue @@ -652,7 +652,7 @@ func TestHTTPHost(t *testing.T) { // Create a connection to test ConnInfo func createClientConnSubscribeAndPublish(t *testing.T) net.Conn { - cl := createClientConn(t, "localhost", CLIENT_PORT) + cl := createClientConn(t, "127.0.0.1", CLIENT_PORT) send, expect := setupConn(t, cl) expectMsgs := expectMsgsCommand(t, expect) @@ -665,7 +665,7 @@ func createClientConnSubscribeAndPublish(t *testing.T) net.Conn { func TestMonitorNoTLSConfig(t *testing.T) { opts := DefaultTestOptions opts.Port = CLIENT_PORT - opts.HTTPHost = "localhost" + opts.HTTPHost = "127.0.0.1" opts.HTTPSPort = MONITOR_PORT s := server.New(&opts) defer s.Shutdown() @@ -689,7 +689,7 @@ func TestMonitorErrorOnListen(t *testing.T) { opts := DefaultTestOptions opts.Port = CLIENT_PORT + 1 - opts.HTTPHost = "localhost" + opts.HTTPHost = "127.0.0.1" opts.HTTPPort = MONITOR_PORT s2 := server.New(&opts) defer s2.Shutdown() @@ -701,7 +701,7 @@ func TestMonitorErrorOnListen(t *testing.T) { func TestMonitorBothPortsConfigured(t *testing.T) { opts := DefaultTestOptions opts.Port = CLIENT_PORT - opts.HTTPHost = "localhost" + opts.HTTPHost = "127.0.0.1" opts.HTTPPort = MONITOR_PORT opts.HTTPSPort = MONITOR_PORT + 1 s := server.New(&opts) @@ -715,7 +715,7 @@ func TestMonitorStop(t *testing.T) { resetPreviousHTTPConnections() opts := DefaultTestOptions opts.Port = CLIENT_PORT - opts.HTTPHost = "localhost" + opts.HTTPHost = "127.0.0.1" opts.HTTPPort = MONITOR_PORT url := fmt.Sprintf("http://%v:%d/", opts.HTTPHost, MONITOR_PORT) // Create a server instance and start only the monitoring http server. diff --git a/test/pedantic_test.go b/test/pedantic_test.go index a3d9456b..62585336 100644 --- a/test/pedantic_test.go +++ b/test/pedantic_test.go @@ -33,7 +33,7 @@ func TestPedanticSub(t *testing.T) { s := runPedanticServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send := sendCommand(t, c) @@ -78,7 +78,7 @@ func TestPedanticPub(t *testing.T) { s := runPedanticServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send := sendCommand(t, c) diff --git a/test/ping_test.go b/test/ping_test.go index 65fb8b99..ceb14814 100644 --- a/test/ping_test.go +++ b/test/ping_test.go @@ -56,7 +56,7 @@ func TestPingSentToTLSConnection(t *testing.T) { s := RunServer(&opts) defer s.Shutdown() - c := createClientConn(t, "localhost", PING_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PING_TEST_PORT) defer c.Close() checkInfoMsg(t, c) @@ -104,7 +104,7 @@ func TestPingInterval(t *testing.T) { s := runPingServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PING_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PING_TEST_PORT) defer c.Close() doConnect(t, c, false, false, false) @@ -146,7 +146,7 @@ func TestUnpromptedPong(t *testing.T) { s := runPingServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PING_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PING_TEST_PORT) defer c.Close() doConnect(t, c, false, false, false) diff --git a/test/proto_test.go b/test/proto_test.go index 4bd04374..200c49bf 100644 --- a/test/proto_test.go +++ b/test/proto_test.go @@ -33,7 +33,7 @@ func TestProtoBasics(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) @@ -60,7 +60,7 @@ func TestProtoErr(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) @@ -74,7 +74,7 @@ func TestUnsubMax(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) @@ -97,7 +97,7 @@ func TestQueueSub(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) @@ -131,7 +131,7 @@ func TestMultipleQueueSub(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) @@ -168,7 +168,7 @@ func TestPubToArgState(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) @@ -181,7 +181,7 @@ func TestSubToArgState(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) @@ -195,7 +195,7 @@ func TestProtoCrash(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := sendCommand(t, c), expectCommand(t, c) @@ -215,7 +215,7 @@ func TestDuplicateProtoSub(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) @@ -247,7 +247,7 @@ func TestIncompletePubArg(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) @@ -281,7 +281,7 @@ func TestControlLineMaximums(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() send, expect := setupConn(t, c) diff --git a/test/route_discovery_test.go b/test/route_discovery_test.go index 5455bbef..417993d3 100644 --- a/test/route_discovery_test.go +++ b/test/route_discovery_test.go @@ -548,7 +548,7 @@ func TestSeedReturnIPInInfo(t *testing.T) { rc1ID := "2222" rc1Port := 22 - rc1Host := "localhost" + rc1Host := "127.0.0.1" routeSend1, route1Expect := setupRouteEx(t, rc1, opts, rc1ID) route1Expect(infoRe) @@ -566,7 +566,7 @@ func TestSeedReturnIPInInfo(t *testing.T) { rc2ID := "2224" rc2Port := 24 - rc2Host := "localhost" + rc2Host := "127.0.0.1" routeSend2, _ := setupRouteEx(t, rc2, opts, rc2ID) diff --git a/test/routes_test.go b/test/routes_test.go index ecd01f9f..3328f649 100644 --- a/test/routes_test.go +++ b/test/routes_test.go @@ -642,7 +642,7 @@ func TestRouteSendAsyncINFOToClients(t *testing.T) { sendRouteINFO := func(routeSend sendFun, routeExpect expectFun, urls []string) { routeInfo := server.Info{} routeInfo.ID = routeID - routeInfo.Host = "localhost" + routeInfo.Host = "127.0.0.1" routeInfo.Port = 5222 routeInfo.ClientConnectURLs = urls b, err := json.Marshal(routeInfo) diff --git a/test/test.go b/test/test.go index 1ebc9e3d..43684528 100644 --- a/test/test.go +++ b/test/test.go @@ -36,7 +36,7 @@ type tLogger interface { // DefaultTestOptions are default options for the unit tests. var DefaultTestOptions = server.Options{ - Host: "localhost", + Host: "127.0.0.1", Port: 4222, NoLog: true, NoSigs: true, diff --git a/test/verbose_test.go b/test/verbose_test.go index 84745204..d370a2df 100644 --- a/test/verbose_test.go +++ b/test/verbose_test.go @@ -21,7 +21,7 @@ func TestVerbosePing(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() doConnect(t, c, true, false, false) @@ -40,7 +40,7 @@ func TestVerboseConnect(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() doConnect(t, c, true, false, false) @@ -59,7 +59,7 @@ func TestVerbosePubSub(t *testing.T) { s := runProtoServer() defer s.Shutdown() - c := createClientConn(t, "localhost", PROTO_TEST_PORT) + c := createClientConn(t, "127.0.0.1", PROTO_TEST_PORT) defer c.Close() doConnect(t, c, true, false, false)