@@ -2,6 +2,8 @@ extern crate influxdb;
2
2
3
3
#[ path = "./utilities.rs" ]
4
4
mod utilities;
5
+
6
+ use serde:: Deserialize ;
5
7
use utilities:: {
6
8
assert_result_err, assert_result_ok, create_client, create_db, delete_db, run_test,
7
9
} ;
@@ -271,6 +273,88 @@ async fn test_write_and_read_field() {
271
273
. await ;
272
274
}
273
275
276
+ /// INTEGRATION TEST
277
+ ///
278
+ /// This test case tests the authentication on json reads
279
+ #[ async_std:: test]
280
+ #[ cfg( feature = "use-serde" ) ]
281
+ #[ cfg( not( tarpaulin_include) ) ]
282
+ async fn test_json_non_authed_read ( ) {
283
+ const TEST_NAME : & str = "test_json_non_authed_read" ;
284
+
285
+ run_test (
286
+ || async move {
287
+ let client =
288
+ Client :: new ( "http://127.0.0.1:9086" , TEST_NAME ) . with_auth ( "admin" , "password" ) ;
289
+ let query = format ! ( "CREATE DATABASE {}" , TEST_NAME ) ;
290
+ client
291
+ . query ( ReadQuery :: new ( query) )
292
+ . await
293
+ . expect ( "could not setup db" ) ;
294
+ let non_authed_client = Client :: new ( "http://127.0.0.1:9086" , TEST_NAME ) ;
295
+
296
+ let read_query = ReadQuery :: new ( "SELECT * FROM weather" ) ;
297
+ let read_result = non_authed_client. json_query ( read_query) . await ;
298
+ assert_result_err ( & read_result) ;
299
+ match read_result {
300
+ Err ( Error :: AuthorizationError ) => { }
301
+ _ => panic ! (
302
+ "Should be a AuthorizationError: {}" ,
303
+ read_result. unwrap_err( )
304
+ ) ,
305
+ }
306
+ } ,
307
+ || async move {
308
+ let client =
309
+ Client :: new ( "http://127.0.0.1:9086" , TEST_NAME ) . with_auth ( "admin" , "password" ) ;
310
+ let query = format ! ( "DROP DATABASE {}" , TEST_NAME ) ;
311
+
312
+ client
313
+ . query ( ReadQuery :: new ( query) )
314
+ . await
315
+ . expect ( "could not clean up db" ) ;
316
+ } ,
317
+ )
318
+ . await
319
+ }
320
+
321
+ /// INTEGRATION TEST
322
+ ///
323
+ /// This test case tests the authentication on json reads
324
+ #[ async_std:: test]
325
+ #[ cfg( feature = "use-serde" ) ]
326
+ #[ cfg( not( tarpaulin_include) ) ]
327
+ async fn test_json_authed_read ( ) {
328
+ const TEST_NAME : & str = "test_json_authed_read" ;
329
+
330
+ run_test (
331
+ || async move {
332
+ let client =
333
+ Client :: new ( "http://127.0.0.1:9086" , TEST_NAME ) . with_auth ( "admin" , "password" ) ;
334
+ let query = format ! ( "CREATE DATABASE {}" , TEST_NAME ) ;
335
+ client
336
+ . query ( ReadQuery :: new ( query) )
337
+ . await
338
+ . expect ( "could not setup db" ) ;
339
+
340
+ let read_query = ReadQuery :: new ( "SELECT * FROM weather" ) ;
341
+ let read_result = client. json_query ( read_query) . await ;
342
+ assert_result_ok ( & read_result) ;
343
+ } ,
344
+ || async move {
345
+ let client =
346
+ Client :: new ( "http://127.0.0.1:9086" , TEST_NAME ) . with_auth ( "admin" , "password" ) ;
347
+ let query = format ! ( "DROP DATABASE {}" , TEST_NAME ) ;
348
+
349
+ client
350
+ . query ( ReadQuery :: new ( query) )
351
+ . await
352
+ . expect ( "could not clean up db" ) ;
353
+ } ,
354
+ )
355
+ . await
356
+ }
357
+
274
358
/// INTEGRATION TEST
275
359
///
276
360
/// This integration tests that writing data and retrieving the data again is working
0 commit comments