Skip to content

Commit

Permalink
[FABG-705] fix: override clientTLS in backend
Browse files Browse the repository at this point in the history
Change-Id: Ie9e21b87de864f0961702ed44f8aaa8c8ad05a82
Signed-off-by: ping40 <[email protected]>
  • Loading branch information
ping40 committed Aug 9, 2018
1 parent c0144e2 commit d2e3b47
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
6 changes: 3 additions & 3 deletions pkg/fab/endpointconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ package fab
import (
"crypto/tls"
"crypto/x509"
"math"
"reflect"
"regexp"
"strconv"
"strings"
"time"

"math"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"

"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/multi"
"github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
Expand All @@ -27,8 +29,6 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/lookup"
"github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite"
"github.com/hyperledger/fabric-sdk-go/pkg/util/pathvar"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabsdk/fab")
Expand Down
33 changes: 17 additions & 16 deletions pkg/fab/endpointconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,22 +973,22 @@ func TestTLSClientCertFromPemAndKeyFromFile(t *testing.T) {
clientTLSOverride.Client.Key.Path = pathvar.Subst(keyPath)

clientTLSOverride.Client.Cert.Pem = `-----BEGIN CERTIFICATE-----
MIIC5TCCAkegAwIBAgIUBzAG7MTjO4n9GFkYTkJBnvCInRIwCgYIKoZIzj0EAwQw
MIIC5TCCAkagAwIBAgIUMYhiY5MS3jEmQ7Fz4X/e1Dx33J0wCgYIKoZIzj0EAwQw
gYwxCzAJBgNVBAYTAkNBMRAwDgYDVQQIEwdPbnRhcmlvMRAwDgYDVQQHEwdUb3Jv
bnRvMREwDwYDVQQKEwhsaW51eGN0bDEMMAoGA1UECxMDTGFiMTgw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SAZHIUMhYZjcDi7YEOZ3Fs1h
xKmIxR+TTR2vf9KjgZAwgY0wDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoGCCsG
AQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFDwS3xhpAWs81OVWvZt+iUNL
z26DMB8GA1UdIwQYMBaAFLRasbknomawJKuQGiyKs/RzTCujMBgGA1UdEQQRMA+C
DWZhYnJpY19zZGtfZ28wCgYIKoZIzj0EAwQDgYwAMIGIAkIAk1MxMogtMtNO0rM8
gw2rrxqbW67ulwmMQzp6EJbm/28T2pIoYWWyIwpzrquypI7BOuf8is5b7Jcgn9oz
7sdMTggCQgF7/8ZFl+wikAAPbciIL1I+LyCXKwXosdFL6KMT6/myYjsGNeeDeMbg
3YkZ9DhdH1tN4U/h+YulG/CkKOtUATtQxg==
-----END CERTIFICATE-----`

clientTLSOverride.Client.Key.Pem = ""
Expand All @@ -1014,10 +1014,10 @@ func TestTLSClientCertFromFileAndKeyFromPem(t *testing.T) {
clientTLSOverride.Client.Key.Path = ""
clientTLSOverride.Client.Cert.Pem = ""
clientTLSOverride.Client.Key.Pem = `-----BEGIN EC PRIVATE KEY-----
MIGkAgEBBDAeWRhdAl+olgpLiI9mXHwcgJ1g4NNgPrYFSkkukISeAGfvK348izwG
0Aub948H5IygBwYFK4EEACKhZANiAATJb6oe7bpmnuJwjYMaQX7D2YQ0vLHmRWKs
QSn674xQJ5N8rMHAA/DXtpIMKI5uulot0jJ5xFkpikLGd8+6soQp8pd5tkMqZB0a
nFoUptdom8LjgRus6rnHbXxGqcIN6oA=
MIGkAgEBBDByldj7VTpqTQESGgJpR9PFW9b6YTTde2WN6/IiBo2nW+CIDmwQgmAl
c/EOc9wmgu+gBwYFK4EEACKhZANiAAT6I1CGNrkchIAEmeJGo53XhDsoJwRiohBv
2PotEEGuO6rMyaOupulj2VOj+YtgWw4ZtU49g4Nv6rq1QlKwRYyMwwRJSAZHIUMh
YZjcDi7YEOZ3Fs1hxKmIxR+TTR2vf9I=
-----END EC PRIVATE KEY-----`

backends, err := overrideClientTLSInBackend(configBackend, &clientTLSOverride)
Expand Down Expand Up @@ -1357,6 +1357,7 @@ func overrideClientTLSInBackend(backend core.ConfigBackend, tlsCerts *endpoint.M
if err != nil {
return nil, err
}
endpointEntity.Client.TLSCerts.Client = tlsCerts.Client

backendOverride := mocks.MockConfigBackend{}
backendOverride.KeyValueMap = make(map[string]interface{})
Expand Down
4 changes: 2 additions & 2 deletions pkg/fab/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ SPDX-License-Identifier: Apache-2.0
package fab

import (
"strings"
"testing"

"strings"
"github.com/stretchr/testify/assert"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/stretchr/testify/assert"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion pkg/fab/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"crypto/tls"
"time"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/pkg/errors"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
)

// EndpointConfigOptions represents EndpointConfig interface with overridable interface functions
Expand Down

0 comments on commit d2e3b47

Please sign in to comment.