13
13
14
14
class TestSender (unittest .TestCase ):
15
15
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 ))
18
18
self .tcp_address = os .getenv ('DEVO_SENDER_TCP_SERVER' , "127.0.0.1" )
19
19
self .tcp_port = int (os .getenv ('DEVO_SENDER_TCP_PORT' , 4489 ))
20
20
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
+
21
25
self .key = os .getenv ('DEVO_SENDER_KEY' , CLIENT_KEY )
22
26
self .cert = os .getenv ('DEVO_SENDER_CERT' , CLIENT_CERT )
23
27
self .chain = os .getenv ('DEVO_SENDER_CHAIN' , CLIENT_CHAIN )
@@ -42,7 +46,7 @@ def setUp(self):
42
46
configuration = Configuration ()
43
47
configuration .set ("sender" , {
44
48
"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 ,
46
50
"verify_mode" : 0 , "check_hostname" : False
47
51
})
48
52
@@ -57,9 +61,10 @@ def test_cli_args(self):
57
61
def test_cli_bad_address (self ):
58
62
runner = CliRunner ()
59
63
result = runner .invoke (data , ["--debug" ,
60
- "--address" , self .address + "asd" ])
64
+ "--type" , "TCP" ,
65
+ "--address" , self .local_address + "asd" ])
61
66
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 )
63
68
64
69
def test_cli_bad_certs (self ):
65
70
runner = CliRunner ()
@@ -73,6 +78,22 @@ def test_cli_bad_certs(self):
73
78
"--verify_mode" , 1 ,
74
79
'--check_hostname' , True ])
75
80
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 )
76
97
self .assertIn ("SSL conn establishment socket error" ,
77
98
result .exception .args [0 ])
78
99
@@ -92,11 +113,28 @@ def test_cli_notfound_certs(self):
92
113
"'not_a_folder/not_a_file' does not exist." ,
93
114
result .output )
94
115
95
- def test_cli_normal_send (self ):
116
+ def test_cli_normal_send_without_certificates_checking (self ):
96
117
runner = CliRunner ()
97
118
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 ,
100
138
"--key" , self .key ,
101
139
"--cert" , self .cert ,
102
140
"--chain" , self .chain ,
@@ -112,16 +150,17 @@ def test_cli_with_config_file(self):
112
150
if self .config_path :
113
151
runner = CliRunner ()
114
152
result = runner .invoke (data , ["--debug" ,
115
- "--config" , self .config_path ])
153
+ "--config" , self .config_path ,
154
+ "--no-verify-certificates" ])
116
155
117
156
self .assertIsNone (result .exception )
118
157
self .assertGreater (int (result .output .split ("Sended: " )[- 1 ]), 0 )
119
158
120
159
def test_cli_escape_quotes (self ):
121
160
runner = CliRunner ()
122
161
result = runner .invoke (lookup , ["--debug" ,
123
- "--address" , self .address ,
124
- "--port" , self .port ,
162
+ "--address" , self .local_address ,
163
+ "--port" , self .local_port ,
125
164
"--key" , self .key ,
126
165
"--cert" , self .cert ,
127
166
"--chain" , self .chain ,
@@ -131,7 +170,8 @@ def test_cli_escape_quotes(self):
131
170
"-ac" , "FULL" ,
132
171
"-f" , self .lookup_file ,
133
172
"-lk" , "KEY" ,
134
- "-eq"
173
+ "-eq" ,
174
+ "--no-verify-certificates"
135
175
])
136
176
137
177
self .assertIsNone (result .exception )
@@ -140,8 +180,8 @@ def test_cli_escape_quotes(self):
140
180
def test_cli_not_escape_quotes (self ):
141
181
runner = CliRunner ()
142
182
result = runner .invoke (lookup , ["--debug" ,
143
- "--address" , self .address ,
144
- "--port" , self .port ,
183
+ "--address" , self .local_address ,
184
+ "--port" , self .local_port ,
145
185
"--key" , self .key ,
146
186
"--cert" , self .cert ,
147
187
"--chain" , self .chain ,
@@ -150,12 +190,12 @@ def test_cli_not_escape_quotes(self):
150
190
"-n" , self .lookup_name ,
151
191
"-ac" , "FULL" ,
152
192
"-f" , self .lookup_file ,
153
- "-lk" , "KEY"
193
+ "-lk" , "KEY" ,
194
+ "--no-verify-certificates"
154
195
])
155
196
156
197
self .assertIsNotNone (result .exception )
157
198
self .assertEquals (result .exit_code , 64 )
158
199
159
-
160
200
if __name__ == '__main__' :
161
201
unittest .main ()
0 commit comments