Skip to content

Commit a029672

Browse files
zregvartarp242
authored andcommitted
Test for sslinline=true feature
I've found no test for the `sslinline=true` feature, so I added one.
1 parent 05b0e79 commit a029672

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

ssl_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,45 @@ func TestSSLClientCertificates(t *testing.T) {
300300
}
301301
}
302302

303+
// Authenticate over SSL using inline client certificates
304+
func TestSSLInlineClientCertificates(t *testing.T) {
305+
maybeSkipSSLTests(t)
306+
// Environment sanity check: should fail without SSL
307+
checkSSLSetup(t, "sslmode=disable user=pqgossltest")
308+
309+
certpath, ok := os.LookupEnv("PQSSLCERTTEST_PATH")
310+
if !ok {
311+
t.Fatalf("PQSSLCERTTEST_PATH not present in environment")
312+
}
313+
314+
sslcertBytes, err := os.ReadFile(filepath.Join(certpath, "postgresql.crt"))
315+
if err != nil {
316+
t.Fatal(err)
317+
}
318+
sslcert := string(sslcertBytes)
319+
320+
sslkeyBytes, err := os.ReadFile(filepath.Join(certpath, "postgresql.key"))
321+
if err != nil {
322+
t.Fatal(err)
323+
}
324+
sslkey := string(sslkeyBytes)
325+
326+
db, err := openSSLConn(t, "sslmode=require user=pqgosslcert sslinline=true sslcert='"+sslcert+"' sslkey='"+sslkey+"'")
327+
if err != nil {
328+
t.Fatal(err)
329+
}
330+
rows, err := db.Query("SELECT 1")
331+
if err != nil {
332+
t.Fatal(err)
333+
}
334+
if err := rows.Close(); err != nil {
335+
t.Fatal(err)
336+
}
337+
if err := db.Close(); err != nil {
338+
t.Fatal(err)
339+
}
340+
}
341+
303342
// Check that clint sends SNI data when `sslsni` is not disabled
304343
func TestSNISupport(t *testing.T) {
305344
t.Parallel()

0 commit comments

Comments
 (0)