-
Notifications
You must be signed in to change notification settings - Fork 21
PMM-9320: fix username/password incorrect escape #372
base: main
Are you sure you want to change the base?
Changes from 1 commit
e702a18
27a9c8a
8976716
9fabb3e
4c44b7f
9f69bb3
0a57917
1f022eb
1cc70c5
68f8084
d4ce64f
2b88a51
c189e5f
32a33c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mongo_fix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. called
ritbl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
"net/url" | ||
) | ||
|
||
// ClientForDSN applies URI to Client | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci-lint] reported by reviewdog 🐶 |
||
func ClientForDSN(dsn string) (*options.ClientOptions, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably we should call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, |
||
parsedDsn, err := url.Parse(dsn) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "cannot parse DSN") | ||
} | ||
|
||
username := parsedDsn.User.Username() | ||
password, _ := parsedDsn.User.Password() | ||
creds := options.Credential{Username: username, Password: password} | ||
|
||
clientOptions := options.Client(). | ||
ApplyURI(dsn). | ||
SetAuth(creds) //Workaround for PMM-9320 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixing here |
||
|
||
return clientOptions, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ package tests | |
|
||
import ( | ||
"context" | ||
"github.com/percona/pmm-agent/mongo_fix" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
@@ -25,7 +26,6 @@ import ( | |
"github.com/stretchr/testify/require" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
// GetTestMongoDBDSN returns DNS for MongoDB test database. | ||
|
@@ -104,7 +104,12 @@ func GetTestMongoDBReplicatedWithSSLDSN(tb testing.TB, pathToRoot string) (strin | |
func OpenTestMongoDB(tb testing.TB, dsn string) *mongo.Client { | ||
tb.Helper() | ||
|
||
client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(dsn)) | ||
opts, err := mongo_fix.ClientForDSN(dsn) | ||
if err != nil { | ||
panic(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
client, err := mongo.Connect(context.Background(), opts) | ||
require.NoError(tb, err) | ||
|
||
require.NoError(tb, client.Ping(context.Background(), nil)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is test, so we can
panic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can, but should we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, here we return error, so I think we can just propagate error.
but what about other cases, like in
func OpenTestMongoDB(tb testing.TB, dsn string) *mongo.Client {
we don't have error in the API, do you think we should refactor API or we can panic (in tests only)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can call
require.NoError(tb, err)
in that places. so it will stop test with failed resultThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, good idea