|
7 | 7 | #include "data/es/json_es.h" /* JSON_ES */
|
8 | 8 |
|
9 | 9 |
|
| 10 | +static void cb_check_http_api_key(void *ctx, int ffd, |
| 11 | + int res_ret, void *res_data, |
| 12 | + size_t res_size, void *data) |
| 13 | +{ |
| 14 | + char *p; |
| 15 | + char *out_js = res_data; |
| 16 | + char *auth_header = data; |
| 17 | + |
| 18 | + /* Check if the Authorization header is properly set */ |
| 19 | + TEST_CHECK(res_data != NULL); |
| 20 | + |
| 21 | + /* Print test debugging info */ |
| 22 | + flb_debug("[api key test] %s, data: %s", auth_header, out_js); |
| 23 | + |
| 24 | + flb_free(res_data); |
| 25 | +} |
| 26 | + |
| 27 | + |
10 | 28 | static void cb_check_write_op_index(void *ctx, int ffd,
|
11 | 29 | int res_ret, void *res_data,
|
12 | 30 | size_t res_size, void *data)
|
@@ -722,6 +740,51 @@ void flb_test_div0()
|
722 | 740 | flb_destroy(ctx);
|
723 | 741 | }
|
724 | 742 |
|
| 743 | +void flb_test_http_api_key() |
| 744 | +{ |
| 745 | + int ret; |
| 746 | + int size = sizeof(JSON_ES) - 1; |
| 747 | + flb_ctx_t *ctx; |
| 748 | + int in_ffd; |
| 749 | + int out_ffd; |
| 750 | + char *api_key = "my-api-key-for-elasticsearch"; |
| 751 | + |
| 752 | + /* Create context, flush every second (some checks omitted here) */ |
| 753 | + ctx = flb_create(); |
| 754 | + flb_service_set(ctx, "flush", "1", "grace", "1", NULL); |
| 755 | + |
| 756 | + /* Lib input mode */ |
| 757 | + in_ffd = flb_input(ctx, (char *) "lib", NULL); |
| 758 | + flb_input_set(ctx, in_ffd, "tag", "test", NULL); |
| 759 | + |
| 760 | + /* Elasticsearch output */ |
| 761 | + out_ffd = flb_output(ctx, (char *) "es", NULL); |
| 762 | + flb_output_set(ctx, out_ffd, |
| 763 | + "match", "test", |
| 764 | + NULL); |
| 765 | + |
| 766 | + /* Configure http_api_key */ |
| 767 | + flb_output_set(ctx, out_ffd, |
| 768 | + "http_api_key", api_key, |
| 769 | + NULL); |
| 770 | + |
| 771 | + /* Enable test mode */ |
| 772 | + ret = flb_output_set_test(ctx, out_ffd, "formatter", |
| 773 | + cb_check_http_api_key, |
| 774 | + api_key, NULL); |
| 775 | + |
| 776 | + /* Start */ |
| 777 | + ret = flb_start(ctx); |
| 778 | + TEST_CHECK(ret == 0); |
| 779 | + |
| 780 | + /* Ingest data sample */ |
| 781 | + flb_lib_push(ctx, in_ffd, (char *) JSON_ES, size); |
| 782 | + |
| 783 | + sleep(2); |
| 784 | + flb_stop(ctx); |
| 785 | + flb_destroy(ctx); |
| 786 | +} |
| 787 | + |
725 | 788 |
|
726 | 789 | static void cb_check_long_index(void *ctx, int ffd,
|
727 | 790 | int res_ret, void *res_data, size_t res_size,
|
@@ -1012,6 +1075,7 @@ TEST_LIST = {
|
1012 | 1075 | {"tag_key" , flb_test_tag_key },
|
1013 | 1076 | {"replace_dots" , flb_test_replace_dots },
|
1014 | 1077 | {"id_key" , flb_test_id_key },
|
| 1078 | + {"http_api_key" , flb_test_http_api_key }, |
1015 | 1079 | {"logstash_prefix_separator" , flb_test_logstash_prefix_separator },
|
1016 | 1080 | {"response_success" , flb_test_response_success },
|
1017 | 1081 | {"response_successes", flb_test_response_successes },
|
|
0 commit comments