github.com/silveraid/fabric-ca@v1.1.0-preview.0.20180127000700-71974f53ab08/lib/identity_test.go (about) 1 /* 2 Copyright IBM Corp. 2016 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 lib 18 19 import ( 20 "io/ioutil" 21 "testing" 22 23 "github.com/hyperledger/fabric-ca/api" 24 "github.com/hyperledger/fabric-ca/util" 25 "github.com/hyperledger/fabric/bccsp/factory" 26 ) 27 28 func getIdentity() *Identity { 29 key, _ := util.ImportBCCSPKeyFromPEM("../tesdata/ec-key.pem", factory.GetDefault(), true) 30 cert, _ := ioutil.ReadFile("../tesdata/ec.pem") 31 id := newIdentity(nil, "test", key, cert) 32 return id 33 } 34 35 func TestIdentity(t *testing.T) { 36 id := getIdentity() 37 testGetName(id, t) 38 testGetECert(id, t) 39 } 40 41 func TestBadStoreIdentity(t *testing.T) { 42 id := &Identity{} 43 err := id.Store() 44 if err == nil { 45 t.Error("TestBadStoreIdentity passed but should have failed") 46 } 47 } 48 49 func TestBadRegistration(t *testing.T) { 50 id := &Identity{} 51 req := &api.RegistrationRequest{} 52 _, err := id.Register(req) 53 if err == nil { 54 t.Error("Empty registration request should have failed") 55 } 56 } 57 58 func testGetName(id *Identity, t *testing.T) { 59 name := id.GetName() 60 if name != "test" { 61 t.Error("Incorrect name retrieved") 62 } 63 } 64 65 func testGetECert(id *Identity, t *testing.T) { 66 ecert := id.GetECert() 67 if ecert == nil { 68 t.Error("No ECert was returned") 69 } 70 }