
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
gopkg.in/nowk/go-netmock.v0
http.Client
mocking when you can't control the URL
go get gopkg.in/nowk/go-netmock.v0
You use a http.DefaultClient
mapped interface.
type SomeApi struct {
HTTPClient HTTPClient
}
func (s SomeApi) GetSomeApiRequest() (*http.Response, error) {
return s.HTTPClient.Get("http://example.com")
}
Pass your mock in your tests.
func TestRequest(t *testing.T) {
mock := netmock.NewMock(t)
mock.Expect("GET", "http://example.com").Respond(200, "Hello World!")
api := &SomeApi{mock.HTTPClient}
res, _ := api.GetSomeApiRequest()
if code := res.StatusCode; code != 200 {
t.Errorf("Expected 200, got %d", code)
}
}
mock.Expect("GET", "http://example.com").Respond(200, "Hello World!")
With a regexp
reg := regexp.MustCompile(`http:\/\/example\.com\/foo`)
mock.Expect("GET", reg).Respond(200, "Hello World!")
res, _ := mock.Expect("GET", "http://example.com").Respond(200, `{"foo": "bar"}`)
res.Header.Add("Content-Type", "application/json")
_, mr := mock.Expect("GET", "http://example.com").Respond(200, "Hello World!")
Number of times called
mr.Called(1).Times()
Request Body
mr.Body().Equals("Hello World!")
Request Header
mr.Header("Content-Type").Equals("application/json")
Form values
mr.Form("foo").Equals("bar")
PostForm values
mr.PostForm("baz").Equals("qux")
MIT
FAQs
Unknown package
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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.