@@ -25,24 +25,22 @@ def test_TrailingSlashInUrl(self):
25
25
self .assertEqual ('http://localhost:8086' , self .client .api_client .configuration .host )
26
26
27
27
def test_ConnectToSelfSignedServer (self ):
28
- import http .server
29
- import ssl
28
+ self ._start_http_server ()
30
29
31
- # Disable unverified HTTPS requests
32
- import urllib3
33
- urllib3 . disable_warnings ()
30
+ self . client = InfluxDBClient ( f"https://localhost: { self . httpd . server_address [ 1 ] } " ,
31
+ token = "my-token" , verify_ssl = False )
32
+ health = self . client . health ()
34
33
35
- # Configure HTTP server
36
- self .httpd = http .server .HTTPServer (('localhost' , 0 ), ServerWithSelfSingedSSL )
37
- self .httpd .socket = ssl .wrap_socket (self .httpd .socket , certfile = f'{ os .path .dirname (__file__ )} /server.pem' ,
38
- server_side = True )
34
+ self .assertEqual (health .message , 'ready for queries and writes' )
35
+ self .assertEqual (health .status , "pass" )
36
+ self .assertEqual (health .name , "influxdb" )
39
37
40
- # Start server at background
41
- self .httpd_thread = threading .Thread (target = self .httpd .serve_forever )
42
- self .httpd_thread .start ()
38
+ def test_certificate_file (self ):
39
+ self ._start_http_server ()
43
40
44
41
self .client = InfluxDBClient (f"https://localhost:{ self .httpd .server_address [1 ]} " ,
45
- token = "my-token" , verify_ssl = False )
42
+ token = "my-token" , verify_ssl = True ,
43
+ ssl_ca_cert = f'{ os .path .dirname (__file__ )} /server.pem' )
46
44
health = self .client .health ()
47
45
48
46
self .assertEqual (health .message , 'ready for queries and writes' )
@@ -60,16 +58,54 @@ def test_init_from_file_ssl(self):
60
58
self .assertFalse (self .client .api_client .configuration .verify_ssl )
61
59
62
60
def test_init_from_env_ssl_default (self ):
63
- del os .environ ["INFLUXDB_V2_VERIFY_SSL" ]
61
+ if os .getenv ("INFLUXDB_V2_VERIFY_SSL" ):
62
+ del os .environ ["INFLUXDB_V2_VERIFY_SSL" ]
64
63
self .client = InfluxDBClient .from_env_properties ()
65
64
66
65
self .assertTrue (self .client .api_client .configuration .verify_ssl )
67
66
68
67
def test_init_from_env_ssl (self ):
69
- os .environ ["INFLUXDB_V2_VERIFY_SSL " ] = "False "
68
+ os .environ ["INFLUXDB_V2_SSL_CA_CERT " ] = "/my/custom/path "
70
69
self .client = InfluxDBClient .from_env_properties ()
71
70
72
- self .assertFalse (self .client .api_client .configuration .verify_ssl )
71
+ self .assertEqual ("/my/custom/path" , self .client .api_client .configuration .ssl_ca_cert )
72
+
73
+ def test_init_from_file_ssl_ca_cert_default (self ):
74
+ self .client = InfluxDBClient .from_config_file (f'{ os .path .dirname (__file__ )} /config.ini' )
75
+
76
+ self .assertIsNone (self .client .api_client .configuration .ssl_ca_cert )
77
+
78
+ def test_init_from_file_ssl_ca_cert (self ):
79
+ self .client = InfluxDBClient .from_config_file (f'{ os .path .dirname (__file__ )} /config-ssl-ca-cert.ini' )
80
+
81
+ self .assertEqual ("/path/to/my/cert" , self .client .api_client .configuration .ssl_ca_cert )
82
+
83
+ def test_init_from_env_ssl_ca_cert_default (self ):
84
+ if os .getenv ("INFLUXDB_V2_SSL_CA_CERT" ):
85
+ del os .environ ["INFLUXDB_V2_SSL_CA_CERT" ]
86
+ self .client = InfluxDBClient .from_env_properties ()
87
+
88
+ self .assertIsNone (self .client .api_client .configuration .ssl_ca_cert )
89
+
90
+ def test_init_from_env_ssl_ca_cert (self ):
91
+ os .environ ["INFLUXDB_V2_SSL_CA_CERT" ] = "/my/custom/path/to/cert"
92
+ self .client = InfluxDBClient .from_env_properties ()
93
+
94
+ self .assertEqual ("/my/custom/path/to/cert" , self .client .api_client .configuration .ssl_ca_cert )
95
+
96
+ def _start_http_server (self ):
97
+ import http .server
98
+ import ssl
99
+ # Disable unverified HTTPS requests
100
+ import urllib3
101
+ urllib3 .disable_warnings ()
102
+ # Configure HTTP server
103
+ self .httpd = http .server .HTTPServer (('localhost' , 0 ), ServerWithSelfSingedSSL )
104
+ self .httpd .socket = ssl .wrap_socket (self .httpd .socket , certfile = f'{ os .path .dirname (__file__ )} /server.pem' ,
105
+ server_side = True )
106
+ # Start server at background
107
+ self .httpd_thread = threading .Thread (target = self .httpd .serve_forever )
108
+ self .httpd_thread .start ()
73
109
74
110
75
111
class ServerWithSelfSingedSSL (http .server .SimpleHTTPRequestHandler ):
0 commit comments