Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/A7103/assert
package assert_test
import (
"testing"
"github.com/go-repo/assert"
)
type StructA struct {
A int64
B string
}
func TestEqual(t *testing.T) {
assert.Equal(t,
&StructA{
A: 1,
B: "str",
},
&StructA{
A: 2,
B: "str",
},
)
}
Run the test and output:
=== RUN TestEqual
main_test.go:15: Actual (-) and expected (+) are not equal:
&assert_test.StructA{
- A: int64(1)
+ A: int64(2)
}
--- FAIL: TestEqual (0.00s)
FAIL
Useful for table test, you can test all cases even if one of them is failed, for example:
package errorassert_test
import (
"testing"
"github.com/go-repo/assert/errorassert"
)
type StructA struct {
A int64
B string
}
func TestEqual(t *testing.T) {
tests := []struct {
name string
actual interface{}
expected interface{}
}{
{
name: "equal",
actual: "123str",
expected: "123str",
},
{
name: "not equal for int type",
actual: 1,
expected: 2,
},
{
name: "not equal for struct type",
actual: StructA{B: "abc"},
expected: StructA{B: "def"},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
errorassert.Equal(t, test.actual, test.expected)
})
}
}
Run the test and output:
=== RUN TestEqual
=== RUN TestEqual/equal
=== RUN TestEqual/not_equal_for_int_type
main_test.go:40: Actual (-) and expected (+) are not equal:
- int(1)
+ int(2)
=== RUN TestEqual/not_equal_for_struct_type
main_test.go:40: Actual (-) and expected (+) are not equal:
errorassert_test.StructA{
- B: string("abc")
+ B: string("def")
}
--- FAIL: TestEqual (0.00s)
--- PASS: TestEqual/equal (0.00s)
--- FAIL: TestEqual/not_equal_for_int_type (0.00s)
--- FAIL: TestEqual/not_equal_for_struct_type (0.00s)
FAIL
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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.