mirror of
https://github.com/github/codeql.git
synced 2026-01-29 14:23:03 +01:00
Use comment-based tests for GoModExpr
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
| go.mod:10:1:10:44 | go.mod exclude line | codeql-go-tests/gomod | github.com/github/codeql-go | v1.23.1 |
|
||||
| go.mod:23:1:23:42 | go.mod exclude line | codeql-go-tests/gomod | github.com/sirupsen/logrus | v1.4.2 |
|
||||
@@ -1,4 +0,0 @@
|
||||
import go
|
||||
|
||||
from GoModExcludeLine excl
|
||||
select excl, excl.getModulePath(), excl.getPath(), excl.getVersion()
|
||||
@@ -0,0 +1,3 @@
|
||||
missingRequire
|
||||
missingExclude
|
||||
missingReplace
|
||||
88
ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.ql
Normal file
88
ql/test/library-tests/semmle/go/GoModExpr/GoModExprs.ql
Normal file
@@ -0,0 +1,88 @@
|
||||
import go
|
||||
|
||||
/**
|
||||
* Holds if there exists a comment on the same line as `l`
|
||||
* that contains the substring "`kind`,`dep`,`ver`".
|
||||
*/
|
||||
predicate metadata(Locatable l, string kind, string mod, string dep, string ver) {
|
||||
exists(string f, int line, Comment c, string text |
|
||||
l.hasLocationInfo(f, line, _, _, _) and
|
||||
c.hasLocationInfo(f, line, _, _, _)
|
||||
|
|
||||
text = c.getText().regexpFind("\\b([^,\\s]+,[^,]+,[^,]+,[^,\\s]+)", _, _) and
|
||||
kind = text.regexpCapture("([^,]+),([^,]+),([^,]+),([^,]+)", 1) and
|
||||
mod = text.regexpCapture("([^,]+),([^,]+),([^,]+),([^,]+)", 2) and
|
||||
dep = text.regexpCapture("([^,]+),([^,]+),([^,]+),([^,]+)", 3) and
|
||||
ver = text.regexpCapture("([^,]+),([^,]+),([^,]+),([^,]+)", 4)
|
||||
)
|
||||
}
|
||||
|
||||
query predicate missingRequire(string mod, string dep, string ver, int line) {
|
||||
exists(Locatable l | metadata(l, "RequireLine", mod, dep, ver) |
|
||||
l.hasLocationInfo(_, line, _, _, _)
|
||||
) and
|
||||
not exists(GoModRequireLine req |
|
||||
req.getModulePath() = mod and
|
||||
req.getPath() = dep and
|
||||
req.getVersion() = ver and
|
||||
metadata(req, "RequireLine", mod, dep, ver) and
|
||||
req.hasLocationInfo(_, line, _, _, _)
|
||||
)
|
||||
}
|
||||
|
||||
query predicate missingExclude(string mod, string dep, string ver, int line) {
|
||||
exists(Locatable l | metadata(l, "ExcludeLine", mod, dep, ver) |
|
||||
l.hasLocationInfo(_, line, _, _, _)
|
||||
) and
|
||||
not exists(GoModExcludeLine exc |
|
||||
exc.getModulePath() = mod and
|
||||
exc.getPath() = dep and
|
||||
exc.getVersion() = ver and
|
||||
metadata(exc, "ExcludeLine", mod, dep, ver) and
|
||||
exc.hasLocationInfo(_, line, _, _, _)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if there exists a comment on the same line as `l`
|
||||
* that contains the substring "ReplaceLine,`mod`,`dep`,`dver`,`rep`,`rver`".
|
||||
*/
|
||||
predicate repmetadata(Locatable l, string mod, string dep, string dver, string rep, string rver) {
|
||||
exists(string f, int line, Comment c, string text |
|
||||
l.hasLocationInfo(f, line, _, _, _) and
|
||||
c.hasLocationInfo(f, line, _, _, _)
|
||||
|
|
||||
text = c.getText().regexpFind("\\b(ReplaceLine,[^,]*,[^,]*,[^,]*,[^,]*,[^,\\s]*)", _, _) and
|
||||
mod = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 1) and
|
||||
dep = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 2) and
|
||||
dver = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 3) and
|
||||
rep = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 4) and
|
||||
rver = text.regexpCapture("ReplaceLine,([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)", 5)
|
||||
)
|
||||
}
|
||||
|
||||
query predicate missingReplace(string mod, string dep, string dver, string rep, string rver, int line) {
|
||||
exists(Locatable l | repmetadata(l, mod, dep, dver, rep, rver) |
|
||||
l.hasLocationInfo(_, line, _, _, _)
|
||||
) and
|
||||
not exists(GoModReplaceLine repl |
|
||||
(
|
||||
rver = repl.getReplacementVersion()
|
||||
or
|
||||
not exists(repl.getReplacementVersion()) and
|
||||
rver = ""
|
||||
) and
|
||||
(
|
||||
dver = repl.getOriginalVersion()
|
||||
or
|
||||
not exists(repl.getOriginalVersion()) and
|
||||
dver = ""
|
||||
)
|
||||
|
|
||||
repl.getModulePath() = mod and
|
||||
repl.getOriginalPath() = dep and
|
||||
repl.getReplacementPath() = rep and
|
||||
repmetadata(repl, mod, dep, dver, rep, rver) and
|
||||
repl.hasLocationInfo(_, line, _, _, _)
|
||||
)
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
| go.mod:12:1:12:54 | go.mod replace line | codeql-go-tests/gomod | github.com/Masterminds/squirrel | no version | ./squirrel | no version |
|
||||
| go.mod:14:1:14:79 | go.mod replace line | codeql-go-tests/gomod | github.com/Sirupsen/logrus | v1.4.1 | github.com/sirupsen/logrus | v1.4.1 |
|
||||
@@ -1,18 +0,0 @@
|
||||
import go
|
||||
|
||||
from GoModReplaceLine repl, string origVersion, string repVersion
|
||||
where
|
||||
(
|
||||
repVersion = repl.getReplacementVersion()
|
||||
or
|
||||
not exists(repl.getReplacementVersion()) and
|
||||
repVersion = "no version"
|
||||
) and
|
||||
(
|
||||
origVersion = repl.getOriginalVersion()
|
||||
or
|
||||
not exists(repl.getOriginalVersion()) and
|
||||
origVersion = "no version"
|
||||
)
|
||||
select repl, repl.getModulePath(), repl.getOriginalPath(), origVersion, repl.getReplacementPath(),
|
||||
repVersion
|
||||
@@ -1,5 +0,0 @@
|
||||
| go.mod:6:2:6:67 | go.mod require line | codeql-go-tests/gomod | github.com/github/codeql-go | v1.23.2-0.20200302182241-5e71a04fdf30 |
|
||||
| go.mod:7:2:7:55 | go.mod require line | codeql-go-tests/gomod | golang.org/x/tools | v0.0.0-20200109174759-ac4f524c1612 |
|
||||
| go.mod:16:1:16:38 | go.mod require line | codeql-go-tests/gomod | github.com/gorilla/mux | v1.7.4 |
|
||||
| go.mod:19:2:19:40 | go.mod require line | codeql-go-tests/gomod | github.com/Masterminds/squirrel | v1.2.0 |
|
||||
| go.mod:20:2:20:35 | go.mod require line | codeql-go-tests/gomod | github.com/Sirupsen/logrus | v1.4.1 |
|
||||
@@ -1,4 +0,0 @@
|
||||
import go
|
||||
|
||||
from GoModRequireLine req
|
||||
select req, req.getModulePath(), req.getPath(), req.getVersion()
|
||||
@@ -3,21 +3,21 @@ module codeql-go-tests/gomod
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/github/codeql-go v1.23.2-0.20200302182241-5e71a04fdf30 // indirect
|
||||
golang.org/x/tools v0.0.0-20200109174759-ac4f524c1612 // indirect
|
||||
github.com/github/codeql-go v1.23.2-0.20200302182241-5e71a04fdf30 // indirect RequireLine,codeql-go-tests/gomod,github.com/github/codeql-go,v1.23.2-0.20200302182241-5e71a04fdf30
|
||||
golang.org/x/tools v0.0.0-20200109174759-ac4f524c1612 // indirect RequireLine,codeql-go-tests/gomod,golang.org/x/tools,v0.0.0-20200109174759-ac4f524c1612
|
||||
)
|
||||
|
||||
exclude github.com/github/codeql-go v1.23.1
|
||||
exclude github.com/github/codeql-go v1.23.1 // ExcludeLine,codeql-go-tests/gomod,github.com/github/codeql-go,v1.23.1
|
||||
|
||||
replace github.com/Masterminds/squirrel => ./squirrel
|
||||
replace github.com/Masterminds/squirrel => ./squirrel // ReplaceLine,codeql-go-tests/gomod,github.com/Masterminds/squirrel,,./squirrel,
|
||||
|
||||
replace github.com/Sirupsen/logrus v1.4.1 => github.com/sirupsen/logrus v1.4.1
|
||||
replace github.com/Sirupsen/logrus v1.4.1 => github.com/sirupsen/logrus v1.4.1 // ReplaceLine,codeql-go-tests/gomod,github.com/Sirupsen/logrus,v1.4.1,github.com/sirupsen/logrus,v1.4.1
|
||||
|
||||
require github.com/gorilla/mux v1.7.4 // indirect
|
||||
require github.com/gorilla/mux v1.7.4 // indirect RequireLine,codeql-go-tests/gomod,github.com/gorilla/mux,v1.7.4
|
||||
|
||||
require (
|
||||
github.com/Masterminds/squirrel v1.2.0 // indirect
|
||||
github.com/Sirupsen/logrus v1.4.1 // indirect
|
||||
github.com/Masterminds/squirrel v1.2.0 // indirect RequireLine,codeql-go-tests/gomod,github.com/Masterminds/squirrel,v1.2.0
|
||||
github.com/Sirupsen/logrus v1.4.1 // indirect RequireLine,codeql-go-tests/gomod,github.com/Sirupsen/logrus,v1.4.1
|
||||
)
|
||||
|
||||
exclude github.com/sirupsen/logrus v1.4.2
|
||||
exclude github.com/sirupsen/logrus v1.4.2 // ExcludeLine,codeql-go-tests/gomod,github.com/sirupsen/logrus,v1.4.2
|
||||
|
||||
Reference in New Issue
Block a user