Skip to content

Commit

Permalink
[FAB-7849] Hide deprecated methods behind build tag
Browse files Browse the repository at this point in the history
Change-Id: Ic2de488ce73ab7d01b89a91ec72e9a7e3ce20347
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Feb 25, 2018
1 parent c898ec5 commit 07c145d
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 148 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ THIRDPARTY_FABRIC_COMMIT ?= v1.1.0-alpha
# Force removal of images in cleanup (overridable)
FIXTURE_DOCKER_REMOVE_FORCE ?= false

# Options for exercising unit tests (overridable)
FABRIC_DEPRECATED_UNITTEST ?= false

# Code levels to exercise integration/e2e tests against (overridable)
FABRIC_STABLE_INTTEST ?= true
FABRIC_STABLE_PKCS11_INTTEST ?= false
Expand Down Expand Up @@ -129,6 +132,7 @@ GO_DEP_COMMIT := v0.4.1
ifdef JENKINS_URL
export FABRIC_SDKGO_DEPEND_INSTALL=true

FABRIC_DEPRECATED_UNITTEST := true
FABRIC_STABLE_INTTEST := true
FABRIC_STABLE_PKCS11_INTTEST := true
FABRIC_PREV_INTTEST := true
Expand Down Expand Up @@ -202,6 +206,9 @@ build-softhsm2-image:
.PHONY: unit-test
unit-test: checks depend populate
@FABRIC_SDKGO_CODELEVEL=$(FABRIC_CODELEVEL_UNITTEST_TAG) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_CODELEVEL_UNITTEST_VER) $(TEST_SCRIPTS_PATH)/unit.sh
ifeq ($(FABRIC_DEPRECATED_UNITTEST),true)
@GO_TAGS="$(GO_TAGS) deprecated" GO_TESTFLAGS="$(GO_TESTFLAGS) -count=1" FABRIC_SDKGO_CODELEVEL=$(FABRIC_CODELEVEL_UNITTEST_TAG) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_CODELEVEL_UNITTEST_VER) $(TEST_SCRIPTS_PATH)/unit.sh
endif

.PHONY: unit-tests
unit-tests: unit-test
Expand All @@ -210,7 +217,6 @@ unit-tests: unit-test
unit-tests-pkcs11: checks depend populate
@FABRIC_SDKGO_CODELEVEL=$(FABRIC_CODELEVEL_UNITTEST_TAG) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_CODELEVEL_UNITTEST_VER) $(TEST_SCRIPTS_PATH)/unit-pkcs11.sh


.PHONY: integration-tests-stable
integration-tests-stable: clean depend populate
@cd $(FIXTURE_DOCKERENV_PATH) && \
Expand Down
2 changes: 2 additions & 0 deletions pkg/fab/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build deprecated

/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions pkg/fab/client_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build deprecated

/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
Expand Down
8 changes: 4 additions & 4 deletions pkg/fab/events/eventmocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
fcConsumer "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/events/consumer"
"github.com/hyperledger/fabric-sdk-go/pkg/context"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
client "github.com/hyperledger/fabric-sdk-go/pkg/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
ledger_util "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/core/ledger/util"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -109,10 +108,11 @@ func (mec *mockEventClient) Stop() error {
}

func createMockedEventHub() (*EventHub, *mockEventClientFactory, error) {
client := client.NewClient(mocks.NewMockConfig())
user := mocks.NewMockUser("user")
fabCtx := mocks.NewMockContext(user)
ctx := Context{
ProviderContext: client,
IdentityContext: client.IdentityContext(),
ProviderContext: fabCtx,
IdentityContext: fabCtx,
}
eventHub, err := New(ctx)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/fab/orderer/deprecated.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build deprecated

/*
Copyright SecureKey Technologies Inc., Unchain B.V. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions pkg/fab/orderer/deprecated_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build deprecated

/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
Expand Down
10 changes: 6 additions & 4 deletions pkg/fab/orderer/orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package orderer

import (
"crypto/x509"
"fmt"
"net"
"reflect"
Expand Down Expand Up @@ -351,13 +352,14 @@ func TestBroadcastBadDial(t *testing.T) {
config := mock_core.NewMockConfig(mockCtrl)

config.EXPECT().TimeoutOrDefault(core.OrdererConnection).Return(time.Second * 1)
config.EXPECT().TLSCACertPool(gomock.Any()).Return(nil, errors.New("error adding cert to pool")).AnyTimes()
config.EXPECT().TLSCACertPool(gomock.Any()).Return(x509.NewCertPool(), nil).AnyTimes()

orderer, _ := NewOrderer("grpc://127.0.0.1:0", "", "", config, kap)
orderer, err := New(config, WithURL("grpc://127.0.0.1:0"))
assert.Nil(t, err)
orderer.grpcDialOption = append(orderer.grpcDialOption, grpc.WithBlock())
orderer.secured = true
orderer.allowInsecure = true
_, err := orderer.SendBroadcast(&fab.SignedEnvelope{})
_, err = orderer.SendBroadcast(&fab.SignedEnvelope{})
assert.NotNil(t, err)

if err == nil || !strings.Contains(err.Error(), "CONNECTION_FAILED") {
Expand Down Expand Up @@ -519,7 +521,7 @@ func TestNewOrdererFromConfig(t *testing.T) {
URL: "",
GRPCOptions: grpcOpts,
}
_, err := NewOrdererFromConfig(ordererConfig, mocks.NewMockConfig())
_, err := New(mocks.NewMockConfig(), FromOrdererConfig(ordererConfig))
if err != nil {
t.Fatalf("Failed to get new orderer from config%v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/fab/peer/deprecated.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build deprecated

/*
Copyright SecureKey Technologies Inc., Unchain B.V. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions pkg/fab/peer/deprecated_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build deprecated

/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions pkg/fabsdk/deprecated.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build deprecated

/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions pkg/fabsdk/deprecated_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build deprecated

/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
Expand Down
138 changes: 0 additions & 138 deletions test/integration/fab/fabric_ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,102 +7,17 @@ SPDX-License-Identifier: Apache-2.0
package fab

import (
"bytes"
"math/rand"
"strconv"
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"

"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
cryptosuite "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite/bccsp/sw"
client "github.com/hyperledger/fabric-sdk-go/pkg/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/identity"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/identitymgr"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/peer"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/signingmgr"
)

const (
org1Name = "Org1"
org2Name = "Org2"
)

// This test loads/enrols an admin user
// Using the admin, it registers, enrols, and revokes a test user
func TestRegisterEnrollRevoke(t *testing.T) {
mspID, err := testFabricConfig.MspID(org1Name)
if err != nil {
t.Fatalf("GetMspId() returned error: %v", err)
}

caConfig, err := testFabricConfig.CAConfig(org1Name)
if err != nil {
t.Fatalf("GetCAConfig returned error: %s", err)
}

client := client.NewClient(testFabricConfig)

cryptoSuiteProvider, err := cryptosuite.GetSuiteByConfig(testFabricConfig)
if err != nil {
t.Fatalf("Failed getting cryptosuite from config : %s", err)
}

stateStorePath := "/tmp/enroll_user"
client.SetCryptoSuite(cryptoSuiteProvider)
stateStore, err := identity.NewCertFileUserStore(stateStorePath, cryptoSuiteProvider)
if err != nil {
t.Fatalf("CreateNewFileKeyValueStore return error[%s]", err)
}
client.SetStateStore(stateStore)

idmgr, err := identitymgr.New(org1Name, testFabricConfig, cryptoSuiteProvider)
if err != nil {
t.Fatalf("NewFabricCAClient return error: %v", err)
}

// Register a random user
userName := createRandomName()
registerRequest := fab.RegistrationRequest{
Name: userName,
Type: "user",
Affiliation: "org1.department1",
CAName: caConfig.CAName,
}
enrolmentSecret, err := idmgr.Register(&registerRequest)
if err != nil {
t.Fatalf("Error from Register: %s", err)
}
t.Logf("Registered User: %s, Secret: %s", userName, enrolmentSecret)
// Enrol the previously registered user
ekey, ecert, err := idmgr.Enroll(userName, enrolmentSecret)
if err != nil {
t.Fatalf("Error enroling user: %s", err.Error())
}
//re-enroll
t.Logf("** Attempt to re-enrolled user: '%s'", userName)
//create new user object and set certificate and private key of the previously enrolled user
enrolleduser := identity.NewUser(mspID, userName)
enrolleduser.SetEnrollmentCertificate(ecert)
enrolleduser.SetPrivateKey(ekey)
//reenroll
_, reenrollCert, err := idmgr.Reenroll(enrolleduser)
if err != nil {
t.Fatalf("Error Reenroling user: %s", err.Error())
}
t.Logf("** User '%s' was re-enrolled", userName)
if bytes.Equal(ecert, reenrollCert) {
t.Fatalf("Error Reenroling user. Enrollmet and Reenrollment certificates are the same.")
}

revokeRequest := fab.RevocationRequest{Name: userName, CAName: "ca.org1.example.com"}
_, err = idmgr.Revoke(&revokeRequest)
if err != nil {
t.Fatalf("Error from Revoke: %s", err)
}

}

func TestEnrollOrg2(t *testing.T) {

cryptoSuiteProvider, err := cryptosuite.GetSuiteByConfig(testFabricConfig)
Expand All @@ -126,56 +41,3 @@ func TestEnrollOrg2(t *testing.T) {
t.Fatalf("Expected enrol to return an enrolment cert")
}
}

func TestEnrollAndTransact(t *testing.T) {
mspID, err := testFabricConfig.MspID(org1Name)
if err != nil {
t.Fatalf("GetMspId() returned error: %v", err)
}
peers, err := testFabricConfig.PeersConfig(org1Name)
if err != nil {
t.Fatalf("Failed to get peer config : %s", err)
}
networkPeer := &core.NetworkPeer{PeerConfig: peers[0], MspID: mspID}
testPeer, err := peer.New(testFabricConfig, peer.FromPeerConfig(networkPeer))
if err != nil {
t.Fatalf("Failed to create peer from config : %s", err)
}

cryptoSuiteProvider, err := cryptosuite.GetSuiteByConfig(testFabricConfig)
if err != nil {
t.Fatalf("Failed getting cryptosuite from config : %s", err)
}
signingManager, err := signingmgr.New(cryptoSuiteProvider, testFabricConfig)
if err != nil {
t.Fatalf("Could not create signing manager: %s", err)
}

caClient, err := identitymgr.New(org1Name, testFabricConfig, cryptoSuiteProvider)
if err != nil {
t.Fatalf("NewFabricCAClient returned error: %v", err)
}

key, cert, err := caClient.Enroll("admin", "adminpw")
if err != nil {
t.Fatalf("Enroll returned error: %v", err)
}

myUser := identity.NewUser(mspID, "myUser")
myUser.SetEnrollmentCertificate(cert)
myUser.SetPrivateKey(key)

testClient := client.NewClient(testFabricConfig)
testClient.SetCryptoSuite(cryptoSuiteProvider)
testClient.SetIdentityContext(myUser)
testClient.SetSigningManager(signingManager)

_, err = testClient.QueryChannels(testPeer)
if err != nil {
t.Fatalf("Failed to query with enrolled user : %s", err)
}
}

func createRandomName() string {
return "user" + strconv.Itoa(rand.Intn(500000))
}
Loading

0 comments on commit 07c145d

Please sign in to comment.