Skip to content

Commit

Permalink
Add tests for Conn
Browse files Browse the repository at this point in the history
  • Loading branch information
egregius313 committed Jan 8, 2025
1 parent a4afff2 commit 8e4939e
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ func test_sqlx_ctx(ctx context.Context, q sqlx.ExtContext) {
sink(user2) // $ hasTaintFlow="user2"
}

func test_sqlx_Conn(conn *sqlx.Conn) {
var user User
conn.GetContext(nil, &user, "SELECT * FROM users WHERE id = 1") // $ source

var user2 User
conn.SelectContext(nil, &user2, "SELECT * FROM users WHERE id = 1") // $ source

row := conn.QueryRowxContext(nil, "SELECT * FROM users WHERE id = 1") // $ source

userMap := make(map[string]interface{})
row.MapScan(userMap)
id := userMap["id"].(int)
sink(id) // $ hasTaintFlow="id"

rows, err := conn.QueryxContext(nil, "SELECT * FROM users WHERE id = 1") // $ source
ignore(err)

for rows.Next() {
var id int
var name string
err = rows.Scan(&id, &name)

if err != nil {
return
}

sink(id, name) // $ hasTaintFlow="id" hasTaintFlow="name"
}
}

func test_sqlx_DB(db *sqlx.DB) {
example, err := db.Query("SELECT * FROM users") // $ source
ignore(example, err)
Expand Down

0 comments on commit 8e4939e

Please sign in to comment.