Skip to content

Commit

Permalink
[nodejs] fix tag_value endpoint and enable APISec path_params tests (#…
Browse files Browse the repository at this point in the history
…3251)

Co-authored-by: Carles Capell <107924659+CarlesDD@users.noreply.github.com>
  • Loading branch information
simon-id and CarlesDD authored Oct 16, 2024
1 parent 180efa8 commit 9f29fe6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion manifests/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ tests/:
nextjs: *ref_5_3_0
Test_Schema_Request_Headers: *ref_4_21_0
Test_Schema_Request_Json_Body: *ref_4_21_0
Test_Schema_Request_Path_Parameters: missing_feature (path_params not supported yet)
Test_Schema_Request_Path_Parameters:
'*': *ref_4_21_0
nextjs: missing_feature
Test_Schema_Request_Query_Parameters: *ref_4_21_0
Test_Schema_Response_Body:
'*': *ref_5_3_0
Expand Down
9 changes: 5 additions & 4 deletions utils/build/docker/nodejs/express4-typescript/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,17 @@ app.get('/load_dependency', (req: Request, res: Response) => {
res.send("Loaded a dependency")
});

app.all('/tag_value/:tag/:status', (req: Request, res: Response) => {
require('dd-trace/packages/dd-trace/src/plugins/util/web').root(req).setTag('appsec.events.system_tests_appsec_event.value', req.params.tag);
app.all('/tag_value/:tag_value/:status_code', (req: Request, res: Response) => {
require('dd-trace/packages/dd-trace/src/plugins/util/web')
.root(req).setTag('appsec.events.system_tests_appsec_event.value', req.params.tag_value);

for (const [k, v] of Object.entries(req.query)) {
res.set(k, v && v.toString());
}

res.status(parseInt(req.params.status) || 200)
res.status(parseInt(req.params.status_code) || 200)

if (req.params?.tag?.startsWith?.('payload_in_response_body') && req.method === 'POST') {
if (req.params.tag_value.startsWith?.('payload_in_response_body') && req.method === 'POST') {
res.send({ payload: req.body });
} else {
res.send('Value tagged');
Expand Down
8 changes: 4 additions & 4 deletions utils/build/docker/nodejs/express4/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,17 @@ app.get('/load_dependency', (req, res) => {
res.send('Loaded a dependency')
})

app.all('/tag_value/:tag/:status', (req, res) => {
app.all('/tag_value/:tag_value/:status_code', (req, res) => {
require('dd-trace/packages/dd-trace/src/plugins/util/web')
.root(req).setTag('appsec.events.system_tests_appsec_event.value', req.params.tag)
.root(req).setTag('appsec.events.system_tests_appsec_event.value', req.params.tag_value)

for (const [k, v] of Object.entries(req.query)) {
res.set(k, v)
}

res.status(req.params.status || 200)
res.status(req.params.status_code || 200)

if (req.params?.tag?.startsWith?.('payload_in_response_body') && req.method === 'POST') {
if (req.params.tag_value.startsWith?.('payload_in_response_body') && req.method === 'POST') {
res.send({ payload: req.body })
} else {
res.send('Value tagged')
Expand Down

0 comments on commit 9f29fe6

Please sign in to comment.