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.
gopkg.in/khaiql/dbcleaner.v2
Clean database for testing, inspired by database_cleaner for Ruby. It uses flock syscall under the hood to make sure the test can runs in parallel without racing issues.
go get gopkg.in/khaiql/dbcleaner.v2
import "gopkg.in/khaiql/dbcleaner.v2"
TestSuite
:go get github.com/stretchr/testify
import "gopkg.in/khaiql/dbcleaner.v1"
During running test suites, there might be deadlock when 2 suites try to acquire the same table. Dbcleaner tries to mitigate the issue by providing options for retry and panic when the deadlock couldn't be resolved after excessive retries.
type Options struct {
Logger logging.Logger
LockTimeout time.Duration
NumberOfRetry int
RetryInterval time.Duration
}
type Option func(opt *Options)
// SetLogger to an instance of logging.Logger, default to Noop
func SetLogger(logger logging.Logger) Option {
return func(opt *Options) {
opt.Logger = logger
}
}
// SetLockTimeout sets timeout for locking operation, default to 10 seconds
func SetLockTimeout(d time.Duration) Option {
return func(opt *Options) {
opt.LockTimeout = d
}
}
// SetNumberOfRetry sets max retries for acquire the table, default to 5 times
func SetNumberOfRetry(t int) Option {
return func(opt *Options) {
opt.NumberOfRetry = t
}
}
// SetRetryInterval sets sleep duration between each retry, default to 10 seconds
func SetRetryInterval(d time.Duration) Option {
return func(opt *Options) {
opt.RetryInterval = d
}
}
// SetLockFileDir sets directory for lock files
func SetLockFileDir(dir string) Option {
return func(opt *Options) {
opt.LockFileDir = dir
}
}
cleaner := dbcleaner.New(SetNumberOfRetry(10), SetLockTimeout(5*time.Second))
import (
"testing"
"gopkg.in/khaiql/dbcleaner.v2"
"gopkg.in/khaiql/dbcleaner.v2/engine"
"github.com/stretchr/testify/suite"
)
var Cleaner = dbcleaner.New()
type ExampleSuite struct {
suite.Suite
}
func (suite *ExampleSuite) SetupSuite() {
// Init and set mysql cleanup engine
mysql := engine.NewMySQLEngine("YOUR_DB_DSN")
Cleaner.SetEngine(mysql)
}
func (suite *ExampleSuite) SetupTest() {
Cleaner.Acquire("users")
}
func (suite *ExampleSuite) TearDownTest() {
Cleaner.Clean("users")
}
func (suite *ExampleSuite) TestSomething() {
// Have some meaningful test
suite.Equal(true, true)
}
func TestRunSuite(t *testing.T) {
suite.Run(t, new(ExampleSuite))
}
Basically all drivers supported by database/sql
package are also supported by
dbcleaner
. Check list of drivers:
https://github.com/golang/go/wiki/SQLDrivers
For custom driver, implement your own engine.Engine
interface and call SetEngine
on dbcleaner.Cleaner
instance.
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’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.