1313
1414class TestSender (unittest .TestCase ):
1515 def setUp (self ):
16- self .address = os .getenv ('DEVO_SENDER_SERVER' , "127.0.0.1" )
17- self .port = int (os .getenv ('DEVO_SENDER_PORT' , 4488 ))
16+ self .local_address = os .getenv ('DEVO_SENDER_SERVER' , "127.0.0.1" )
17+ self .local_port = int (os .getenv ('DEVO_SENDER_PORT' , 4488 ))
1818 self .tcp_address = os .getenv ('DEVO_SENDER_TCP_SERVER' , "127.0.0.1" )
1919 self .tcp_port = int (os .getenv ('DEVO_SENDER_TCP_PORT' , 4489 ))
2020
21+ self .remote_address = os .getenv ('DEVO_REMOTE_SENDER_SERVER' ,
22+ "collector-us.devo.io" )
23+ self .remote_port = int (os .getenv ('DEVO_REMOTE_SENDER_PORT' , 443 ))
24+
2125 self .key = os .getenv ('DEVO_SENDER_KEY' , CLIENT_KEY )
2226 self .cert = os .getenv ('DEVO_SENDER_CERT' , CLIENT_CERT )
2327 self .chain = os .getenv ('DEVO_SENDER_CHAIN' , CLIENT_CHAIN )
@@ -42,7 +46,7 @@ def setUp(self):
4246 configuration = Configuration ()
4347 configuration .set ("sender" , {
4448 "key" : self .key , "cert" : self .cert , "chain" : self .chain ,
45- "address" : self .address , "port" : self .port ,
49+ "address" : self .local_address , "port" : self .local_port ,
4650 "verify_mode" : 0 , "check_hostname" : False
4751 })
4852
@@ -57,9 +61,10 @@ def test_cli_args(self):
5761 def test_cli_bad_address (self ):
5862 runner = CliRunner ()
5963 result = runner .invoke (data , ["--debug" ,
60- "--address" , self .address + "asd" ])
64+ "--type" , "TCP" ,
65+ "--address" , self .local_address + "asd" ])
6166 self .assertIsInstance (result .exception , DevoSenderException )
62- self .assertIn ("SSL conn establishment socket error" , result .stdout )
67+ self .assertIn ("TCP conn establishment socket error" , result .stdout )
6368
6469 def test_cli_bad_certs (self ):
6570 runner = CliRunner ()
@@ -73,6 +78,22 @@ def test_cli_bad_certs(self):
7378 "--verify_mode" , 1 ,
7479 '--check_hostname' , True ])
7580 self .assertIsInstance (result .exception , DevoSenderException )
81+ self .assertIn ("Error in the configuration" ,
82+ result .exception .args [0 ])
83+
84+ def test_cli_bad_certs_no_verify_on (self ):
85+ runner = CliRunner ()
86+ result = runner .invoke (data , ["--debug" ,
87+ "--address" ,
88+ "collector-us.devo.io" ,
89+ "--port" , "443" ,
90+ "--key" , self .local_key ,
91+ "--cert" , self .cert ,
92+ "--chain" , self .chain ,
93+ "--verify_mode" , 1 ,
94+ '--check_hostname' , True ,
95+ "--no-verify-certificates" ])
96+ self .assertIsInstance (result .exception , DevoSenderException )
7697 self .assertIn ("SSL conn establishment socket error" ,
7798 result .exception .args [0 ])
7899
@@ -92,11 +113,28 @@ def test_cli_notfound_certs(self):
92113 "'not_a_folder/not_a_file' does not exist." ,
93114 result .output )
94115
95- def test_cli_normal_send (self ):
116+ def test_cli_normal_send_without_certificates_checking (self ):
96117 runner = CliRunner ()
97118 result = runner .invoke (data , ["--debug" ,
98- "--address" , self .address ,
99- "--port" , self .port ,
119+ "--address" , self .local_address ,
120+ "--port" , self .local_port ,
121+ "--key" , self .key ,
122+ "--cert" , self .cert ,
123+ "--chain" , self .chain ,
124+ "--tag" , self .my_app ,
125+ "--verify_mode" , 0 ,
126+ '--check_hostname' , False ,
127+ "--line" , "Test line" ,
128+ "--no-verify-certificates" ])
129+
130+ self .assertIsNone (result .exception )
131+ self .assertGreater (int (result .output .split ("Sended: " )[- 1 ]), 0 )
132+
133+ def test_cli_normal_send_with_certificates_checking (self ):
134+ runner = CliRunner ()
135+ result = runner .invoke (data , ["--debug" ,
136+ "--address" , self .remote_address ,
137+ "--port" , self .remote_port ,
100138 "--key" , self .key ,
101139 "--cert" , self .cert ,
102140 "--chain" , self .chain ,
@@ -112,16 +150,17 @@ def test_cli_with_config_file(self):
112150 if self .config_path :
113151 runner = CliRunner ()
114152 result = runner .invoke (data , ["--debug" ,
115- "--config" , self .config_path ])
153+ "--config" , self .config_path ,
154+ "--no-verify-certificates" ])
116155
117156 self .assertIsNone (result .exception )
118157 self .assertGreater (int (result .output .split ("Sended: " )[- 1 ]), 0 )
119158
120159 def test_cli_escape_quotes (self ):
121160 runner = CliRunner ()
122161 result = runner .invoke (lookup , ["--debug" ,
123- "--address" , self .address ,
124- "--port" , self .port ,
162+ "--address" , self .local_address ,
163+ "--port" , self .local_port ,
125164 "--key" , self .key ,
126165 "--cert" , self .cert ,
127166 "--chain" , self .chain ,
@@ -131,7 +170,8 @@ def test_cli_escape_quotes(self):
131170 "-ac" , "FULL" ,
132171 "-f" , self .lookup_file ,
133172 "-lk" , "KEY" ,
134- "-eq"
173+ "-eq" ,
174+ "--no-verify-certificates"
135175 ])
136176
137177 self .assertIsNone (result .exception )
@@ -140,8 +180,8 @@ def test_cli_escape_quotes(self):
140180 def test_cli_not_escape_quotes (self ):
141181 runner = CliRunner ()
142182 result = runner .invoke (lookup , ["--debug" ,
143- "--address" , self .address ,
144- "--port" , self .port ,
183+ "--address" , self .local_address ,
184+ "--port" , self .local_port ,
145185 "--key" , self .key ,
146186 "--cert" , self .cert ,
147187 "--chain" , self .chain ,
@@ -150,12 +190,12 @@ def test_cli_not_escape_quotes(self):
150190 "-n" , self .lookup_name ,
151191 "-ac" , "FULL" ,
152192 "-f" , self .lookup_file ,
153- "-lk" , "KEY"
193+ "-lk" , "KEY" ,
194+ "--no-verify-certificates"
154195 ])
155196
156197 self .assertIsNotNone (result .exception )
157198 self .assertEquals (result .exit_code , 64 )
158199
159-
160200if __name__ == '__main__' :
161201 unittest .main ()
0 commit comments