Files
Miccah ddc81bd7c1 [THOG-162] Implement JDBC verification for select drivers (#792)
* [THOG-162] Implement JDBC verification for select drivers

Also includes integration tests for postgres and mysql via docker. To
run, execute the following (untested what will happen if the docker
images aren't installed):

go test -tags=detectors,integration ./pkg/detectors/jdbc

* Make jdbc regex a bit more strict

* Surface the context to allow the caller to set a timeout
2022-09-21 17:50:48 +02:00

38 lines
765 B
Go

package jdbc
import (
"context"
"errors"
"strings"
_ "github.com/mattn/go-sqlite3"
)
type sqliteJDBC struct {
filename string
params map[string]string
testing bool
}
func (s *sqliteJDBC) ping(ctx context.Context) bool {
if !s.testing {
// sqlite is not a networked database, so we cannot verify
return false
}
return ping(ctx, "sqlite3", s.filename)
}
func parseSqlite(subname string) (jdbc, error) {
filename, params, _ := strings.Cut(subname, "?")
if filename == "" {
return nil, errors.New("empty filename")
}
j := &sqliteJDBC{filename: filename, params: map[string]string{}}
for _, keyVal := range strings.Split(params, "&") {
if key, val, found := strings.Cut(keyVal, "="); found {
j.params[key] = val
}
}
return j, nil
}