Skip to content

Commit 48565c6

Browse files
authored
Par 16742 verify config (#171)
* feat: Added `verify-certificates` parameter support in event sending and lookups management clients * fix: Some documentation fixes
1 parent c14f7c7 commit 48565c6

File tree

6 files changed

+90
-23
lines changed

6 files changed

+90
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [5.0.6] - Unreleased
7+
## [5.0.6] - 2023-02-21
88
### Chorus
99
* Update version range support for `requests`
1010
### Fixed
1111
* Documentation fixes in `README.md` and `docs/common.md`
12+
* Documentation related to testing updated at `README.md`
13+
### Added
14+
* Added `verify-certificates` parameter support in event sending and lookups management clients
1215

1316
## [5.0.5] - 2023-02-20
1417
### Fix
@@ -20,7 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2023
## [5.0.4] - 2023-02-13
2124
### Chorus
2225
* Fix documentation (implementation remains the same) for keep-alive mechanism in queries for `xls` format
23-
* Bump version to avoid collision with tag belonging to fomer release candidate version
26+
* Bump version to avoid collision with tag belonging to former release candidate version
2427

2528
## [5.0.3] - 2023-01-26
2629
### Fixed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ You can also run the test for just one module. This is a useful feature if you a
125125
~/projects/devo-python-sdk > python run_tests.py -m SEND_CLI
126126
```
127127

128+
You can also exclude one or several tests with `-M` parameter:
129+
130+
```console
131+
~/projects/devo-python-sdk > python run_tests.py -M SEND_CLI,API_CLI
132+
```
133+
128134
Using the --help flag prints the available modules to use:
129135

130136
```console
@@ -135,17 +141,27 @@ optional arguments:
135141
-h, --help show this help message and exit
136142
--coverage [COVERAGE]
137143
Generate coverage
138-
-m [MODULE], --module [MODULE]
139-
Run tests for selected module: API_CLI, API_QUERY, API_TASKS, COMMON_CONFIGURATION,
140-
COMMON_DATE_PARSER, SENDER_CLI, SENDER_NUMBER_LOOKUP, SENDER_SEND_DATA, SENDER_SEND_LOOKUP
144+
-m [MODULES], --modules [MODULES]
145+
Run tests for selected modules: API_CLI, API_QUERY, API_TASKS, API_ERRORS, API_PARSER_DATE,
146+
API_PROCESSORS, API_KEEPALIVE, COMMON_CONFIGURATION, COMMON_DATE_PARSER, SENDER_CLI, SENDER_CSV,
147+
SENDER_NUMBER_LOOKUP, SENDER_SEND_DATA, SENDER_SEND_LOOKUP
148+
-M [EXCLUDE_MODULES], --exclude-modules [EXCLUDE_MODULES]
149+
Exclude tests for modules: API_CLI, API_QUERY, API_TASKS, API_ERRORS, API_PARSER_DATE,
150+
API_PROCESSORS, API_KEEPALIVE, COMMON_CONFIGURATION, COMMON_DATE_PARSER, SENDER_CLI, SENDER_CSV,
151+
SENDER_NUMBER_LOOKUP, SENDER_SEND_DATA, SENDER_SEND_LOOKUP
141152
```
142153

143154
* API_CLI: API Command-line interface tests.
144155
* API_QUERY: Query API tests.
145156
* API_TASKS: Task API tests.
157+
* API_ERRORS: Managing of API Errors tests.
158+
* API_PARSER_DATE: Parsing of dates in API tests.
159+
* API_PROCESSORS: Response processors in API tests.
160+
* API_KEEPALIVE: Keep Alive functionality in API tests.
146161
* COMMON_CONFIGURATION: Configuration tests.
147162
* COMMON_DATE_PARSER: Date parser tests.
148163
* SENDER_CLI: Lookup command-line interface tests.
164+
* SENDER_CSV: Lookup uploading through CSV tests.
149165
* SENDER_NUMBER_LOOKUP: Numbers in lookup tests
150166
* SENDER_SEND_DATA: Data sending tests.
151167
* SENDER_SEND_LOOKUP: Lookup sending tests.

devo/sender/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def check_config_certificate_chain(self):
195195
def check_config_certificate_address(self):
196196
"""
197197
Check if the certificate is compatible with the
198-
address, also check is the address and port are
198+
address, also check if the address and port are
199199
valid.
200200
201201
:return: Boolean true or raises an exception

devo/sender/scripts/sender_cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def cli(version):
7777
@click.option('--compression_level', help='Compression level for zipped data. '
7878
'Read readme for more info',
7979
type=int)
80+
@click.option('--no-verify-certificates', help='Do not Verify certificates '
81+
'credentials before connection',
82+
type=bool, is_flag=True)
8083
@click.option('--env', '-e', help='Use env vars for configuration',
8184
default=False, type=bool)
8285
@click.option('--default', '-d', help='Use default file for configuration',
@@ -176,6 +179,9 @@ def data(**kwargs):
176179
@click.option('--escapequotes', '-eq', is_flag=True,
177180
help='Escape Quotes. Default: False',
178181
default=False)
182+
@click.option('--no-verify-certificates', help='Do not Verify certificates '
183+
'credentials before connection',
184+
type=bool, is_flag=True)
179185
@click.option('--debug/--no-debug', help='For testing purposes', default=False)
180186
def lookup(**kwargs):
181187
"""Send csv lookups to devo"""
@@ -226,6 +232,8 @@ def init_conf(args):
226232
if args.get('config'):
227233
config.load_config(args.get('config'), 'sender')
228234

235+
config['verify_config'] = not args.get('no_verify_certificates', False)
236+
229237
if args.get('env'):
230238
config.set("address",
231239
os.environ.get('DEVO_SENDER_ADDRESS',

docs/api/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Query by id has the same parameters as query (), changing the field "query"
176176
to "query_id", which is the ID of the query in Devo.
177177

178178
## Not verify certificates
179-
If server has https certificates with problems, autogenrados or not verified, you can deactivate
179+
If server has https certificates with problems, autogenerated or not verified, you can deactivate
180180
the secure calls (Verifying the certificates https when making the call) disabling it with:
181181

182182
```python

tests/sender/cli.py

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313

1414
class 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-
160200
if __name__ == '__main__':
161201
unittest.main()

0 commit comments

Comments
 (0)