1
+ extern crate os_type;
2
+
1
3
pub mod common;
2
4
use common:: * ;
3
5
4
6
use elasticsearch:: cert:: { Certificate , CertificateValidation } ;
7
+ use os_type:: OSType ;
5
8
6
9
// TODO: These tests require a cluster configured with Security. Figure out best way to surface this e.g. test category, naming convention, etc.
7
10
@@ -13,7 +16,11 @@ fn expected_error_message() -> String {
13
16
if cfg ! ( windows) {
14
17
"terminated in a root certificate which is not trusted by the trust provider" . to_string ( )
15
18
} else {
16
- "unable to get local issuer certificate" . to_string ( )
19
+ let os = os_type:: current_platform ( ) ;
20
+ match os. os_type {
21
+ OSType :: OSX => "The certificate was not trusted" . to_string ( ) ,
22
+ _ => "unable to get local issuer certificate" . to_string ( )
23
+ }
17
24
}
18
25
}
19
26
@@ -87,21 +94,32 @@ async fn full_certificate_validation() -> Result<(), failure::Error> {
87
94
client:: create_default_builder ( ) . cert_validation ( CertificateValidation :: Full ( cert) ) ;
88
95
let client = client:: create ( builder) ;
89
96
let result = client. ping ( ) . send ( ) . await ;
90
- match result {
91
- Ok ( response) => Err ( failure:: err_msg ( format ! (
92
- "Expected error but response was {}" ,
93
- response. status_code( )
94
- ) ) ) ,
95
- Err ( e) => {
96
- let expected = "unable to get local issuer certificate" ;
97
- let actual = e. to_string ( ) ;
98
- assert ! (
99
- actual. contains( expected) ,
100
- "Expected error message to contain '{}' but was '{}'" ,
101
- expected,
102
- actual
103
- ) ;
104
- Ok ( ( ) )
97
+ let os_type = os_type:: current_platform ( ) ;
98
+ match os_type. os_type {
99
+ OSType :: OSX => {
100
+ match result {
101
+ Ok ( _) => Ok ( ( ) ) ,
102
+ Err ( e) => Err ( failure:: err_msg ( e. to_string ( ) ) ) ,
103
+ }
104
+ } ,
105
+ _ => {
106
+ match result {
107
+ Ok ( response) => Err ( failure:: err_msg ( format ! (
108
+ "Expected error but response was {}" ,
109
+ response. status_code( )
110
+ ) ) ) ,
111
+ Err ( e) => {
112
+ let expected = expected_error_message ( ) ;
113
+ let actual = e. to_string ( ) ;
114
+ assert ! (
115
+ actual. contains( & expected) ,
116
+ "Expected error message to contain '{}' but was '{}'" ,
117
+ expected,
118
+ actual
119
+ ) ;
120
+ Ok ( ( ) )
121
+ }
122
+ }
105
123
}
106
124
}
107
125
}
@@ -128,21 +146,32 @@ async fn certificate_certificate_validation() -> Result<(), failure::Error> {
128
146
client:: create_default_builder ( ) . cert_validation ( CertificateValidation :: Certificate ( cert) ) ;
129
147
let client = client:: create ( builder) ;
130
148
let result = client. ping ( ) . send ( ) . await ;
131
- match result {
132
- Ok ( response) => Err ( failure:: err_msg ( format ! (
133
- "Expected error but response was {}" ,
134
- response. status_code( )
135
- ) ) ) ,
136
- Err ( e) => {
137
- let expected = "unable to get local issuer certificate" ;
138
- let actual = e. to_string ( ) ;
139
- assert ! (
140
- actual. contains( expected) ,
141
- "Expected error message to contain '{}' but was '{}'" ,
142
- expected,
143
- actual
144
- ) ;
145
- Ok ( ( ) )
149
+ let os_type = os_type:: current_platform ( ) ;
150
+ match os_type. os_type {
151
+ OSType :: OSX => {
152
+ match result {
153
+ Ok ( _) => Ok ( ( ) ) ,
154
+ Err ( e) => Err ( failure:: err_msg ( e. to_string ( ) ) ) ,
155
+ }
156
+ } ,
157
+ _ => {
158
+ match result {
159
+ Ok ( response) => Err ( failure:: err_msg ( format ! (
160
+ "Expected error but response was {}" ,
161
+ response. status_code( )
162
+ ) ) ) ,
163
+ Err ( e) => {
164
+ let expected = expected_error_message ( ) ;
165
+ let actual = e. to_string ( ) ;
166
+ assert ! (
167
+ actual. contains( & expected) ,
168
+ "Expected error message to contain '{}' but was '{}'" ,
169
+ expected,
170
+ actual
171
+ ) ;
172
+ Ok ( ( ) )
173
+ }
174
+ }
146
175
}
147
176
}
148
177
}
0 commit comments