Skip to content

Commit cad182f

Browse files
committed
Tests
1 parent c93a53b commit cad182f

File tree

14 files changed

+465
-0
lines changed

14 files changed

+465
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module test
2+
3+
go 1.22.5
4+
5+
require (
6+
gorm.io/gorm v1.23.0
7+
github.com/jmoiron/sqlx v1.4.0
8+
go.mongodb.org/mongo-driver/mongo v1.17.0
9+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
testFailures
2+
invalidModelRow
3+
failures
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/threat-models
4+
extensible: threatModelConfiguration
5+
data:
6+
- ["database", true, 0]
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package test
2+
3+
import (
4+
"context"
5+
"database/sql"
6+
"fmt"
7+
8+
beegoOrm "github.com/beego/beego/orm"
9+
gocb "github.com/couchbase/gocb/v2"
10+
"github.com/gogf/gf/database/gdb"
11+
"github.com/jmoiron/sqlx"
12+
"github.com/rqlite/gorqlite"
13+
"go.mongodb.org/mongo-driver/mongo"
14+
"gorm.io/gorm"
15+
)
16+
17+
func stdlib() {
18+
pool, err := sql.Open("mysql", "user:password@localhost:5555/dbname")
19+
if err != nil {
20+
return
21+
}
22+
23+
row := pool.QueryRow("SELECT * FROM users WHERE id = ?", 1) // $source
24+
fmt.Println(row)
25+
}
26+
27+
func gormDB(db *gorm.DB) {
28+
type User struct {
29+
gorm.Model
30+
}
31+
32+
var u1 User
33+
var u2 User
34+
35+
db.Find(&u1, 1) // $source
36+
db.FirstOrCreate(&u2, 1) // $source
37+
}
38+
39+
func mongoDB(ctx context.Context, userCollection mongo.Collection) {
40+
type User struct {
41+
}
42+
43+
var u1 User
44+
45+
result := userCollection.FindOne(ctx, nil) // $source
46+
result.Decode(&u1)
47+
48+
fmt.Println(u1)
49+
}
50+
51+
func gogf(g gdb.DB) {
52+
u1, err := g.GetOne("SELECT user from users") // $source
53+
54+
if err != nil {
55+
return
56+
}
57+
58+
fmt.Println(u1)
59+
}
60+
61+
func Sqlx() {
62+
db, err := sqlx.Connect("mysql", "user:password@localhost:5555/dbname")
63+
64+
if err != nil {
65+
return
66+
}
67+
68+
u1 := db.QueryRow("SELECT * FROM users WHERE id = ?", 1) // $source
69+
70+
fmt.Println(u1)
71+
72+
type User struct{}
73+
74+
rows, err := db.Queryx("SELECT * FROM users") // $source
75+
for rows.Next() {
76+
var user User
77+
rows.StructScan(&user)
78+
}
79+
}
80+
81+
func beego() {
82+
orm := beegoOrm.NewOrm()
83+
84+
type User struct {
85+
Id int
86+
Name string
87+
}
88+
89+
var user User
90+
orm.Read(&user) // $source
91+
}
92+
93+
func couchbase(coll *gocb.Collection) {
94+
type User struct {
95+
Name string
96+
}
97+
98+
var user User
99+
100+
result, err := coll.Get("documentID", nil) // $source
101+
102+
if err != nil {
103+
return
104+
}
105+
106+
result.Content(&user)
107+
108+
fmt.Println(user)
109+
}
110+
111+
func GoRqlite(conn *gorqlite.Connection) {
112+
var id int64
113+
var name string
114+
115+
rows, err := conn.QueryOne("select id, name from foo where id = 1") // $source
116+
if err != nil {
117+
return
118+
}
119+
rows.Scan(&id, &name)
120+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import go
2+
import ModelValidation
3+
import TestUtilities.InlineExpectationsTest
4+
5+
module SourceTest implements TestSig {
6+
string getARelevantTag() { result = "source" }
7+
8+
predicate hasActualResult(Location location, string element, string tag, string value) {
9+
exists(ActiveThreatModelSource s |
10+
s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
11+
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
12+
element = s.toString() and
13+
value = "" and
14+
tag = "source"
15+
)
16+
}
17+
}
18+
19+
import MakeTest<SourceTest>

go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/vendor/github.com/beego/beego/orm/stub.go

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/vendor/github.com/couchbase/gocb/v2/stub.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/vendor/github.com/gogf/gf/database/gdb/stub.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/database/vendor/github.com/jmoiron/sqlx/stub.go

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)