Skip to content

Commit 5dcf253

Browse files
authored
Merge pull request DeusData#2555 from lorenzozanee/fix/js-template-leading-substitution-url
test(pipeline): guard base-URL constant in JS/TS template fetch URLs (DeusData#2540)
2 parents 69b26df + 807a780 commit 5dcf253

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎tests/test_pipeline.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13710,6 +13710,40 @@ TEST(pipeline_native_fetch_classified_as_http_calls) {
1371013710
PASS();
1371113711
}
1371213712

13713+
TEST(pipeline_native_fetch_template_base_url_makes_route) {
13714+
char tmp[256];
13715+
snprintf(tmp, sizeof(tmp), "/tmp/cbm_fetch_template_base_XXXXXX");
13716+
if (!cbm_mkdtemp(tmp)) {
13717+
FAIL("tmpdir");
13718+
}
13719+
13720+
write_temp_file(tmp, "src/api.ts",
13721+
"const BASE_URL = \"http://payments:8080\";\n"
13722+
"export async function createPayment(body: unknown) {\n"
13723+
" return fetch(`${BASE_URL}/v1/payments`, { method: 'POST', body });\n"
13724+
"}\n");
13725+
13726+
char db_path[512];
13727+
snprintf(db_path, sizeof(db_path), "%s/fetch_template_base.db", tmp);
13728+
cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
13729+
ASSERT_NOT_NULL(p);
13730+
ASSERT_EQ(cbm_pipeline_run(p), 0);
13731+
const char *project = cbm_pipeline_project_name(p);
13732+
13733+
cbm_store_t *s = cbm_store_open_path(db_path);
13734+
ASSERT_NOT_NULL(s);
13735+
int http_call_count = cbm_store_count_edges_by_type(s, project, "HTTP_CALLS");
13736+
int matching_route_count =
13737+
http_calls_to_route(s, project, "createPayment", "/v1/payments");
13738+
13739+
cbm_store_close(s);
13740+
cbm_pipeline_free(p);
13741+
th_rmtree(tmp);
13742+
ASSERT_EQ(http_call_count, 1);
13743+
ASSERT_EQ(matching_route_count, 1);
13744+
PASS();
13745+
}
13746+
1371313747
/* #1892: Swift produced no Route node and no HTTP_CALLS edge, because the
1371413748
* Swift grammar has no "arguments" field and the generic lookup therefore read
1371513749
* no call arguments at all. Alamofire/URLSession were already in the service
@@ -28245,6 +28279,7 @@ SUITE(pipeline) {
2824528279
RUN_TEST(pipeline_ts_config_object_url_http_calls_issue2235);
2824628280
RUN_TEST(pipeline_arg_url_rejects_document_file_paths);
2824728281
RUN_TEST(pipeline_native_fetch_classified_as_http_calls);
28282+
RUN_TEST(pipeline_native_fetch_template_base_url_makes_route);
2824828283
RUN_TEST(pipeline_swift_nested_url_makes_route_issue1892);
2824928284
RUN_TEST(pipeline_swift_http_call_makes_route_issue1892);
2825028285
RUN_TEST(pipeline_route_prefix_bridge_is_order_free_and_root_bridges_nothing);

0 commit comments

Comments
 (0)