Skip to content

Commit

Permalink
[FAB-7392] Enable multiple version testing
Browse files Browse the repository at this point in the history
This patch adds new make targets for testing against
various Fabric code levels. Additionally some fixtures
are versioned to support the code levels.

Change-Id: I581e2ca94ac52c76599a5599711bf0f7b2b81578
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Dec 12, 2017
1 parent 4a56d4a commit 3651028
Show file tree
Hide file tree
Showing 211 changed files with 1,229 additions and 223 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ vendor/


# Files auto-generated by docker-compose
test/fixtures/tls/fabricca/certs/server/ca.org*.example.com-cert.pem
test/fixtures/fabricca/tls/certs/server/ca.org*.example.com-cert.pem
251 changes: 217 additions & 34 deletions Makefile

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ You're good to go, happy coding! Check out the examples for usage demonstrations

## Client SDK

### Compatibility
### Current Compatibility
The SDK's integration tests run against three tagged Fabric versions:
- prev (currently v1.0.0)
- stable (currently latest of v1.0.x)
- prerelease (currently latest of v1.1.0-x)

Additionally for development purposes integration tests also run against the devstable Fabric version as needed.

### Retired versions
When the 'prev' code level is updated, the last tested fabric-sdk-go commit or tag is listed below.

- fabric v1.0.4 & fabric-ca v1.0.4
- fabric-sdk-go: master:HEAD
- fabric v1.0.0 & fabric-ca v1.0.0
- fabric-sdk-go: master:110bf21bf3ab0a9a084f46d9698e1daeeda68a59
- fabric-sdk-go: master:HEAD

### Running the test suite

Expand Down
12 changes: 6 additions & 6 deletions def/fabapi/testdata/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ client:
response: 5s

cryptoconfig:
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config
path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}

credentialStore:
path: "/tmp/hfc-kvs"
Expand Down Expand Up @@ -98,7 +98,7 @@ orderers:
grpc-max-send-message-length: 15

tlsCACerts:
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem

peers:
peer0.org2.example.com:
Expand All @@ -107,7 +107,7 @@ peers:
grpcOptions:
ssl-target-name-override: peer0.org2.example.com
tlsCACerts:
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem
path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem

certificateAuthorities:
ca-org2:
Expand All @@ -117,10 +117,10 @@ certificateAuthorities:
verify: true

tlsCACerts:
path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/ca_root.pem
path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/fabricca/tls/certs/ca_root.pem
client:
keyfile: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/client/client_fabric_client-key.pem
certfile: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/client/client_fabric_client.pem
keyfile: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/fabricca/tls/certs/client/client_fabric_client-key.pem
certfile: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/fabricca/tls/certs/client/client_fabric_client.pem

registrar:
enrollId: admin
Expand Down
37 changes: 13 additions & 24 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import (
"bytes"
"crypto/x509"
"encoding/pem"
"go/build"
"io/ioutil"
"math/rand"
"os"
"path"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -160,7 +158,7 @@ func loadDefaultConfig(myViper *viper.Viper) error {
return nil
}
// if set, use it to load default config
myViper.AddConfigPath(substGoPath(defaultPath))
myViper.AddConfigPath(substPathVars(defaultPath))
err := myViper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
return errors.Wrap(err, "loading config file failed")
Expand Down Expand Up @@ -236,7 +234,7 @@ func (c *Config) CAServerCertPaths(org string) ([]string, error) {

certFileModPath := make([]string, len(certFiles))
for i, v := range certFiles {
certFileModPath[i] = substGoPath(v)
certFileModPath[i] = substPathVars(v)
}

return certFileModPath, nil
Expand Down Expand Up @@ -277,7 +275,7 @@ func (c *Config) CAClientKeyPath(org string) (string, error) {
if _, ok := config.CertificateAuthorities[strings.ToLower(caName)]; !ok {
return "", errors.Errorf("CA Server Name '%s' not found", caName)
}
return substGoPath(config.CertificateAuthorities[strings.ToLower(caName)].TLSCACerts.Client.Keyfile), nil
return substPathVars(config.CertificateAuthorities[strings.ToLower(caName)].TLSCACerts.Client.Keyfile), nil
}

// CAClientKeyPem Read configuration option for the fabric CA client key pem embedded in the client config
Expand Down Expand Up @@ -317,7 +315,7 @@ func (c *Config) CAClientCertPath(org string) (string, error) {
if _, ok := config.CertificateAuthorities[strings.ToLower(caName)]; !ok {
return "", errors.Errorf("CA Server Name '%s' not found", caName)
}
return substGoPath(config.CertificateAuthorities[strings.ToLower(caName)].TLSCACerts.Client.Certfile), nil
return substPathVars(config.CertificateAuthorities[strings.ToLower(caName)].TLSCACerts.Client.Certfile), nil
}

// CAClientCertPem Read configuration option for the fabric CA client cert pem embedded in the client config
Expand Down Expand Up @@ -439,7 +437,7 @@ func (c *Config) OrderersConfig() ([]apiconfig.OrdererConfig, error) {
for _, orderer := range config.Orderers {

if orderer.TLSCACerts.Path != "" {
orderer.TLSCACerts.Path = substGoPath(orderer.TLSCACerts.Path)
orderer.TLSCACerts.Path = substPathVars(orderer.TLSCACerts.Path)
} else if len(orderer.TLSCACerts.Pem) == 0 && c.configViper.GetBool("client.systemcertpool") == false {
errors.Errorf("Orderer has no certs configured. Make sure TLSCACerts.Pem or TLSCACerts.Path is set for %s", orderer.URL)
}
Expand Down Expand Up @@ -482,7 +480,7 @@ func (c *Config) OrdererConfig(name string) (*apiconfig.OrdererConfig, error) {
}

if orderer.TLSCACerts.Path != "" {
orderer.TLSCACerts.Path = substGoPath(orderer.TLSCACerts.Path)
orderer.TLSCACerts.Path = substPathVars(orderer.TLSCACerts.Path)
}

return &orderer, nil
Expand All @@ -505,7 +503,7 @@ func (c *Config) PeersConfig(org string) ([]apiconfig.PeerConfig, error) {
return nil, err
}
if p.TLSCACerts.Path != "" {
p.TLSCACerts.Path = substGoPath(p.TLSCACerts.Path)
p.TLSCACerts.Path = substPathVars(p.TLSCACerts.Path)
}

peers = append(peers, p)
Expand Down Expand Up @@ -537,7 +535,7 @@ func (c *Config) PeerConfig(org string, name string) (*apiconfig.PeerConfig, err
}

if peerConfig.TLSCACerts.Path != "" {
peerConfig.TLSCACerts.Path = substGoPath(peerConfig.TLSCACerts.Path)
peerConfig.TLSCACerts.Path = substPathVars(peerConfig.TLSCACerts.Path)
}
return &peerConfig, nil
}
Expand Down Expand Up @@ -618,7 +616,7 @@ func (c *Config) ChannelPeers(name string) ([]apiconfig.ChannelPeer, error) {
}

if p.TLSCACerts.Path != "" {
p.TLSCACerts.Path = substGoPath(p.TLSCACerts.Path)
p.TLSCACerts.Path = substPathVars(p.TLSCACerts.Path)
}

mspID, err := c.PeerMspID(peerName)
Expand Down Expand Up @@ -653,7 +651,7 @@ func (c *Config) NetworkPeers() ([]apiconfig.NetworkPeer, error) {
}

if p.TLSCACerts.Path != "" {
p.TLSCACerts.Path = substGoPath(p.TLSCACerts.Path)
p.TLSCACerts.Path = substPathVars(p.TLSCACerts.Path)
}

mspID, err := c.PeerMspID(name)
Expand Down Expand Up @@ -796,20 +794,20 @@ func (c *Config) SecurityProviderLabel() string {

// KeyStorePath returns the keystore path used by BCCSP
func (c *Config) KeyStorePath() string {
keystorePath := substGoPath(c.configViper.GetString("client.credentialStore.cryptoStore.path"))
keystorePath := substPathVars(c.configViper.GetString("client.credentialStore.cryptoStore.path"))
return path.Join(keystorePath, "keystore")
}

// CAKeyStorePath returns the same path as KeyStorePath() without the
// 'keystore' directory added. This is done because the fabric-ca-client
// adds this to the path
func (c *Config) CAKeyStorePath() string {
return substGoPath(c.configViper.GetString("client.credentialStore.cryptoStore.path"))
return substPathVars(c.configViper.GetString("client.credentialStore.cryptoStore.path"))
}

// CryptoConfigPath ...
func (c *Config) CryptoConfigPath() string {
return substGoPath(c.configViper.GetString("client.cryptoconfig.path"))
return substPathVars(c.configViper.GetString("client.cryptoconfig.path"))
}

// loadCAKey
Expand All @@ -826,12 +824,3 @@ func loadCAKey(rawData []byte) (*x509.Certificate, error) {
}
return nil, errors.New("pem data missing")
}

// substGoPath replaces instances of '$GOPATH' with the GOPATH. If the system
// has multiple GOPATHs then the first is used.
func substGoPath(s string) string {
gpDefault := build.Default.GOPATH
gps := filepath.SplitList(gpDefault)

return strings.Replace(s, "$GOPATH", gps[0], -1)
}
2 changes: 1 addition & 1 deletion pkg/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ orderers:

# tlsCACerts:
# Certificate location absolute path
# path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
# path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem

#
# List of peers to send various requests to, including endorsement, query
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ func teardown() {
}

func crossCheckWithViperConfig(expected string, actual string, message string, t *testing.T) {
expected = strings.Replace(expected, "$GOPATH", "", -1)
if !strings.HasSuffix(actual, expected) {
expected = substPathVars(expected)
if actual != expected {
t.Fatalf(message)
}
}
Expand Down
93 changes: 93 additions & 0 deletions pkg/config/subst.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package config

import (
"bytes"
"go/build"
"path/filepath"
"strings"

"github.com/hyperledger/fabric-sdk-go/test/metadata"
)

// goPath returns the current GOPATH. If the system
// has multiple GOPATHs then the first is used.
func goPath() string {
gpDefault := build.Default.GOPATH
gps := filepath.SplitList(gpDefault)

return gps[0]
}

// substPathVars replaces instances of '${VARNAME}' (eg ${GOPATH}) with the variable.
// As a special case, $GOPATH is also replaced.
// NOTE: this function currently only performs substitution when the path string starts with $
// as the path variables are intended to assist with testing.
func substPathVars(path string) string {
if !strings.HasPrefix(path, "$") {
return path
}

splits := strings.Split(path, "$")

// Due to the first check above, the following code is currently not possible:
//if len(splits) == 1 && path == splits[0] {
// // No variables are in the path
// return path
//}

var buffer bytes.Buffer
buffer.WriteString(splits[0]) // first split precedes the first $ so should always be written
for _, s := range splits[1:] {
// special case for GOPATH
if strings.HasPrefix(s, "GOPATH") {
buffer.WriteString(goPath())
buffer.WriteString(s[6:]) // Skip "GOPATH"
continue
}

if !strings.HasPrefix(s, "{") {
// not a variable
buffer.WriteString("$")
buffer.WriteString(s)
continue
}

endPos := strings.Index(s, "}") // not worrying about embedded '{'
if endPos == -1 {
// not a variable
buffer.WriteString("$")
buffer.WriteString(s)
continue
}

subs, ok := substVar(s[1:endPos]) // fix if not ASCII variable names
if !ok {
// not a variable
buffer.WriteString("$")
buffer.WriteString(s)
continue
}

buffer.WriteString(subs)
buffer.WriteString(s[endPos+1:]) // fix if not ASCII variable names
}
return buffer.String()
}

// substVar returns the substituted variable
func substVar(v string) (s string, ok bool) {
// TODO: optimize if the number of variable names grows
switch v {
case "GOPATH":
return goPath(), true
case "CRYPTOCONFIG_FIXTURES_PATH":
return metadata.CryptoConfigPath, true
}
return "", false
}
Loading

0 comments on commit 3651028

Please sign in to comment.