@@ -22,6 +22,8 @@ import (
2222 "testing"
2323 "time"
2424
25+ "github.com/stretchr/testify/require"
26+
2527 "go.etcd.io/etcd/tests/v3/framework/e2e"
2628)
2729
@@ -76,3 +78,84 @@ type logEntry struct {
7678 Caller string `json:"caller"`
7779 Message string `json:"msg"`
7880}
81+
82+ func TestConnectionRejectMessage (t * testing.T ) {
83+ e2e .SkipInShortMode (t )
84+
85+ testCases := []struct {
86+ name string
87+ url string
88+ expectedErrMsg string
89+ }{
90+ {
91+ name : "reject client connection" ,
92+ url : "https://127.0.0.1:2379/version" ,
93+ expectedErrMsg : "rejected connection on client endpoint" ,
94+ },
95+ {
96+ name : "reject peer connection" ,
97+ url : "https://127.0.0.1:2380/members" ,
98+ expectedErrMsg : "rejected connection on peer endpoint" ,
99+ },
100+ }
101+
102+ for _ , tc := range testCases {
103+ t .Run (tc .name , func (t * testing.T ) {
104+ commonArgs := []string {
105+ e2e .BinPath ,
106+ "--name" , "etcd1" ,
107+ "--listen-client-urls" , "https://127.0.0.1:2379" ,
108+ "--advertise-client-urls" , "https://127.0.0.1:2379" ,
109+ "--cert-file" , e2e .CertPath ,
110+ "--key-file" , e2e .PrivateKeyPath ,
111+ "--trusted-ca-file" , e2e .CaPath ,
112+ "--listen-peer-urls" , "https://127.0.0.1:2380" ,
113+ "--initial-advertise-peer-urls" , "https://127.0.0.1:2380" ,
114+ "--initial-cluster" , "etcd1=https://127.0.0.1:2380" ,
115+ "--peer-cert-file" , e2e .CertPath ,
116+ "--peer-key-file" , e2e .PrivateKeyPath ,
117+ "--peer-trusted-ca-file" , e2e .CaPath ,
118+ }
119+
120+ t .Log ("Starting an etcd process and wait for it to get ready." )
121+ p , err := e2e .SpawnCmd (commonArgs , nil )
122+ require .NoError (t , err )
123+ err = e2e .WaitReadyExpectProc (p , e2e .EtcdServerReadyLines )
124+ require .NoError (t , err )
125+ defer func () {
126+ p .Stop ()
127+ p .Close ()
128+ }()
129+
130+ t .Log ("Starting a separate goroutine to verify the expected output." )
131+ startedCh := make (chan struct {}, 1 )
132+ doneCh := make (chan struct {}, 1 )
133+ go func () {
134+ startedCh <- struct {}{}
135+ verr := e2e .WaitReadyExpectProc (p , []string {tc .expectedErrMsg })
136+ require .NoError (t , verr )
137+ doneCh <- struct {}{}
138+ }()
139+
140+ // wait for the goroutine to get started
141+ <- startedCh
142+
143+ t .Log ("Running curl command to trigger the corresponding warning message." )
144+ curlCmdArgs := []string {"curl" , "--connect-timeout" , "1" , "-k" , tc .url }
145+ curlCmd , err := e2e .SpawnCmd (curlCmdArgs , nil )
146+ require .NoError (t , err )
147+
148+ defer func () {
149+ curlCmd .Stop ()
150+ curlCmd .Close ()
151+ }()
152+
153+ t .Log ("Waiting for the result." )
154+ select {
155+ case <- doneCh :
156+ case <- time .After (5 * time .Second ):
157+ t .Fatal ("Timed out waiting for the result" )
158+ }
159+ })
160+ }
161+ }
0 commit comments