Skip to content

Commit

Permalink
testserver: add missing tenant client certificate
Browse files Browse the repository at this point in the history
Fixes #87.
  • Loading branch information
tbg committed Aug 18, 2020
1 parent 4a99d43 commit 23be265
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/jinzhu/gorm v1.9.12
github.com/jmoiron/sqlx v1.2.0
github.com/lib/pq v1.4.0
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/shopspring/decimal v0.0.0-20200419222939-1884f454f8ea // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
google.golang.org/appengine v1.6.5 // indirect
Expand Down
19 changes: 17 additions & 2 deletions testserver/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"net"
"os/exec"
"path/filepath"
"strconv"
)
Expand All @@ -42,6 +43,7 @@ func (ts *testServerImpl) isTenant() bool {
// NewTenantServer, and subsequently cast the TestServer obtained from
// NewTestServer to this interface. Refer to the tests for an example.
func (ts *testServerImpl) NewTenantServer() (TestServer, error) {
cockroachBinary := ts.cmdArgs[0]
tenantID, err := func() (int, error) {
ts.mu.Lock()
defer ts.mu.Unlock()
Expand All @@ -61,7 +63,20 @@ func (ts *testServerImpl) NewTenantServer() (TestServer, error) {

secureFlag := "--insecure"
if ts.serverArgs.secure {
secureFlag = "--certs-dir=" + filepath.Join(ts.baseDir, "certs")
certsDir := filepath.Join(ts.baseDir, "certs")
secureFlag = "--certs-dir=" + certsDir
certArgs := []string{
secureFlag,
"--ca-key=" + filepath.Join(certsDir, "ca.key"),
}
for _, args := range [][]string{
// Create tenant client certificate.
{"mt", "cert", "create-tenant-client", fmt.Sprint(tenantID)},
} {
if err := exec.Command(cockroachBinary, append(args, certArgs...)...).Run(); err != nil {
return nil, err
}
}
}
// Create a new tenant.
if err := ts.WaitForInit(); err != nil {
Expand Down Expand Up @@ -97,7 +112,7 @@ func (ts *testServerImpl) NewTenantServer() (TestServer, error) {
}

args := []string{
ts.cmdArgs[0],
cockroachBinary,
"mt",
"start-sql",
secureFlag,
Expand Down
3 changes: 0 additions & 3 deletions testserver/testserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ func TestRunServer(t *testing.T) {
instantiation: func() (*sql.DB, func()) { return newTenantDBForTest(t, true /* secure */) },
},
} {
if tc.name == "SecureTenant" {
t.Skip("Skipping due to https://github.com/cockroachdb/cockroach-go/issues/87")
}
t.Run(tc.name, func(t *testing.T) {
db, stop := tc.instantiation()
defer stop()
Expand Down

0 comments on commit 23be265

Please sign in to comment.