-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* PMM-12640 Fix support of SSL certificates for PostgreSQL. * PMM-12640 Fix tests. * PMM-12640 don't send sslsni for old PMM clients. * PMM-12640 Fix tests. * PMM-12640 Fix linter. * PMM-12640 Fix linter. * PMM-12654 Fix test and address review comments. * PMM-12640 Fix connection checker.
- Loading branch information
Showing
23 changed files
with
252 additions
and
94 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
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
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
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
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
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 |
---|---|---|
|
@@ -66,15 +66,15 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
} | ||
|
||
t.Run("MongoDBNoDatabase", func(t *testing.T) { | ||
agent.AgentType = models.MongoDBExporterType | ||
|
||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000", agent.DSN(service, time.Second, "", nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true", agent.DSN(service, 0, "", nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true", agent.DSN(service, models.DSNParams{}, nil)) | ||
}) | ||
}) | ||
|
||
|
@@ -94,7 +94,7 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
} | ||
}) | ||
|
@@ -113,7 +113,7 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
} | ||
}) | ||
|
@@ -159,7 +159,7 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
} | ||
|
||
|
@@ -169,8 +169,8 @@ func TestAgent(t *testing.T) { | |
agent.MongoDBOptions.TLSCertificateKeyFilePassword = "" | ||
agent.MongoDBOptions.AuthenticationMechanism = "" | ||
|
||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, time.Second, "", nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, 0, "", nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{}, nil)) | ||
expectedFiles := map[string]string{ | ||
"caFilePlaceholder": "cert", | ||
"certificateKeyFilePlaceholder": "key", | ||
|
@@ -185,8 +185,8 @@ func TestAgent(t *testing.T) { | |
agent.MongoDBOptions.AuthenticationMechanism = "MONGO-X509" | ||
agent.MongoDBOptions.AuthenticationDatabase = "$external" | ||
|
||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?authMechanism=MONGO-X509&authSource=%24external&connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, time.Second, "", nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?authMechanism=MONGO-X509&authSource=%24external&directConnection=true&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, 0, "", nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?authMechanism=MONGO-X509&authSource=%24external&connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?authMechanism=MONGO-X509&authSource=%24external&directConnection=true&ssl=true&tlsCaFile={{.TextFiles.caFilePlaceholder}}&tlsCertificateKeyFile={{.TextFiles.certificateKeyFilePlaceholder}}", agent.DSN(service, models.DSNParams{}, nil)) | ||
expectedFiles := map[string]string{ | ||
"caFilePlaceholder": "cert", | ||
"certificateKeyFilePlaceholder": "key", | ||
|
@@ -217,15 +217,15 @@ func TestAgent(t *testing.T) { | |
} { | ||
t.Run(string(typ), func(t *testing.T) { | ||
agent.AgentType = typ | ||
assert.Equal(t, expected, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
} | ||
|
||
t.Run("MongoDBNoDatabase", func(t *testing.T) { | ||
agent.AgentType = models.MongoDBExporterType | ||
|
||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsInsecure=true", agent.DSN(service, time.Second, "", nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true&ssl=true&tlsInsecure=true", agent.DSN(service, 0, "", nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true&tlsInsecure=true", agent.DSN(service, models.DSNParams{DialTimeout: time.Second}, nil)) | ||
assert.Equal(t, "mongodb://username:s3cur3%20p%[email protected]:12345/?directConnection=true&ssl=true&tlsInsecure=true", agent.DSN(service, models.DSNParams{}, nil)) | ||
}) | ||
}) | ||
} | ||
|
@@ -255,7 +255,7 @@ func TestPostgresAgentTLS(t *testing.T) { | |
t.Run(name, func(t *testing.T) { | ||
agent.TLS = testCase.tls | ||
agent.TLSSkipVerify = testCase.tlsSkipVerify | ||
assert.Equal(t, testCase.expected, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, testCase.expected, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
} | ||
} | ||
|
@@ -272,7 +272,7 @@ func TestPostgresWithSocket(t *testing.T) { | |
Socket: pointer.ToString("/var/run/postgres"), | ||
} | ||
expect := "postgres://username@/database?connect_timeout=1&host=%2Fvar%2Frun%2Fpostgres&sslmode=verify-ca" | ||
assert.Equal(t, expect, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
|
||
t.Run("empty-user-password", func(t *testing.T) { | ||
|
@@ -283,7 +283,7 @@ func TestPostgresWithSocket(t *testing.T) { | |
Socket: pointer.ToString("/var/run/postgres"), | ||
} | ||
expect := "postgres:///database?connect_timeout=1&host=%2Fvar%2Frun%2Fpostgres&sslmode=disable" | ||
assert.Equal(t, expect, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
|
||
t.Run("dir-with-symbols", func(t *testing.T) { | ||
|
@@ -294,7 +294,7 @@ func TestPostgresWithSocket(t *testing.T) { | |
Socket: pointer.ToString(`/tmp/123\ A0m\%\$\@\8\,\+\-`), | ||
} | ||
expect := "postgres:///database?connect_timeout=1&host=%2Ftmp%2F123%5C+A0m%5C%25%5C%24%5C%40%5C8%5C%2C%5C%2B%5C-&sslmode=disable" | ||
assert.Equal(t, expect, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
} | ||
|
||
|
@@ -310,7 +310,7 @@ func TestMongoWithSocket(t *testing.T) { | |
Socket: pointer.ToString("/tmp/mongodb-27017.sock"), | ||
} | ||
expect := "mongodb://username@%2Ftmp%2Fmongodb-27017.sock/database?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000&ssl=true" | ||
assert.Equal(t, expect, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
|
||
t.Run("empty-user-password", func(t *testing.T) { | ||
|
@@ -321,7 +321,7 @@ func TestMongoWithSocket(t *testing.T) { | |
Socket: pointer.ToString("/tmp/mongodb-27017.sock"), | ||
} | ||
expect := "mongodb://%2Ftmp%2Fmongodb-27017.sock/database?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000" | ||
assert.Equal(t, expect, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
|
||
t.Run("dir-with-symbols", func(t *testing.T) { | ||
|
@@ -332,7 +332,7 @@ func TestMongoWithSocket(t *testing.T) { | |
Socket: pointer.ToString(`/tmp/123\ A0m\%\$\@\8\,\+\-/mongodb-27017.sock`), | ||
} | ||
expect := "mongodb://%2Ftmp%2F123%5C%20A0m%5C%25%5C$%5C%40%5C8%5C,%5C+%5C-%2Fmongodb-27017.sock/database?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000" | ||
assert.Equal(t, expect, agent.DSN(service, time.Second, "database", nil)) | ||
assert.Equal(t, expect, agent.DSN(service, models.DSNParams{DialTimeout: time.Second, Database: "database"}, nil)) | ||
}) | ||
} | ||
|
||
|
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
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
Oops, something went wrong.