Skip to content

Commit a1b394b

Browse files
committed
Test for sslinline=true feature
I've found no test for the `sslinline=true` feature, so I added one.
1 parent b7ffbd3 commit a1b394b

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+
if db, err := openSSLConn(t, "sslmode=require user=pqgosslcert sslinline=true sslcert='"+sslcert+"' sslkey='"+sslkey+"'"); err != nil {
327+
t.Fatal(err)
328+
} else {
329+
rows, err := db.Query("SELECT 1")
330+
if err != nil {
331+
t.Fatal(err)
332+
}
333+
if err := rows.Close(); err != nil {
334+
t.Fatal(err)
335+
}
336+
if err := db.Close(); err != nil {
337+
t.Fatal(err)
338+
}
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)