TSG-15457: 通过流标签获取subscriber_id,将结构体强转为字符串导致proxy不生效

This commit is contained in:
liuxueli
2023-06-12 16:19:09 +08:00
parent 03b39fc314
commit 1d47ee19ad
3 changed files with 370 additions and 184 deletions

View File

@@ -134,25 +134,25 @@ struct bridge_info
stream_bridge_free_cb_t *free_cb;
stream_bridge_sync_cb_t *sync_cb;
};
extern struct bridge_info g_tm_bridge_para[BRIDGE_TYPE_MAX];
extern struct bridge_info g_tsg_bridge_para[BRIDGE_TYPE_MAX];
TEST(TSG_Bridge, SyncAppIdentifyResultSync)
TEST(TSGBridge, SyncAppIdentifyResultSync)
{
const struct streaminfo a_stream = {0};
int SyncAppIdentifyResult_test_data_before = 10;
stream_bridge_sync_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SYNC_APP_IDENTIFY_RESULT].id, (void *)&SyncAppIdentifyResult_test_data_before);
stream_bridge_sync_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SYNC_APP_IDENTIFY_RESULT].id, (void *)&SyncAppIdentifyResult_test_data_before);
EXPECT_EQ(10, SyncAppIdentifyResult_test_data_after);
SyncAppIdentifyResult_test_data_after = 0;
}
TEST(TSG_Bridge, RecvConnSketchDataAsync)
TEST(TSGBridge, RecvConnSketchDataAsync)
{
const struct streaminfo a_stream = {0};
struct tsg_conn_sketch_notify_data RecvConnSketchData_test_data_before;
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_RECV_CONN_SKETCH_DATA].id, (void *)&RecvConnSketchData_test_data_before);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_RECV_CONN_SKETCH_DATA].id, (void *)&RecvConnSketchData_test_data_before);
struct tsg_conn_sketch_notify_data *RecvConnSketchData_test_data_after = (struct tsg_conn_sketch_notify_data *)session_conn_sketch_notify_data_get(&a_stream);
EXPECT_EQ(&RecvConnSketchData_test_data_before, RecvConnSketchData_test_data_after);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_RECV_CONN_SKETCH_DATA].id, NULL);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_RECV_CONN_SKETCH_DATA].id, NULL);
}
struct tsg_notify_data notify_data_for_test = {0};
@@ -161,9 +161,9 @@ int send_conn_sketch_data_sync_cb(const struct streaminfo *a_stream, int bridge_
memcpy(&notify_data_for_test, data, sizeof(struct tsg_notify_data));
return 0;
}
TEST(TSG_Bridge, SendConnSketchDataMirrorSync)
TEST(TSGBridge, SendConnSketchDataMirrorSync)
{
stream_bridge_register_data_sync_cb(g_tm_bridge_para[BRIDGE_TYPE_SEND_CONN_SKETCH_DATA].id, send_conn_sketch_data_sync_cb);
stream_bridge_register_data_sync_cb(g_tsg_bridge_para[BRIDGE_TYPE_SEND_CONN_SKETCH_DATA].id, send_conn_sketch_data_sync_cb);
const struct streaminfo a_stream = {0};
struct maat_rule rules = {0};
@@ -176,9 +176,9 @@ TEST(TSG_Bridge, SendConnSketchDataMirrorSync)
memset(&notify_data_for_test, 0, sizeof(struct tsg_notify_data));
}
TEST(TSG_Bridge, SendConnSketchDataCaptureSync)
TEST(TSGBridge, SendConnSketchDataCaptureSync)
{
stream_bridge_register_data_sync_cb(g_tm_bridge_para[BRIDGE_TYPE_SEND_CONN_SKETCH_DATA].id, send_conn_sketch_data_sync_cb);
stream_bridge_register_data_sync_cb(g_tsg_bridge_para[BRIDGE_TYPE_SEND_CONN_SKETCH_DATA].id, send_conn_sketch_data_sync_cb);
const struct streaminfo a_stream = {0};
struct maat_rule rules = {0};
@@ -190,11 +190,11 @@ TEST(TSG_Bridge, SendConnSketchDataCaptureSync)
memset(&notify_data_for_test, 0, sizeof(struct tsg_notify_data));
}
TEST(TSG_Bridge, SessionFlagsSync)
TEST(TSGBridge, SessionFlagsSync)
{
const struct streaminfo a_stream = {0};
int SyncSessionFlags_test_data_before = 20;
stream_bridge_sync_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SYNC_SESSION_FLAGS].id, (void *)&SyncSessionFlags_test_data_before);
stream_bridge_sync_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SYNC_SESSION_FLAGS].id, (void *)&SyncSessionFlags_test_data_before);
EXPECT_EQ(20, SyncSessionFlags_test_data_after);
SyncSessionFlags_test_data_after = 0;
}
@@ -204,15 +204,15 @@ struct session_marker_notify_ctx
uint64_t flags;
char *identify_str;
};
TEST(TSG_Bridge, SessionFlagsAsync)
TEST(TSGBridge, SessionFlagsAsync)
{
const struct streaminfo a_stream = {0};
struct session_marker_notify_ctx sm_notify = {0};
sm_notify.flags = 40;
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_ASYNC_SESSION_FLAGS].id, (void *)&sm_notify);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_ASYNC_SESSION_FLAGS].id, (void *)&sm_notify);
struct session_marker_notify_ctx *test = (struct session_marker_notify_ctx *)session_session_flags_get(&a_stream);
EXPECT_EQ(test->flags, 40);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_ASYNC_SESSION_FLAGS].id, NULL);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_ASYNC_SESSION_FLAGS].id, NULL);
EXPECT_EQ(nullptr, session_session_flags_get(&a_stream));
}
@@ -223,9 +223,9 @@ int session_matched_rules_result_sync_cb(const struct streaminfo *a_stream, int
memcpy(&matched_rules_test_data_after, data, sizeof(struct matched_policy_rules));
return 0;
}
TEST(TSG_Bridge, ShapingResultSync)
TEST(TSGBridge, ShapingResultSync)
{
stream_bridge_register_data_sync_cb(g_tm_bridge_para[BRIDGE_TYPE_SHAPING_RESULT].id, session_matched_rules_result_sync_cb);
stream_bridge_register_data_sync_cb(g_tsg_bridge_para[BRIDGE_TYPE_SHAPING_RESULT].id, session_matched_rules_result_sync_cb);
const struct streaminfo a_stream = {0};
struct matched_policy_rules ShapingResultSync_test_data_before = {0};
ShapingResultSync_test_data_before.n_rules = 1;
@@ -234,7 +234,7 @@ TEST(TSG_Bridge, ShapingResultSync)
memset(&matched_rules_test_data_after, 0, sizeof(struct matched_policy_rules));
}
TEST(TSG_Bridge, ShapingResultAsync)
TEST(TSGBridge, ShapingResultAsync)
{
const struct streaminfo a_stream = {0};
struct matched_policy_rules *rules = (struct matched_policy_rules *)dictator_malloc(a_stream.threadnum, sizeof(struct matched_policy_rules));
@@ -249,9 +249,9 @@ TEST(TSG_Bridge, ShapingResultAsync)
session_matched_rules_async(&a_stream, TSG_SERVICE_SHAPING, NULL);
}
TEST(TSG_Bridge, ServiceChainingResultSync)
TEST(TSGBridge, ServiceChainingResultSync)
{
stream_bridge_register_data_sync_cb(g_tm_bridge_para[BRIDGE_TYPE_SERVICE_CHAINING_RESULT].id, session_matched_rules_result_sync_cb);
stream_bridge_register_data_sync_cb(g_tsg_bridge_para[BRIDGE_TYPE_SERVICE_CHAINING_RESULT].id, session_matched_rules_result_sync_cb);
const struct streaminfo a_stream = {0};
struct matched_policy_rules ServiceChainingResultSync_test_data_before = {0};
ServiceChainingResultSync_test_data_before.n_rules = 2;
@@ -260,7 +260,7 @@ TEST(TSG_Bridge, ServiceChainingResultSync)
memset(&matched_rules_test_data_after, 0, sizeof(struct matched_policy_rules));
}
TEST(TSG_Bridge, ServiceChainingResultAsync)
TEST(TSGBridge, ServiceChainingResultAsync)
{
const struct streaminfo a_stream = {0};
struct matched_policy_rules *rules = (struct matched_policy_rules *)dictator_malloc(a_stream.threadnum, sizeof(struct matched_policy_rules));
@@ -275,9 +275,9 @@ TEST(TSG_Bridge, ServiceChainingResultAsync)
session_matched_rules_async(&a_stream, TSG_SERVICE_CHAINING, NULL);
}
TEST(TSG_Bridge, SecurityResultSync)
TEST(TSGBridge, SecurityResultSync)
{
stream_bridge_register_data_sync_cb(g_tm_bridge_para[BRIDGE_TYPE_SECURITY_RESULT].id, session_matched_rules_result_sync_cb);
stream_bridge_register_data_sync_cb(g_tsg_bridge_para[BRIDGE_TYPE_SECURITY_RESULT].id, session_matched_rules_result_sync_cb);
const struct streaminfo a_stream = {0};
struct matched_policy_rules SecurityResultSync_test_data_before = {0};
SecurityResultSync_test_data_before.n_rules = 3;
@@ -286,7 +286,7 @@ TEST(TSG_Bridge, SecurityResultSync)
memset(&matched_rules_test_data_after, 0, sizeof(struct matched_policy_rules));
}
TEST(TSG_Bridge, SecurityResultAsync)
TEST(TSGBridge, SecurityResultAsync)
{
const struct streaminfo a_stream = {0};
struct matched_policy_rules *rules = (struct matched_policy_rules *)dictator_malloc(a_stream.threadnum, sizeof(struct matched_policy_rules));
@@ -301,9 +301,9 @@ TEST(TSG_Bridge, SecurityResultAsync)
session_matched_rules_async(&a_stream, TSG_SERVICE_SECURITY, NULL);
}
TEST(TSG_Bridge, InterceptResultSync)
TEST(TSGBridge, InterceptResultSync)
{
stream_bridge_register_data_sync_cb(g_tm_bridge_para[BRIDGE_TYPE_INTERCEPT_RESULT].id, session_matched_rules_result_sync_cb);
stream_bridge_register_data_sync_cb(g_tsg_bridge_para[BRIDGE_TYPE_INTERCEPT_RESULT].id, session_matched_rules_result_sync_cb);
const struct streaminfo a_stream = {0};
struct matched_policy_rules InterceptResultSync_test_data_before = {0};
InterceptResultSync_test_data_before.n_rules = 4;
@@ -312,7 +312,7 @@ TEST(TSG_Bridge, InterceptResultSync)
memset(&matched_rules_test_data_after, 0, sizeof(struct matched_policy_rules));
}
TEST(TSG_Bridge, InterceptResultAsync)
TEST(TSGBridge, InterceptResultAsync)
{
const struct streaminfo a_stream = {0};
struct matched_policy_rules *rules = (struct matched_policy_rules *)dictator_malloc(a_stream.threadnum, sizeof(struct matched_policy_rules));
@@ -327,9 +327,9 @@ TEST(TSG_Bridge, InterceptResultAsync)
session_matched_rules_async(&a_stream, TSG_SERVICE_INTERCEPT, NULL);
}
TEST(TSG_Bridge, AppSignatureResultSync)
TEST(TSGBridge, AppSignatureResultSync)
{
stream_bridge_register_data_sync_cb(g_tm_bridge_para[BRIDGE_TYPE_APP_SIGNATURE_RESULT].id, session_matched_rules_result_sync_cb);
stream_bridge_register_data_sync_cb(g_tsg_bridge_para[BRIDGE_TYPE_APP_SIGNATURE_RESULT].id, session_matched_rules_result_sync_cb);
const struct streaminfo a_stream = {0};
struct matched_policy_rules AppSignaturegResultSync_test_data_before = {0};
AppSignaturegResultSync_test_data_before.n_rules = 5;
@@ -338,7 +338,7 @@ TEST(TSG_Bridge, AppSignatureResultSync)
memset(&matched_rules_test_data_after, 0, sizeof(struct matched_policy_rules));
}
TEST(TSG_Bridge, AppSignatureResultAsync)
TEST(TSGBridge, AppSignatureResultAsync)
{
const struct streaminfo a_stream = {0};
struct matched_policy_rules *rules = (struct matched_policy_rules *)dictator_malloc(a_stream.threadnum, sizeof(struct matched_policy_rules));
@@ -355,19 +355,19 @@ TEST(TSG_Bridge, AppSignatureResultAsync)
extern const struct session_runtime_process_context *session_runtime_process_context_new(const struct streaminfo *a_stream);
extern void session_runtime_process_context_free_cb(const struct streaminfo *a_stream, int bridge_id, void *data);
TEST(TSG_Bridge, SessionProcessContextAsync)
TEST(TSGBridge, SessionProcessContextAsync)
{
const struct streaminfo a_stream = {0};
const struct session_runtime_process_context *context = session_runtime_process_context_new(&a_stream);
EXPECT_EQ(session_runtime_process_context_get(&a_stream), context);
EXPECT_EQ(session_runtime_process_context_get(&a_stream), session_runtime_process_context_new(&a_stream));
session_runtime_process_context_free_cb(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)context);
session_runtime_process_context_free_cb(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)context);
session_runtime_process_context_async(&a_stream, NULL);
EXPECT_EQ(nullptr, session_runtime_process_context_get(&a_stream));
}
extern void session_runtime_action_context_free(const struct streaminfo *a_stream, int bridge_id, void *data);
TEST(TSG_Bridge, SessionActionContextAsync)
TEST(TSGBridge, SessionActionContextAsync)
{
const struct streaminfo a_stream = {0};
struct session_runtime_action_context *context = (struct session_runtime_action_context *)session_runtime_action_context_new(&a_stream);
@@ -375,7 +375,7 @@ TEST(TSG_Bridge, SessionActionContextAsync)
EXPECT_EQ(session_runtime_action_context_get(&a_stream), session_runtime_action_context_new(&a_stream));
context->direction = DIR_S2C;
EXPECT_EQ(srt_action_context_get_direction(context), DIR_S2C);
session_runtime_action_context_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].id, (void *)context);
session_runtime_action_context_free(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].id, (void *)context);
session_runtime_action_context_async(&a_stream, NULL);
EXPECT_EQ(nullptr, session_runtime_action_context_get(&a_stream));
}
@@ -391,7 +391,7 @@ static void tsg_bridge_test_init_process_ctx(const struct streaminfo *a_stream,
memcpy(process_ctx->http_url, "thisishttp_url", strlen("thisishttp_url"));
}
TEST(TSG_Bridge, ProcessAndActionContextAsync)
TEST(TSGBridge, ProcessAndActionContextAsync)
{
const struct streaminfo a_stream = {0};
struct session_runtime_action_context *action_ctx = (struct session_runtime_action_context *)session_runtime_action_context_new(&a_stream);
@@ -402,8 +402,8 @@ TEST(TSG_Bridge, ProcessAndActionContextAsync)
struct session_runtime_process_context *process_test = (struct session_runtime_process_context *)session_runtime_process_context_get(&a_stream);
EXPECT_STREQ(process_test->domain, "thisisdomain");
EXPECT_STREQ(process_test->http_url, "thisishttp_url");
session_runtime_action_context_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].id, (void *)action_ctx);
session_runtime_process_context_free_cb(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)process_test);
session_runtime_action_context_free(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SESSION_ACTION_CONTEXT].id, (void *)action_ctx);
session_runtime_process_context_free_cb(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SESSION_PROCESS_CONTEXT].id, (void *)process_test);
session_runtime_action_context_async(&a_stream, NULL);
EXPECT_EQ(nullptr, session_runtime_action_context_get(&a_stream));
session_runtime_process_context_async(&a_stream, NULL);
@@ -411,7 +411,7 @@ TEST(TSG_Bridge, ProcessAndActionContextAsync)
}
extern void session_gather_app_results_free(const struct streaminfo *a_stream, int bridge_id, void *data);
TEST(TSG_Bridge, GatherAppResultAsync)
TEST(TSGBridge, GatherAppResultAsync)
{
const struct streaminfo a_stream = {0};
struct gather_app_result *gather_result_in = (struct gather_app_result *)dictator_malloc(a_stream.threadnum, sizeof(struct gather_app_result));
@@ -442,7 +442,7 @@ TEST(TSG_Bridge, GatherAppResultAsync)
EXPECT_EQ(nullptr, gather_result_out->qm_engine);
EXPECT_EQ(nullptr, gather_result_out->user_define);
session_gather_app_results_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_GATHER_APP_RESULT].id, (void *)gather_result_out);
session_gather_app_results_free(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_GATHER_APP_RESULT].id, (void *)gather_result_out);
session_gather_app_results_async(&a_stream, NULL);
EXPECT_EQ(nullptr, session_gather_app_results_get(&a_stream));
@@ -476,7 +476,7 @@ static void tsg_bridge_test_init_attribute(const struct streaminfo *a_stream, st
}
extern void session_runtime_attribute_free(const struct streaminfo *a_stream, int bridge_id, void *data);
TEST(TSG_Bridge, SessionAttributeAsync)
TEST(TSGBridge, SessionAttributeAsync)
{
const struct streaminfo a_stream = {0};
struct session_runtime_attribute *attribute = (struct session_runtime_attribute *)session_runtime_attribute_new(&a_stream);
@@ -495,98 +495,98 @@ TEST(TSG_Bridge, SessionAttributeAsync)
EXPECT_EQ(attribute_test->user_info->ref_cnt, 9);
EXPECT_STREQ(attribute->ja3_fingerprint, "thisisja3_fingerprint");
EXPECT_EQ(attribute_test->proxy_tcp_attr->tcp_seq, 10);
session_runtime_attribute_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_ATTRIBUTE].id, (void *)attribute);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_SESSION_ATTRIBUTE].id, NULL);
session_runtime_attribute_free(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SESSION_ATTRIBUTE].id, (void *)attribute);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SESSION_ATTRIBUTE].id, NULL);
EXPECT_EQ(nullptr, session_runtime_attribute_get(&a_stream));
}
TEST(TSG_Bridge, MacLinkinfoAsync)
TEST(TSGBridge, MacLinkinfoAsync)
{
const struct streaminfo a_stream = {0};
char linkinfo[10];
linkinfo[0] = 0x01;
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_MAC_LINKINFO].id, (void *)linkinfo);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_MAC_LINKINFO].id, (void *)linkinfo);
char *test = (char *)session_mac_linkinfo_get(&a_stream);
EXPECT_EQ(test[0], 0x01);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_MAC_LINKINFO].id, NULL);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_MAC_LINKINFO].id, NULL);
EXPECT_EQ(nullptr, session_mac_linkinfo_get(&a_stream));
}
TEST(TSG_Bridge, NatC2sLinkinfoAsync)
TEST(TSGBridge, NatC2sLinkinfoAsync)
{
const struct streaminfo a_stream = {0};
char linkinfo[10];
linkinfo[0] = 0x02;
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_NAT_C2S_LINKINFO].id, (void *)linkinfo);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_NAT_C2S_LINKINFO].id, (void *)linkinfo);
char *test = (char *)session_nat_c2s_linkinfo_get(&a_stream);
EXPECT_EQ(test[0], 0x02);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_NAT_C2S_LINKINFO].id, NULL);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_NAT_C2S_LINKINFO].id, NULL);
EXPECT_EQ(nullptr, session_nat_c2s_linkinfo_get(&a_stream));
}
TEST(TSG_Bridge, NatS2cLinkinfoAsync)
TEST(TSGBridge, NatS2cLinkinfoAsync)
{
const struct streaminfo a_stream = {0};
char linkinfo[10];
linkinfo[0] = 0x03;
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_NAT_S2C_LINKINFO].id, (void *)linkinfo);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_NAT_S2C_LINKINFO].id, (void *)linkinfo);
char *test = (char *)session_nat_s2c_linkinfo_get(&a_stream);
EXPECT_EQ(test[0], 0x03);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_NAT_S2C_LINKINFO].id, NULL);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_NAT_S2C_LINKINFO].id, NULL);
EXPECT_EQ(nullptr, session_nat_s2c_linkinfo_get(&a_stream));
}
TEST(TSG_Bridge, AppLuaResultAsync)
TEST(TSGBridge, AppLuaResultAsync)
{
const struct streaminfo a_stream = {0};
struct user_defined_attribute uda_label = {0};
uda_label.n_akv = 4;
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_APP_LUA_RESULT].id, (void *)&uda_label);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_APP_LUA_RESULT].id, (void *)&uda_label);
struct user_defined_attribute *test = (struct user_defined_attribute *)session_lua_user_defined_attribute_get(&a_stream);
EXPECT_EQ(test->n_akv, 4);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_APP_LUA_RESULT].id, NULL);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_APP_LUA_RESULT].id, NULL);
EXPECT_EQ(nullptr, session_lua_user_defined_attribute_get(&a_stream));
}
TEST(TSG_Bridge, BusinessS3FilenameAsync)
TEST(TSGBridge, BusinessS3FilenameAsync)
{
const struct streaminfo a_stream = {0};
struct business_notify_data bnd_label;
memset(&bnd_label, 0, sizeof(struct business_notify_data));
bnd_label.proto = PROTO_HTTP;
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_BUSINESS_S3_FILENAME].id, (void *)&bnd_label);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_BUSINESS_S3_FILENAME].id, (void *)&bnd_label);
struct business_notify_data *test = (struct business_notify_data *)session_business_data_get(&a_stream);
EXPECT_EQ(test->proto, PROTO_HTTP);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_BUSINESS_S3_FILENAME].id, NULL);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_BUSINESS_S3_FILENAME].id, NULL);
EXPECT_EQ(nullptr, session_business_data_get(&a_stream));
}
TEST(TSG_Bridge, AppBehaviorResultAsync)
TEST(TSGBridge, AppBehaviorResultAsync)
{
const struct streaminfo a_stream = {0};
char stream_behavior[10];
struct application_behavior behavior_result = {0};
behavior_result.stream_behavior = stream_behavior;
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_APP_BEHAVIOR_RESULT].id, (void *)&behavior_result);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_APP_BEHAVIOR_RESULT].id, (void *)&behavior_result);
struct application_behavior *test = (struct application_behavior *)session_application_behavior_get(&a_stream);
EXPECT_EQ(test->stream_behavior, stream_behavior);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_APP_BEHAVIOR_RESULT].id, NULL);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_APP_BEHAVIOR_RESULT].id, NULL);
EXPECT_EQ(nullptr, session_application_behavior_get(&a_stream));
}
TEST(TSG_Bridge, PolicyActionParaExecResultAsync)
TEST(TSGBridge, PolicyActionParaExecResultAsync)
{
const struct streaminfo a_stream = {0};
struct tsg_notify_execution_result execution_result = {0};
execution_result.capture_result_cnt = 20;
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_POLICY_ACTION_PARA_EXEC_RESULT].id, (void *)&execution_result);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_POLICY_ACTION_PARA_EXEC_RESULT].id, (void *)&execution_result);
struct tsg_notify_execution_result *test = (struct tsg_notify_execution_result *)session_mirrored_and_capture_packets_exec_result_get(&a_stream);
EXPECT_EQ(test->capture_result_cnt, 20);
stream_bridge_async_data_put(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_POLICY_ACTION_PARA_EXEC_RESULT].id, NULL);
stream_bridge_async_data_put(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_POLICY_ACTION_PARA_EXEC_RESULT].id, NULL);
EXPECT_EQ(nullptr, session_mirrored_and_capture_packets_exec_result_get(&a_stream));
}
TEST(TSG_Bridge, SegmentIdsAsync)
TEST(TSGBridge, SegmentIdsAsync)
{
const struct streaminfo a_stream = {0};
struct segment_id_list segment_ids = {0};
@@ -618,7 +618,7 @@ static void tsg_bridge_test_init_proxy(const struct streaminfo *a_stream, struct
memcpy(proxy->ssl_upstream_version, "thisisssl_upstream_version", strlen("thisisssl_upstream_version"));
}
extern void session_proxy_log_update_free(const struct streaminfo *a_stream, int bridge_id, void *data);
TEST(TSG_Bridge, LogUpdateProxyAsync)
TEST(TSGBridge, LogUpdateProxyAsync)
{
const struct streaminfo a_stream = {0};
struct proxy_log_update *proxy = (struct proxy_log_update *)dictator_malloc(a_stream.threadnum, sizeof(struct proxy_log_update));
@@ -630,12 +630,12 @@ TEST(TSG_Bridge, LogUpdateProxyAsync)
EXPECT_STREQ(test->ssl_passthrough_reason, "thisisssl_passthrough_reason");
EXPECT_STREQ(test->ssl_downstream_version, "thisisssl_downstream_version");
EXPECT_STREQ(test->ssl_upstream_version, "thisisssl_upstream_version");
session_proxy_log_update_free(&a_stream, g_tm_bridge_para[BRIDGE_TYPE_LOG_UPDATE_PROXY].id, test);
session_proxy_log_update_free(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_LOG_UPDATE_PROXY].id, test);
session_log_update_data_put(&a_stream, TSG_SERVICE_INTERCEPT, NULL);
EXPECT_EQ(nullptr, session_log_update_data_get(&a_stream, TSG_SERVICE_INTERCEPT));
}
TEST(TSG_Bridge, LogUpdateSceAsync)
TEST(TSGBridge, LogUpdateSceAsync)
{
const struct streaminfo a_stream = {0};
struct sce_log_update sce = {0};
@@ -647,7 +647,7 @@ TEST(TSG_Bridge, LogUpdateSceAsync)
EXPECT_EQ(nullptr, session_log_update_data_get(&a_stream, TSG_SERVICE_CHAINING));
}
TEST(TSG_Bridge, LogUpdateShaperAsync)
TEST(TSGBridge, LogUpdateShaperAsync)
{
const struct streaminfo a_stream = {0};
struct shaper_log_update shaper = {0};
@@ -659,6 +659,193 @@ TEST(TSG_Bridge, LogUpdateShaperAsync)
EXPECT_EQ(nullptr, session_log_update_data_get(&a_stream, TSG_SERVICE_SHAPING));
}
TEST(TSGBridge, SessionSessionRuntimeProcessContext)
{
}
TEST(TSGBridge, SessionSessionRuntimeActionContext)
{
}
extern int session_async_bridge_set_data(const struct streaminfo * a_stream, int bridge_id, void * data);
extern void session_runtime_attribute_free(const struct streaminfo * a_stream, int bridge_id, void * data);
TEST(TSGBridge, SessionSessionRuntimeAttributeTSG15457)
{
const struct streaminfo a_stream = {0};
struct session_runtime_attribute *srt_attribute = (struct session_runtime_attribute *)session_runtime_attribute_new(&a_stream);
srt_attribute->proto=PROTO_SSL;
int length=strlen("30625db44eaf886e65bebc8d1e62f368");
srt_attribute->ja3_fingerprint=(const char *)dictator_malloc(0, length+1);
memset((char *)srt_attribute->ja3_fingerprint, 0, length+1);
memcpy((void *)srt_attribute->ja3_fingerprint, (const void *)"30625db44eaf886e65bebc8d1e62f368", length);
srt_attribute->n_fqdn_category_ids=8;
for(size_t i=0; i<srt_attribute->n_fqdn_category_ids; i++)
{
srt_attribute->fqdn_category_ids[i]=10000+i;
}
srt_attribute->client_asn=(struct asn_info *)dictator_malloc(0, sizeof(struct asn_info));
srt_attribute->client_asn->ref_cnt=1;
srt_attribute->client_asn->asn_id=(char *)"1003";
srt_attribute->client_asn->organization=(char *)"china";
srt_attribute->server_asn=(struct asn_info *)dictator_malloc(0, sizeof(struct asn_info));
srt_attribute->server_asn->ref_cnt=1;
srt_attribute->server_asn->asn_id=(char *)"1004";
srt_attribute->server_asn->organization=(char *)"china";
srt_attribute->client_location=(struct location_info *)dictator_malloc(0, sizeof(struct location_info));
srt_attribute->client_location->ref_cnt=1;
srt_attribute->client_location->country_full=(char *)"china";
srt_attribute->client_location->province_full=(char *)"beijing";
srt_attribute->client_location->city_full=(char *)"west";
srt_attribute->client_location->subdivision_addr=(char *)"yuming road";
srt_attribute->server_location=(struct location_info *)dictator_malloc(0, sizeof(struct location_info));
srt_attribute->server_location->ref_cnt=1;
srt_attribute->server_location->country_full=(char *)"china";
srt_attribute->server_location->province_full=(char *)"shanghai";
srt_attribute->server_location->city_full=(char *)"east";
srt_attribute->server_location->subdivision_addr=(char *)"zhongshan road";
srt_attribute->client_subscribe_id=(struct subscribe_id_info *)dictator_malloc(0, sizeof(struct subscribe_id_info));
srt_attribute->client_subscribe_id->ref_cnt=1;
srt_attribute->client_subscribe_id->subscribe_id=(char *)"zhansan";
srt_attribute->server_subscribe_id=(struct subscribe_id_info *)dictator_malloc(0, sizeof(struct subscribe_id_info));
srt_attribute->server_subscribe_id->ref_cnt=1;
srt_attribute->server_subscribe_id->subscribe_id=(char *)"lisi";
srt_attribute->client_endpoint=(struct tunnel_endpoint *)dictator_malloc(0, sizeof(struct tunnel_endpoint));
srt_attribute->client_endpoint->id=1005;
srt_attribute->client_endpoint->ref_cnt=1;
srt_attribute->client_endpoint->description=(char *)"GTP";
srt_attribute->server_endpoint=(struct tunnel_endpoint *)dictator_malloc(0, sizeof(struct tunnel_endpoint));
srt_attribute->server_endpoint->id=1006;
srt_attribute->server_endpoint->ref_cnt=1;
srt_attribute->server_endpoint->description=(char *)"GTP";
srt_attribute->user_info=(struct umts_user_info *)dictator_malloc(0, sizeof(struct umts_user_info));
srt_attribute->user_info->ref_cnt=1;
srt_attribute->user_info->apn=(char *)"apn.beijing.net";
srt_attribute->user_info->imsi=(char *)"IMSI=123456";
srt_attribute->user_info->imei=(char *)"IMEI=7890";
srt_attribute->user_info->msisdn=(char *)"13500912083";
struct session_runtime_attribute *srt_attribute_out=(struct session_runtime_attribute *)session_runtime_attribute_get(&a_stream);
EXPECT_NE(nullptr, srt_attribute_out);
EXPECT_EQ(PROTO_SSL, srt_attribute_out->proto);
EXPECT_EQ(8, srt_attribute_out->n_fqdn_category_ids);
for(size_t i=0; i<srt_attribute_out->n_fqdn_category_ids; i++)
{
EXPECT_EQ(10000+i, srt_attribute_out->fqdn_category_ids[i]);
}
unsigned int fqdn_category_ids[MAX_CATEGORY_ID_NUM]={0};
size_t n_fqdn_category_ids=srt_attribute_get_category_ids((const struct session_runtime_attribute *)srt_attribute, fqdn_category_ids, MAX_CATEGORY_ID_NUM);
EXPECT_EQ(8, n_fqdn_category_ids);
for(size_t i=0; i<n_fqdn_category_ids; i++)
{
EXPECT_EQ(10000+i, fqdn_category_ids[i]);
}
EXPECT_STREQ("30625db44eaf886e65bebc8d1e62f368", srt_attribute_out->ja3_fingerprint);
EXPECT_STREQ("30625db44eaf886e65bebc8d1e62f368", srt_attribute_get_ja3_fingerprint(srt_attribute_out));
EXPECT_NE(nullptr, srt_attribute_out->client_endpoint);
EXPECT_EQ(1, srt_attribute_out->client_endpoint->ref_cnt);
EXPECT_EQ(1005, srt_attribute_out->client_endpoint->id);
EXPECT_STREQ("GTP", srt_attribute_out->client_endpoint->description);
EXPECT_NE(nullptr, srt_attribute_out->server_endpoint);
EXPECT_EQ(1, srt_attribute_out->server_endpoint->ref_cnt);
EXPECT_EQ(1006, srt_attribute_out->server_endpoint->id);
EXPECT_STREQ("GTP", srt_attribute_out->server_endpoint->description);
EXPECT_NE(nullptr, srt_attribute_out->user_info);
EXPECT_EQ(1, srt_attribute_out->user_info->ref_cnt);
EXPECT_STREQ("apn.beijing.net", srt_attribute_out->user_info->apn);
EXPECT_STREQ("IMSI=123456", srt_attribute_out->user_info->imsi);
EXPECT_STREQ("IMEI=7890", srt_attribute_out->user_info->imei);
EXPECT_STREQ("13500912083", srt_attribute_out->user_info->msisdn);
EXPECT_NE(nullptr, srt_attribute_out->client_asn);
EXPECT_EQ(1, srt_attribute_out->client_asn->ref_cnt);
EXPECT_STREQ("1003", srt_attribute_out->client_asn->asn_id);
EXPECT_STREQ("china", srt_attribute_out->client_asn->organization);
const struct asn_info * c_asn=srt_attribute_get_client_ip_asn((const struct session_runtime_attribute *)srt_attribute_out);
EXPECT_NE(nullptr, c_asn);
EXPECT_EQ(1, c_asn->ref_cnt);
EXPECT_STREQ("1003", c_asn->asn_id);
EXPECT_STREQ("china", c_asn->organization);
EXPECT_NE(nullptr, srt_attribute_out->server_asn);
EXPECT_EQ(1, srt_attribute_out->server_asn->ref_cnt);
EXPECT_STREQ("1004", srt_attribute_out->server_asn->asn_id);
EXPECT_STREQ("china", srt_attribute_out->server_asn->organization);
const struct asn_info * s_asn=srt_attribute_get_server_ip_asn((const struct session_runtime_attribute *)srt_attribute_out);
EXPECT_NE(nullptr, s_asn);
EXPECT_EQ(1, s_asn->ref_cnt);
EXPECT_STREQ("1004", s_asn->asn_id);
EXPECT_STREQ("china", s_asn->organization);
EXPECT_NE(nullptr, srt_attribute_out->client_location);
EXPECT_EQ(1, srt_attribute_out->client_location->ref_cnt);
EXPECT_STREQ("china", srt_attribute_out->client_location->country_full);
EXPECT_STREQ("beijing", srt_attribute_out->client_location->province_full);
EXPECT_STREQ("west", srt_attribute_out->client_location->city_full);
EXPECT_STREQ("yuming road", srt_attribute_out->client_location->subdivision_addr);
const struct location_info *c_location=srt_attribute_get_client_ip_location((const struct session_runtime_attribute *)srt_attribute_out);
EXPECT_NE(nullptr, c_location);
EXPECT_EQ(1, c_location->ref_cnt);
EXPECT_STREQ("china", c_location->country_full);
EXPECT_STREQ("beijing", c_location->province_full);
EXPECT_STREQ("west", c_location->city_full);
EXPECT_STREQ("yuming road", c_location->subdivision_addr);
EXPECT_NE(nullptr, srt_attribute_out->server_location);
EXPECT_EQ(1, srt_attribute_out->server_location->ref_cnt);
EXPECT_STREQ("china", srt_attribute_out->server_location->country_full);
EXPECT_STREQ("shanghai", srt_attribute_out->server_location->province_full);
EXPECT_STREQ("east", srt_attribute_out->server_location->city_full);
EXPECT_STREQ("zhongshan road", srt_attribute_out->server_location->subdivision_addr);
const struct location_info *s_location=srt_attribute_get_server_ip_location((const struct session_runtime_attribute *)srt_attribute_out);
EXPECT_NE(nullptr, s_location);
EXPECT_EQ(1, s_location->ref_cnt);
EXPECT_STREQ("china", s_location->country_full);
EXPECT_STREQ("shanghai", s_location->province_full);
EXPECT_STREQ("east", s_location->city_full);
EXPECT_STREQ("zhongshan road", s_location->subdivision_addr);
EXPECT_NE(nullptr, srt_attribute_out->client_subscribe_id);
EXPECT_EQ(1, srt_attribute_out->client_subscribe_id->ref_cnt);
EXPECT_STREQ("zhansan", srt_attribute_out->client_subscribe_id->subscribe_id);
EXPECT_STREQ("zhansan", srt_attribute_get_client_subscriber_id((const struct session_runtime_attribute *)srt_attribute_out));
EXPECT_NE(nullptr, srt_attribute_out->server_subscribe_id);
EXPECT_EQ(1, srt_attribute_out->server_subscribe_id->ref_cnt);
EXPECT_STREQ("lisi", srt_attribute_out->server_subscribe_id->subscribe_id);
EXPECT_STREQ("lisi", srt_attribute_get_server_subscriber_id((const struct session_runtime_attribute *)srt_attribute_out));
session_runtime_attribute_free(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SESSION_ATTRIBUTE].id, (void *)srt_attribute_out);
session_async_bridge_set_data(&a_stream, g_tsg_bridge_para[BRIDGE_TYPE_SESSION_ATTRIBUTE].id, NULL);
EXPECT_EQ(nullptr, session_runtime_attribute_get(&a_stream));
}
int main(int argc, char *argv[])
{
int ret=tsg_bridge_init("tsgconf/main.conf");

View File

@@ -1008,7 +1008,6 @@ TEST(TSGMaster, SessionApplicationMetrics)
}
int main(int argc, char *argv[])
{
TSG_MASTER_INIT();