You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@arextest/arex-node-agent

Package Overview
Dependencies
Maintainers
4
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arextest/arex-node-agent

Arex node agent

latest
npmnpm
Version
0.0.3-beta.29
Version published
Maintainers
4
Created
Source

背景

arex nodejs-agent 实现

环境

  • js
  • monkey patch
  • rollup 打包
  • ctrip npm 部署
  • npm
  • node v18
  • semver

v1 内容

  • 支持入口为express的api
  • 支持http wrap
  • 支持knex db wrap
  • 支持上下文录制回放交互
  • 预留arex api mock

项目结构

  • 模块agent: nodeagent实现逻辑
  • 模块app: 目标应用
  • 模块app/instrumentation.js: 启动中间件

启动node-agent

  • 自定义中间件启动器,按需配置中间件 参考 app/instrumentation node --require ./instrumentation.js index.js
  • 通过arex-runner启动agent
    • 环境变量指定appid,host
    • 平台配置更多中间件
    • app/Dockerfile CMD ["node", "--require", "--require @arextest/arex-node-agent/dist/runner.js", "index.js"]
  • 调试本地agent debug: DEBUG=@arextest:* node --require ./instrumentation_local.js index.js

实现

  • 代理流程
  • 初始化配置
  • 代理一个入口函数 生成上下文context,store
  • 装载入口函数
  • 装载函数调用的io,自定义装载等
    • 加载context
    • 录制/回放
    • 存储/加载
    • 结束
  • 线程结束
    • 卸载patch

案例 - express 请求一个 updateUser 接口

录制操作

  • Express 中间件
    • 创建recordId
    • 调用client.saveRecord
    • 保存updateUser请求的request, response信息
  • service 被测代码逻辑
    • 调用client.saveRecord
    • 保存service.updateUserName 的request, response信息

回放操作

  • Express 中间件
    • 适配回放标识 arex-record-id
    • 创建replayId
    • 调用client.queryRecord
    • 查询并提交updateUser请求的request,response信息
  • service 被测代码逻辑
    • 调用client.queryRecord
    • 查询service.updateUserName 的request, response信息
    • 替换方法的返回结果

发布

v1.0.6

  • 提取静态字段
  • 修复option读取失败 v1.0.10
  • 支持mysql2

参考

  • 演练场 /jagong/node-agent-payload/-/tree/main/node_arex_agent
  • npm 发布流程
  • 申请权限
  • npm login --registry https://registry.npmjs.org
  • npm publish --registry https://registry.npmjs.org --access=public
  • mock http :Nock 或 Sinon 等库来进行请求拦截和模拟响应

FAQs

Package last updated on 03 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts