Skip to content

Commit 34f3514

Browse files
committed
tests: filter_kubernetes: Add a test case for preventing backtracks on regex
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 551ab40 commit 34f3514

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"log":"hello from uat pod","stream":"stdout","time":"2019-04-01T17:58:33.598656444Z"}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"apiVersion": "v1",
3+
"kind": "Pod",
4+
"metadata": {
5+
"name": "uat-myapp-12345",
6+
"namespace": "core",
7+
"uid": "00000000-0000-0000-0000-000000000000"
8+
},
9+
"spec": {
10+
"containers": [
11+
{
12+
"name": "container"
13+
}
14+
]
15+
}
16+
}
17+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[1554141513.598656,{"log":"hello from uat pod","stream":"stdout","kubernetes":{"pod_name":"uat-myapp-12345","namespace_name":"core","container_name":"fluent-bit"}}]

tests/runtime/filter_kubernetes.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int file_to_buf(const char *path, char **out_buf, size_t *out_size)
8686
return -1;
8787
}
8888

89-
buf = flb_malloc(st.st_size);
89+
buf = flb_malloc(st.st_size + 1);
9090
if (!buf) {
9191
flb_errno();
9292
fclose(fp);
@@ -100,6 +100,7 @@ static int file_to_buf(const char *path, char **out_buf, size_t *out_size)
100100
fclose(fp);
101101
return -1;
102102
}
103+
buf[st.st_size] = '\0';
103104

104105
fclose(fp);
105106
*out_buf = buf;
@@ -411,6 +412,17 @@ static void flb_test_core_base_with_namespace_labels_and_annotations()
411412
flb_test_namespace_labels_and_annotations("core_base-with-namespace-labels-and-annotations_fluent-bit", NULL, 1);
412413
}
413414

415+
static void flb_test_kube_short_prefix_uat_podname()
416+
{
417+
kube_test("core/core_uat-myapp-12345_fluent-bit",
418+
KUBE_TAIL,
419+
NULL,
420+
1,
421+
"Use_Tag_For_Meta", "On",
422+
NULL);
423+
}
424+
425+
414426
#define flb_test_owner_references(target, suffix, nExpected) \
415427
kube_test("core/" target, KUBE_TAIL, suffix, nExpected, \
416428
"Labels", "Off", \
@@ -1113,5 +1125,6 @@ TEST_LIST = {
11131125
#ifdef FLB_HAVE_SYSTEMD
11141126
{"kube_systemd_logs", flb_test_systemd_logs},
11151127
#endif
1128+
{"kube_short_prefix_uat_podname", flb_test_kube_short_prefix_uat_podname},
11161129
{NULL, NULL}
11171130
};

0 commit comments

Comments
 (0)