-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a7f14f
commit 55422d2
Showing
4 changed files
with
606 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...st/library-tests/semmle/go/dataflow/flowsources/local/database/test_mongo_driver_mongo.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
|
||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
func test_mongo_driver_mongo_collection(coll *mongo.Collection, ctx context.Context, pipeline any) { | ||
cursor, err := coll.Aggregate(ctx, pipeline) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
var users []User | ||
|
||
err = cursor.All(ctx, &users) | ||
|
||
sink(users) // $ hasTaintFlow="users" | ||
|
||
distinct, err := coll.Distinct(ctx, "name", nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
sink(distinct) // $ hasTaintFlow="distinct" | ||
|
||
cursor2, err := coll.Find(ctx, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
sink(cursor2) // $ hasTaintFlow="cursor2" | ||
|
||
var user1, user2, user3, user4 User | ||
|
||
single1 := coll.FindOne(ctx, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
single1.Decode(&user1) | ||
|
||
sink(user1) // $ hasTaintFlow="user1" | ||
|
||
single2 := coll.FindOneAndDelete(ctx, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
single2.Decode(&user2) | ||
|
||
sink(user2) // $ hasTaintFlow="user2" | ||
|
||
single3 := coll.FindOneAndReplace(ctx, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
single3.Decode(&user3) | ||
|
||
sink(user3) // $ hasTaintFlow="user3" | ||
|
||
single4 := coll.FindOneAndUpdate(ctx, nil, nil) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
single4.Decode(&user4) | ||
|
||
sink(user4) // $ hasTaintFlow="user4" | ||
|
||
changeStream, err := coll.Watch(ctx, pipeline) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
for changeStream.Next(ctx) { | ||
var userCs User | ||
changeStream.Decode(&userCs) | ||
sink(userCs) // $ hasTaintFlow="userCs" | ||
} | ||
} | ||
|
||
func test_mongo_driver_mongo_database(db *mongo.Database, ctx context.Context, pipeline any) { | ||
agg, err := db.Aggregate(ctx, pipeline) // $ source | ||
|
||
if err != nil { | ||
return | ||
} | ||
|
||
var user User | ||
agg.Decode(&user) | ||
sink(user) // $ hasTaintFlow="user" | ||
|
||
changeStream, err := db.Watch(ctx, pipeline) // $ source | ||
if err != nil { | ||
return | ||
} | ||
|
||
for changeStream.Next(ctx) { | ||
var userCs User | ||
changeStream.Decode(&userCs) | ||
sink(userCs) // $ hasTaintFlow="userCs" | ||
} | ||
} |
Oops, something went wrong.