Skip to content

Commit fa66b22

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 ba0f8b2 commit fa66b22

File tree

2 files changed

+231
-0
lines changed

2 files changed

+231
-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: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
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+
void flb_test_azure_blob_managed_identity_system(void);
25+
void flb_test_azure_blob_managed_identity_user(void);
26+
void flb_test_azure_blob_service_principal(void);
27+
void flb_test_azure_blob_workload_identity(void);
28+
void flb_test_azure_blob_shared_key(void);
29+
void flb_test_azure_blob_sas_token(void);
30+
31+
/* Test list */
32+
TEST_LIST = {
33+
{"managed_identity_system", flb_test_azure_blob_managed_identity_system},
34+
{"managed_identity_user", flb_test_azure_blob_managed_identity_user},
35+
{"service_principal", flb_test_azure_blob_service_principal},
36+
{"workload_identity", flb_test_azure_blob_workload_identity},
37+
{"shared_key", flb_test_azure_blob_shared_key},
38+
{"sas_token", flb_test_azure_blob_sas_token},
39+
{NULL, NULL}
40+
};
41+
42+
/* Test for system-assigned managed identity */
43+
void flb_test_azure_blob_managed_identity_system(void)
44+
{
45+
int ret;
46+
flb_ctx_t *ctx;
47+
int in_ffd;
48+
int out_ffd;
49+
50+
ctx = flb_create();
51+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
52+
53+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
54+
TEST_CHECK(in_ffd >= 0);
55+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
56+
57+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
58+
TEST_CHECK(out_ffd >= 0);
59+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
60+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
61+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
62+
flb_output_set(ctx, out_ffd, "auth_type", "managed_identity", NULL);
63+
flb_output_set(ctx, out_ffd, "client_id", "system", NULL);
64+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
65+
66+
ret = flb_start(ctx);
67+
TEST_CHECK(ret == 0);
68+
69+
flb_stop(ctx);
70+
flb_destroy(ctx);
71+
}
72+
73+
/* Test for user-assigned managed identity */
74+
void flb_test_azure_blob_managed_identity_user(void)
75+
{
76+
int ret;
77+
flb_ctx_t *ctx;
78+
int in_ffd;
79+
int out_ffd;
80+
81+
ctx = flb_create();
82+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
83+
84+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
85+
TEST_CHECK(in_ffd >= 0);
86+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
87+
88+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
89+
TEST_CHECK(out_ffd >= 0);
90+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
91+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
92+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
93+
flb_output_set(ctx, out_ffd, "auth_type", "managed_identity", NULL);
94+
flb_output_set(ctx, out_ffd, "client_id", "00000000-0000-0000-0000-000000000000", NULL);
95+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
96+
97+
ret = flb_start(ctx);
98+
TEST_CHECK(ret == 0);
99+
100+
flb_stop(ctx);
101+
flb_destroy(ctx);
102+
}
103+
104+
/* Test for service principal authentication */
105+
void flb_test_azure_blob_service_principal(void)
106+
{
107+
int ret;
108+
flb_ctx_t *ctx;
109+
int in_ffd;
110+
int out_ffd;
111+
112+
ctx = flb_create();
113+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
114+
115+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
116+
TEST_CHECK(in_ffd >= 0);
117+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
118+
119+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
120+
TEST_CHECK(out_ffd >= 0);
121+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
122+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
123+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
124+
flb_output_set(ctx, out_ffd, "auth_type", "service_principal", NULL);
125+
flb_output_set(ctx, out_ffd, "tenant_id", "test-tenant-id", NULL);
126+
flb_output_set(ctx, out_ffd, "client_id", "test-client-id", NULL);
127+
flb_output_set(ctx, out_ffd, "client_secret", "test-client-secret", NULL);
128+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
129+
130+
ret = flb_start(ctx);
131+
TEST_CHECK(ret == 0);
132+
133+
flb_stop(ctx);
134+
flb_destroy(ctx);
135+
}
136+
137+
/* Test for workload identity authentication */
138+
void flb_test_azure_blob_workload_identity(void)
139+
{
140+
int ret;
141+
flb_ctx_t *ctx;
142+
int in_ffd;
143+
int out_ffd;
144+
145+
ctx = flb_create();
146+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
147+
148+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
149+
TEST_CHECK(in_ffd >= 0);
150+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
151+
152+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
153+
TEST_CHECK(out_ffd >= 0);
154+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
155+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
156+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
157+
flb_output_set(ctx, out_ffd, "auth_type", "workload_identity", NULL);
158+
flb_output_set(ctx, out_ffd, "tenant_id", "test-tenant-id", NULL);
159+
flb_output_set(ctx, out_ffd, "client_id", "test-client-id", NULL);
160+
flb_output_set(ctx, out_ffd, "workload_identity_token_file", "/tmp/test-token", NULL);
161+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
162+
163+
ret = flb_start(ctx);
164+
TEST_CHECK(ret == 0);
165+
166+
flb_stop(ctx);
167+
flb_destroy(ctx);
168+
}
169+
170+
/* Test for shared key authentication (existing method) */
171+
void flb_test_azure_blob_shared_key(void)
172+
{
173+
int ret;
174+
flb_ctx_t *ctx;
175+
int in_ffd;
176+
int out_ffd;
177+
178+
ctx = flb_create();
179+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
180+
181+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
182+
TEST_CHECK(in_ffd >= 0);
183+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
184+
185+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
186+
TEST_CHECK(out_ffd >= 0);
187+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
188+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
189+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
190+
flb_output_set(ctx, out_ffd, "auth_type", "key", NULL);
191+
flb_output_set(ctx, out_ffd, "shared_key", "dGVzdGtleQ==", NULL); /* base64 "testkey" */
192+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
193+
194+
ret = flb_start(ctx);
195+
TEST_CHECK(ret == 0);
196+
197+
flb_stop(ctx);
198+
flb_destroy(ctx);
199+
}
200+
201+
/* Test for SAS token authentication (existing method) */
202+
void flb_test_azure_blob_sas_token(void)
203+
{
204+
int ret;
205+
flb_ctx_t *ctx;
206+
int in_ffd;
207+
int out_ffd;
208+
209+
ctx = flb_create();
210+
flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "error", NULL);
211+
212+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
213+
TEST_CHECK(in_ffd >= 0);
214+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
215+
216+
out_ffd = flb_output(ctx, (char *) "azure_blob", NULL);
217+
TEST_CHECK(out_ffd >= 0);
218+
flb_output_set(ctx, out_ffd, "match", "test", NULL);
219+
flb_output_set(ctx, out_ffd, "account_name", "testaccount", NULL);
220+
flb_output_set(ctx, out_ffd, "container_name", "testcontainer", NULL);
221+
flb_output_set(ctx, out_ffd, "auth_type", "sas", NULL);
222+
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);
223+
flb_output_set(ctx, out_ffd, "auto_create_container", "off", NULL);
224+
225+
ret = flb_start(ctx);
226+
TEST_CHECK(ret == 0);
227+
228+
flb_stop(ctx);
229+
flb_destroy(ctx);
230+
}

0 commit comments

Comments
 (0)