
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@netlify/nock-udp
Advanced tools
Mock outgoing UDP requests. Useful for testing purposes mostly. Based on node-mock-udp.
npm install @netlify/nock-udp
const { Buffer } = require('buffer')
const { intercept, cleanAll } = require('@netlify/nock-udp')
const buffer = Buffer.from('test')
const host = 'localhost'
const port = '1234'
// const opts = {
// persist: false, // Persist the interception for more than one message, defaults to false
// startIntercept: true // Start overriding Socket.prototype.send, defaults to true
// allowUnknown: false // If `startIntercept = true` allow messages to addresses which aren't intercepted, defaults to false
// }
const opts = {}
const scope = intercept(`${host}:${port}`, opts)
console.log(scope.used)
// false
const client = createSocket('udp4')
client.send(buffer, 0, buffer.length, port, host)
console.log(scope.used)
// true
console.log(scope.buffers[0].toString())
// test
// stop intercepting this address
scope.clean()
// clean all the interceptions and restore the original Socket.prototype.send
cleanAll()
const { Buffer } = require('buffer')
const { restoreSocketSend, interceptSocketSend, isMocked } = require('@netlify/nock-udp')
// check if Socket.prototype.send is currently overridden
console.log(isMocked())
// false
// override Socket.prototype.send with our custom method and start using the interceptors (used by `intercept` if `startIntercept = true`)
// optionally allow for requests to addresses which are not intercepted
interceptSocketSend({ allowUnknown: false })
console.log(isMocked())
// true
// restore the original Socket.prototype.send while keeping the current interceptors state
restoreSocketSend()
console.log(isMocked())
// false
Please see CONTRIBUTING.md for instructions on how to set up and work on this repository. Thanks for contributing!
FAQs
Here to mock your UDP packets
The npm package @netlify/nock-udp receives a total of 30 weekly downloads. As such, @netlify/nock-udp popularity was classified as not popular.
We found that @netlify/nock-udp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 16 open source maintainers 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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.