github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/common/mocks/msp/noopmsp_test.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package msp 18 19 import "testing" 20 21 func TestNoopMSP(t *testing.T) { 22 noopmsp := NewNoopMsp() 23 24 id, err := noopmsp.GetDefaultSigningIdentity() 25 if err != nil { 26 t.Fatalf("GetSigningIdentity should have succeeded") 27 return 28 } 29 30 serializedID, err := id.Serialize() 31 if err != nil { 32 t.Fatalf("Serialize should have succeeded") 33 return 34 } 35 36 idBack, err := noopmsp.DeserializeIdentity(serializedID) 37 if err != nil { 38 t.Fatalf("DeserializeIdentity should have succeeded") 39 return 40 } 41 42 msg := []byte("foo") 43 sig, err := id.Sign(msg) 44 if err != nil { 45 t.Fatalf("Sign should have succeeded") 46 return 47 } 48 49 err = id.Verify(msg, sig) 50 if err != nil { 51 t.Fatalf("The signature should be valid") 52 return 53 } 54 55 err = idBack.Verify(msg, sig) 56 if err != nil { 57 t.Fatalf("The signature should be valid") 58 return 59 } 60 }