Skip to content

Commit b0686bb

Browse files
committed
tests: add unit tests for Azure Blob OAuth authentication
Add configuration validation tests for all Azure Blob authentication methods: - System-assigned managed identity - User-assigned managed identity - Service principal - Workload identity - Shared key (existing) - SAS token (existing) Tests verify configuration parsing and plugin initialization without requiring actual Azure connectivity or credentials. Signed-off-by: zshuang0316 <zshuang0316@163.com>
1 parent 444e7ac commit b0686bb

File tree

2 files changed

+237
-0
lines changed

2 files changed

+237
-0
lines changed

tests/runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ if(FLB_IN_LIB)
205205
FLB_RT_TEST(FLB_OUT_LIB "config_map_opts.c")
206206
FLB_RT_TEST(FLB_OUT_COUNTER "out_counter.c")
207207
FLB_RT_TEST(FLB_OUT_AZURE_KUSTO "out_azure_kusto.c")
208+
FLB_RT_TEST(FLB_OUT_AZURE_BLOB "out_azure_blob.c")
208209
FLB_RT_TEST(FLB_OUT_DATADOG "out_datadog.c")
209210
FLB_RT_TEST(FLB_OUT_SKYWALKING "out_skywalking.c")
210211
FLB_RT_TEST(FLB_OUT_ES "out_elasticsearch.c")

tests/runtime/out_azure_blob.c

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* Fluent Bit
4+
* ==========
5+
* Copyright (C) 2015-2026 The Fluent Bit Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#include <fluent-bit.h>
21+
#include "flb_tests_runtime.h"
22+
23+
/* Test functions */
24+
#ifdef FLB_HAVE_TLS
25+
void flb_test_azure_blob_managed_identity_system(void);
26+
void flb_test_azure_blob_managed_identity_user(void);
27+
void flb_test_azure_blob_service_principal(void);
28+
void flb_test_azure_blob_workload_identity(void);
29+
#endif
30+
void flb_test_azure_blob_shared_key(void);
31+
void flb_test_azure_blob_sas_token(void);
32+
33+
/* Test list */
34+
TEST_LIST = {
35+
#ifdef FLB_HAVE_TLS
36+
{"managed_identity_system", flb_test_azure_blob_managed_identity_system},
37+
{"managed_identity_user", flb_test_azure_blob_managed_identity_user},
38+
{"service_principal", flb_test_azure_blob_service_principal},
39+
{"workload_identity", flb_test_azure_blob_workload_identity},
40+
#endif
41+
{"shared_key", flb_test_azure_blob_shared_key},
42+
{"sas_token", flb_test_azure_blob_sas_token},
43+
{NULL, NULL}
44+
};
45+
46+
#ifdef FLB_HAVE_TLS
47+
/* Test for system-assigned managed identity */
48+
void flb_test_azure_blob_managed_identity_system(void)
49+
{
50+
int ret;
51+
flb_ctx_t *ctx;
52+
int in_ffd;
53+
int out_ffd;
54+
55+
ctx = flb_create();
56+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
57+
58+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
59+
TEST_CHECK(in_ffd >= 0);
60+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
61+
62+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
63+
TEST_CHECK(out_ffd >= 0);
64+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
65+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
66+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
67+
flb_output_set(ctx, out_ffd, "auth_type", "managed_identity", NULL);
68+
flb_output_set(ctx, out_ffd, "client_id", "system", NULL);
69+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
70+
71+
ret = flb_start(ctx);
72+
TEST_CHECK(ret == 0);
73+
74+
flb_stop(ctx);
75+
flb_destroy(ctx);
76+
}
77+
78+
/* Test for user-assigned managed identity */
79+
void flb_test_azure_blob_managed_identity_user(void)
80+
{
81+
int ret;
82+
flb_ctx_t *ctx;
83+
int in_ffd;
84+
int out_ffd;
85+
86+
ctx = flb_create();
87+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
88+
89+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
90+
TEST_CHECK(in_ffd >= 0);
91+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
92+
93+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
94+
TEST_CHECK(out_ffd >= 0);
95+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
96+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
97+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
98+
flb_output_set(ctx, out_ffd, "auth_type", "managed_identity", NULL);
99+
flb_output_set(ctx, out_ffd, "client_id", "00000000-0000-0000-0000-000000000000", NULL);
100+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
101+
102+
ret = flb_start(ctx);
103+
TEST_CHECK(ret == 0);
104+
105+
flb_stop(ctx);
106+
flb_destroy(ctx);
107+
}
108+
109+
/* Test for service principal authentication */
110+
void flb_test_azure_blob_service_principal(void)
111+
{
112+
int ret;
113+
flb_ctx_t *ctx;
114+
int in_ffd;
115+
int out_ffd;
116+
117+
ctx = flb_create();
118+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
119+
120+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
121+
TEST_CHECK(in_ffd >= 0);
122+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
123+
124+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
125+
TEST_CHECK(out_ffd >= 0);
126+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
127+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
128+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
129+
flb_output_set(ctx, out_ffd, "auth_type", "service_principal", NULL);
130+
flb_output_set(ctx, out_ffd, "tenant_id", "test-tenant-id", NULL);
131+
flb_output_set(ctx, out_ffd, "client_id", "test-client-id", NULL);
132+
flb_output_set(ctx, out_ffd, "client_secret", "test-client-secret", NULL);
133+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
134+
135+
ret = flb_start(ctx);
136+
TEST_CHECK(ret == 0);
137+
138+
flb_stop(ctx);
139+
flb_destroy(ctx);
140+
}
141+
142+
/* Test for workload identity authentication */
143+
void flb_test_azure_blob_workload_identity(void)
144+
{
145+
int ret;
146+
flb_ctx_t *ctx;
147+
int in_ffd;
148+
int out_ffd;
149+
150+
ctx = flb_create();
151+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
152+
153+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
154+
TEST_CHECK(in_ffd >= 0);
155+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
156+
157+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
158+
TEST_CHECK(out_ffd >= 0);
159+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
160+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
161+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
162+
flb_output_set(ctx, out_ffd, "auth_type", "workload_identity", NULL);
163+
flb_output_set(ctx, out_ffd, "tenant_id", "test-tenant-id", NULL);
164+
flb_output_set(ctx, out_ffd, "client_id", "test-client-id", NULL);
165+
flb_output_set(ctx, out_ffd, "workload_identity_token_file", "/tmp/test-token", NULL);
166+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
167+
168+
ret = flb_start(ctx);
169+
TEST_CHECK(ret == 0);
170+
171+
flb_stop(ctx);
172+
flb_destroy(ctx);
173+
}
174+
#endif /* FLB_HAVE_TLS */
175+
176+
/* Test for shared key authentication (existing method) */
177+
void flb_test_azure_blob_shared_key(void)
178+
{
179+
int ret;
180+
flb_ctx_t *ctx;
181+
int in_ffd;
182+
int out_ffd;
183+
184+
ctx = flb_create();
185+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
186+
187+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
188+
TEST_CHECK(in_ffd >= 0);
189+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
190+
191+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
192+
TEST_CHECK(out_ffd >= 0);
193+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
194+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
195+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
196+
flb_output_set(ctx, out_ffd, "auth_type", "key", NULL);
197+
flb_output_set(ctx, out_ffd, "shared_key", "dGVzdGtleQ==", NULL); /* base64 "testkey" */
198+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
199+
200+
ret = flb_start(ctx);
201+
TEST_CHECK(ret == 0);
202+
203+
flb_stop(ctx);
204+
flb_destroy(ctx);
205+
}
206+
207+
/* Test for SAS token authentication (existing method) */
208+
void flb_test_azure_blob_sas_token(void)
209+
{
210+
int ret;
211+
flb_ctx_t *ctx;
212+
int in_ffd;
213+
int out_ffd;
214+
215+
ctx = flb_create();
216+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
217+
218+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
219+
TEST_CHECK(in_ffd >= 0);
220+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
221+
222+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
223+
TEST_CHECK(out_ffd >= 0);
224+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
225+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
226+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
227+
flb_output_set(ctx, out_ffd, "auth_type", "sas", NULL);
228+
flb_output_set(ctx, out_ffd, "sas_token", "sv=2021-01-01&ss=b&srt=sco&sp=rwdlacx&se=2026-01-01T00:00:00Z&st=2025-01-01T00:00:00Z&spr=https&sig=test", NULL);
229+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
230+
231+
ret = flb_start(ctx);
232+
TEST_CHECK(ret == 0);
233+
234+
flb_stop(ctx);
235+
flb_destroy(ctx);
236+
}

0 commit comments

Comments
 (0)