-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Go: Add database source models for the github.com/couchbase/gocb package
#18913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
owen-mc
merged 5 commits into
github:main
from
egregius313:egregius313/go/mad/database/couchbase
Mar 25, 2025
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
19147ee
Add couchbase models
egregius313 04d9c94
[test] Add couchbase database model tests
egregius313 e6198ba
[change-note] couchbase source models
egregius313 166d523
Apply suggestions from code review
owen-mc 88e9682
Apply suggestions from code review
owen-mc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * `database` source models have been added for v1 and v2 of the `github.com/couchbase/gocb` package. | ||
|
|
This file contains hidden or 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
55 changes: 55 additions & 0 deletions
55
...est/library-tests/semmle/go/dataflow/flowsources/local/database/test_couchbase_gocb_v1.go
This file contains hidden or 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,55 @@ | ||
| package test | ||
|
|
||
| import "github.com/couchbase/gocb" | ||
|
|
||
| func test_couchbase_gocb_v1_Cluster(cluster *gocb.Cluster, aq *gocb.AnalyticsQuery, n1ql *gocb.N1qlQuery, sq *gocb.SearchQuery) { | ||
| // Analytics | ||
| r1, err := cluster.ExecuteAnalyticsQuery(aq, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user1, user2 User | ||
|
|
||
| r1.One(&user1) | ||
| sink(user1) // $ hasTaintFlow="user1" | ||
|
|
||
| for r1.Next(user2) { | ||
| sink(user2) // $ hasTaintFlow="user2" | ||
| } | ||
|
|
||
| var b1 []byte | ||
| b1 = r1.NextBytes() | ||
| sink(b1) // $ hasTaintFlow="b1" | ||
|
|
||
| // N1QL | ||
| r2, err := cluster.ExecuteN1qlQuery(n1ql, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user3, user4 User | ||
|
|
||
| r2.One(&user3) | ||
| sink(user3) // $ hasTaintFlow="user3" | ||
|
|
||
| for r2.Next(user4) { | ||
| sink(user4) // $ hasTaintFlow="user4" | ||
| } | ||
|
|
||
| var b2 []byte | ||
| b2 = r2.NextBytes() | ||
| sink(b2) // $ hasTaintFlow="b2" | ||
|
|
||
| // Search | ||
| r3, err := cluster.ExecuteSearchQuery(sq) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| hit := r3.Hits()[0] | ||
| sink(hit) // $ hasTaintFlow="hit" | ||
| } |
247 changes: 247 additions & 0 deletions
247
...est/library-tests/semmle/go/dataflow/flowsources/local/database/test_couchbase_gocb_v2.go
This file contains hidden or 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,247 @@ | ||
| package test | ||
|
|
||
| //go:generate depstubber -vendor github.com/couchbase/gocb/v2 Cluster,Scope,Collection,TransactionAttemptContext,ViewIndexManager | ||
|
|
||
| import "github.com/couchbase/gocb/v2" | ||
|
|
||
| func test_couchbase_gocb_v2_Cluster(cluster *gocb.Cluster) { | ||
| r1, err := cluster.AnalyticsQuery("SELECT * FROM `travel-sample`", nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| for r1.Next() { | ||
| var name1, name2 string | ||
|
|
||
| r1.One(&name1) | ||
|
|
||
| sink(name1) // $ hasTaintFlow="name1" | ||
|
|
||
| r1.Row(&name2) | ||
| sink(name2) // $ hasTaintFlow="name2" | ||
|
|
||
| b := r1.Raw().NextBytes() | ||
| sink(b) // $ hasTaintFlow="b" | ||
| } | ||
|
|
||
| r2, err := cluster.Query("SELECT * FROM `travel-sample`", nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| for r2.Next() { | ||
| var name1, name2 string | ||
|
|
||
| r2.One(&name1) | ||
|
|
||
| sink(name1) // $ hasTaintFlow="name1" | ||
|
|
||
| r2.Row(&name2) | ||
| sink(name2) // $ hasTaintFlow="name2" | ||
|
|
||
| b := r2.Raw().NextBytes() | ||
| sink(b) // $ hasTaintFlow="b" | ||
| } | ||
| } | ||
|
|
||
| func test_couchbase_gocb_v2_Scope(scope *gocb.Scope) { | ||
| r1, err := scope.AnalyticsQuery("SELECT * FROM `travel-sample`", nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| for r1.Next() { | ||
| var name1, name2 string | ||
|
|
||
| r1.One(&name1) | ||
|
|
||
| sink(name1) // $ hasTaintFlow="name1" | ||
|
|
||
| r1.Row(&name2) | ||
| sink(name2) // $ hasTaintFlow="name2" | ||
|
|
||
| b := r1.Raw().NextBytes() | ||
| sink(b) // $ hasTaintFlow="b" | ||
| } | ||
|
|
||
| r2, err := scope.Query("SELECT * FROM `travel-sample`", nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| for r2.Next() { | ||
| var name1, name2 string | ||
|
|
||
| r2.One(&name1) | ||
|
|
||
| sink(name1) // $ hasTaintFlow="name1" | ||
|
|
||
| r2.Row(&name2) | ||
| sink(name2) // $ hasTaintFlow="name2" | ||
|
|
||
| b := r2.Raw().NextBytes() | ||
| sink(b) // $ hasTaintFlow="b" | ||
| } | ||
| } | ||
|
|
||
| func test_couchbase_gocb_v2_Collection(coll *gocb.Collection) { | ||
| type User struct { | ||
| Name string | ||
| } | ||
|
|
||
| var user User | ||
|
|
||
| r1, err := coll.Get("documentID", nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| r1.Content(&user) | ||
|
|
||
| sink(user) // $ hasTaintFlow="user" | ||
|
|
||
| r2, err := coll.GetAndLock("documentID", 30, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| sink(r2) // $ hasTaintFlow="r2" | ||
|
|
||
| r3, err := coll.GetAndTouch("documentID", 30, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user3 User | ||
| r3.Content(&user3) | ||
| sink(user3) // $ hasTaintFlow="user3" | ||
|
|
||
| r4, err := coll.GetAnyReplica("documentID", nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| sink(r4) // $ hasTaintFlow="r4" | ||
|
|
||
| r5, err := coll.LookupIn("documentID", []gocb.LookupInSpec{}, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user5 User | ||
| r5.ContentAt(0, &user5) | ||
| sink(user5) // $ hasTaintFlow="user5" | ||
|
|
||
| r6, err := coll.LookupInAllReplicas("documentID", []gocb.LookupInSpec{}, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user6 User | ||
| r6.Next().ContentAt(0, &user6) | ||
| sink(user6) // $ hasTaintFlow="user6" | ||
|
|
||
| r7, err := coll.LookupInAnyReplica("documentID", []gocb.LookupInSpec{}, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user7 User | ||
| r7.ContentAt(0, &user7) | ||
| sink(user7) // $ hasTaintFlow="user7" | ||
|
|
||
| r8, err := coll.Scan(nil, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user8 User | ||
| r8.Next().Content(&user8) | ||
| sink(user8) // $ hasTaintFlow="user8" | ||
| } | ||
|
|
||
| func test_couchbase_gocb_v2_TransactionAttemptContext(tam *gocb.TransactionAttemptContext, coll *gocb.Collection) { | ||
| r1, err := tam.Get(coll, "documentID") // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user User | ||
| r1.Content(&user) | ||
|
|
||
| sink(user) // $ hasTaintFlow="user" | ||
|
|
||
| r2, err := tam.GetReplicaFromPreferredServerGroup(coll, "documentID") // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user2 User | ||
| r2.Content(&user2) | ||
| sink(user2) // $ hasTaintFlow="user2" | ||
|
|
||
| var user3 User | ||
|
|
||
| r3, err := tam.Insert(coll, "documentID", &user3) // $ source | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| var user4 User | ||
| r3.Content(&user4) | ||
| sink(user4) // $ hasTaintFlow="user4" | ||
|
|
||
| r4, err := tam.Query("SELECT * FROM `travel-sample`", nil) // $ source | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| for r4.Next() { | ||
| var user5 User | ||
| r4.One(&user5) | ||
| sink(user5) // $ hasTaintFlow="user5" | ||
|
|
||
| var user6 User | ||
| r4.Row(&user6) | ||
| sink(user6) // $ hasTaintFlow="user6" | ||
| } | ||
|
|
||
| r5, err := tam.Replace(r3, user4) // $ source | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| sink(r5) // $ hasTaintFlow="r5" | ||
| } | ||
|
|
||
| func test_couchbase_gocb_v2_ViewIndexManager(v *gocb.ViewIndexManager) { | ||
| doc, err := v.GetDesignDocument("name", 0, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| sink(doc) // $ hasTaintFlow="doc" | ||
|
|
||
| docs, err := v.GetAllDesignDocuments(0, nil) // $ source | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| sink(docs) // $ hasTaintFlow="docs" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.