Skip to content

Commit

Permalink
[FAB-4329] SDK Go - externalize CA root in mock test
Browse files Browse the repository at this point in the history
Change-Id: I93dae990f2349f05eb682b7ca4e8bb413949b02e
Signed-off-by: Firas Qutishat <[email protected]>
  • Loading branch information
fqutishat committed Jun 2, 2017
1 parent b87b5ec commit 9c0f71b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
20 changes: 20 additions & 0 deletions fabric-client/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ import (

var testAddress = "0.0.0.0:5244"

var validRootCA = `-----BEGIN CERTIFICATE-----
MIICYjCCAgmgAwIBAgIUB3CTDOU47sUC5K4kn/Caqnh114YwCgYIKoZIzj0EAwIw
fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK
BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMDEyMTkzMTAw
WhcNMjExMDExMTkzMTAwWjB/MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv
cm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEChMWSW50ZXJuZXQg
V2lkZ2V0cywgSW5jLjEMMAoGA1UECxMDV1dXMRQwEgYDVQQDEwtleGFtcGxlLmNv
bTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKIH5b2JaSmqiQXHyqC+cmknICcF
i5AddVjsQizDV6uZ4v6s+PWiJyzfA/rTtMvYAPq/yeEHpBUB1j053mxnpMujYzBh
MA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBQXZ0I9
qp6CP8TFHZ9bw5nRtZxIEDAfBgNVHSMEGDAWgBQXZ0I9qp6CP8TFHZ9bw5nRtZxI
EDAKBggqhkjOPQQDAgNHADBEAiAHp5Rbp9Em1G/UmKn8WsCbqDfWecVbZPQj3RK4
oG5kQQIgQAe4OOKYhJdh3f7URaKfGTf492/nmRmtK+ySKjpHSrU=
-----END CERTIFICATE-----
`

func TestChainMethods(t *testing.T) {
client := NewClient()
chain, err := NewChain("testChain", client)
Expand Down Expand Up @@ -268,6 +285,7 @@ func TestChainInitializeFromOrderer(t *testing.T) {
org2MSPID,
},
OrdererAddress: "localhost:7054",
RootCA: validRootCA,
},
Index: 0,
LastConfigIndex: 0,
Expand Down Expand Up @@ -321,6 +339,7 @@ func TestOrganizationUnits(t *testing.T) {
org2MSPID,
},
OrdererAddress: "localhost:7054",
RootCA: validRootCA,
},
Index: 0,
LastConfigIndex: 0,
Expand Down Expand Up @@ -371,6 +390,7 @@ func TestChainInitializeFromUpdate(t *testing.T) {
org2MSPID,
},
OrdererAddress: "localhost:7054",
RootCA: validRootCA,
},
}

Expand Down
14 changes: 2 additions & 12 deletions fabric-client/mocks/mockdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ limitations under the License.
package mocks

import (
"io/ioutil"
"log"

"github.com/hyperledger/fabric-sdk-go/fabric-client/util"
fabric_config "github.com/hyperledger/fabric/common/config"
ledger_util "github.com/hyperledger/fabric/core/ledger/util"
Expand All @@ -47,6 +44,7 @@ type MockConfigGroupBuilder struct {
ModPolicy string
OrdererAddress string
MSPNames []string
RootCA string
}

// MockConfigBlockBuilder is used to build a mock Chain configuration block
Expand Down Expand Up @@ -260,19 +258,11 @@ func (b *MockConfigGroupBuilder) buildfabricMSPConfig(name string) *mb.FabricMSP
IntermediateCerts: [][]byte{},
OrganizationalUnitIdentifiers: []*mb.FabricOUIdentifier{},
RevocationList: [][]byte{},
RootCerts: [][]byte{b.buildRootCertBytes()},
RootCerts: [][]byte{[]byte(b.RootCA)},
SigningIdentity: nil,
}
}

func (b *MockConfigGroupBuilder) buildRootCertBytes() []byte {
pem, err := ioutil.ReadFile("../test/fixtures/root.pem")
if err != nil {
log.Fatal(err)
}
return pem
}

func (b *MockConfigGroupBuilder) buildBasicConfigPolicy() *common.ConfigPolicy {
return &common.ConfigPolicy{
Version: b.Version,
Expand Down

0 comments on commit 9c0f71b

Please sign in to comment.