Skip to content

Commit

Permalink
Merge "[FAB-5427] Fixes TestNewUserRegistryMySQL on vagrant"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Yellick authored and Gerrit Code Review committed Sep 14, 2017
2 parents 11ca4d3 + 2339c6c commit 27ebf39
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions lib/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
Expand Down Expand Up @@ -1619,6 +1620,32 @@ func TestSRVSqliteLocking(t *testing.T) {
}
}

func copyFile(src, dst string, t *testing.T) {
srcFile, err := os.Open(src)
if err != nil {
t.Fatalf("Failed to open file %s %s", src, err)
}

defer srcFile.Close()

destFile, err := os.Create(dst)
if err != nil {
t.Fatalf("Failed to create file %s %s", dst, err)
}

defer destFile.Close()

_, err = io.Copy(destFile, srcFile)
if err != nil {
t.Fatalf("Failed to copy file %s to %s: %s", src, dst, err)
}

err = destFile.Sync()
if err != nil {
t.Fatalf("Failed to copy file %s to %s: %s", src, dst, err)
}
}

func TestSRVNewUserRegistryMySQL(t *testing.T) {
datasource := ""

Expand Down Expand Up @@ -1650,14 +1677,16 @@ func TestSRVNewUserRegistryMySQL(t *testing.T) {
assert.Contains(t, err.Error(), "Failed to process certificate from file")

// Test with a file that does not have read permissions
err = os.Chmod("../testdata/root.pem", 0000)
tmpFile := filepath.Join(os.TempDir(), "root.pem")
copyFile("../testdata/root.pem", tmpFile, t)
err = os.Chmod(tmpFile, 0000)
if err != nil {
fmt.Println(err)
t.Fatalf("Failed to change file mode: %s", err)
}

tlsConfig = &libtls.ClientTLSConfig{
Enabled: true,
CertFiles: []string{"../testdata/root.pem"},
CertFiles: []string{tmpFile},
}
_, _, err = dbutil.NewUserRegistryMySQL(datasource, tlsConfig, csp)
assert.Error(t, err)
Expand All @@ -1666,9 +1695,9 @@ func TestSRVNewUserRegistryMySQL(t *testing.T) {
}
assert.Contains(t, err.Error(), "denied")

err = os.Chmod("../testdata/root.pem", 0644)
err = os.RemoveAll(tmpFile)
if err != nil {
fmt.Println(err)
t.Logf("%s", err.Error())
}
}

Expand Down

0 comments on commit 27ebf39

Please sign in to comment.