
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@ckpack/mock-axios
Advanced tools
Intercept Axios
requests and return Mock
data for testing and development.
(mockDatas: MockConfig[], mockOptions?: MockOptions | undefined) => void
: Mock Axios
mockDatas
: an array, when axios
requests, it will check the corresponding url
, method
, and return the corresponding response
data when it matches.
url
: string | RegExp
type, the url to match, can be a string or a regular expression. When it is a string, it will check whether the url
requested by axios
contains the url
. When it is a regular expression, it will check whether the url
requested by axios
matches the url
.method
: GET
| POST
| PUT
| DELETE
| PATCH
, default is empty to match all types of requeststimeout
: number
type, default value: 300
, unit: ms
, the delay time of returning the resultresponse
: the data object of the returned mockadapter
: custom adapter function, refer to adapter, this function accepts two parameters, one is config
, one is It is the matched mockData
object, and the return value is the data object of response
. Through this parameter, you can define the returned data more freely (such as verifying interface permissions).mockOptions
isUseDefaultAdapter
: Boolean
, defaults to true
, if enabled, requests that are not intercepted will be sent in the default mode of axios
isEffect
: Boolean
, default is true
, with this parameter you can enable mockAxios
in test environment and disable mockAxios
in production environmentisLog
: Boolean
, the default is true
, whether to print the request log of mockAxios
logger
: Function
, replace the default log functionimport { mockAxios } from '@ckpack/mock-axios';
mockAxios([{
url: 'https://test.com/v1/user/1',
response: {
data: {
id: 1,
name: 'admin',
},
},
}], {
isEffect: process.env.NODE_ENV === 'development',
});
(mockDatas: MockConfig[]) => MockConfig[]
: Helper function for constructing mockDatas. This function can be used with the IDE to get type hints
mockDatas
: Same as the mockDatas
parameter of mockAxios
.import { defineConfig } from '@ckpack/mock-axios';
const mockDatas = defineConfig([
{
url: 'https://test.com/v1/user/1',
response: {
data: {
id: 1,
name: 'admin',
},
},
},
]);
// mockAxios.js
import { mockAxios } from '@ckpack/mock-axios';
mockAxios([{
method: 'GET',
url: /https:\/\/test.com\/v1\/user\/\d+/,
response: {
data: [{
id: 1,
name: 'admin',
}],
},
}, {
method: 'POST',
url: 'https://test.com/v1/user/create',
adapter: (axiosConfig) => {
return {
data: axiosConfig.data,
};
},
}]);
in other files
import axios from 'axios';
import './mockAxios.js';
await axios.get('https://test.com/v1/user/1');
// return { data: [{ id: 1, name: 'admin' }] }
await axios.post('https://test.com/v1/user/create', {
id: 1,
name: 'admin',
});
// return { data: { id: 1, name: 'admin' } }
await axios.post('https://test.com/v1/user/create', {
id: 2,
name: 'test',
});
// return { data: { id: 2, name: 'test' } }
FAQs
Mock axios requests for testing and development
The npm package @ckpack/mock-axios receives a total of 0 weekly downloads. As such, @ckpack/mock-axios popularity was classified as not popular.
We found that @ckpack/mock-axios demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.