-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-17095] Pretty print peer identities in gossip
This change set makes gossip identities be printed as attributes of certificates and not decimal byte arrays. Change-Id: I18236e33494cabdc9dd5c46e5db1edae2959da59 Signed-off-by: yacovm <yacovm@il.ibm.com>
- Loading branch information
Showing
3 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"encoding/pem" | ||
"io/ioutil" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric-protos-go/msp" | ||
"github.com/hyperledger/fabric/protoutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPeerIdentityTypeString(t *testing.T) { | ||
certBytes, err := ioutil.ReadFile(filepath.Join("testdata", "peer.pem")) | ||
assert.NoError(t, err) | ||
|
||
for _, testCase := range []struct { | ||
description string | ||
identity PeerIdentityType | ||
expectedOut string | ||
}{ | ||
{ | ||
description: "non serialized identity", | ||
identity: PeerIdentityType("some garbage"), | ||
expectedOut: "non SerializedIdentity: c29tZSBnYXJiYWdl", | ||
}, | ||
{ | ||
description: "non PEM identity", | ||
identity: PeerIdentityType(protoutil.MarshalOrPanic(&msp.SerializedIdentity{ | ||
Mspid: "SampleOrg", | ||
IdBytes: []byte{1, 2, 3}, | ||
})), | ||
expectedOut: "non PEM encoded identity: CglTYW1wbGVPcmcSAwECAw==", | ||
}, | ||
{ | ||
description: "non x509 identity", | ||
identity: PeerIdentityType(protoutil.MarshalOrPanic(&msp.SerializedIdentity{ | ||
Mspid: "SampleOrg", | ||
IdBytes: pem.EncodeToMemory(&pem.Block{ | ||
Type: "CERTIFICATE", | ||
Bytes: []byte{1, 2, 3}, | ||
}), | ||
})), | ||
expectedOut: `non x509 identity: CglTYW1wbGVPcmcSOy0tLS0tQkVHSU4gQ0VSVElGSUNBVEUtLS0tLQpBUUlECi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K`, | ||
}, | ||
{ | ||
description: "x509 identity", | ||
identity: PeerIdentityType(protoutil.MarshalOrPanic(&msp.SerializedIdentity{ | ||
Mspid: "SampleOrg", | ||
IdBytes: certBytes, | ||
})), | ||
expectedOut: `{"CN":"peer0.org1.example.com","Issuer-CN":"ca.org1.example.com","Issuer-L-ST-C":"[San Francisco]-[]-[US]","Issuer-OU":["COP"],"L-ST-C":"[San Francisco]-[]-[US]","MSP":"SampleOrg","OU":["COP"]}`, | ||
}, | ||
} { | ||
t.Run(testCase.description, func(t *testing.T) { | ||
assert.Equal(t, testCase.identity.String(), testCase.expectedOut) | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICNjCCAd2gAwIBAgIRAMnf9/dmV9RvCCVw9pZQUfUwCgYIKoZIzj0EAwIwgYEx | ||
CzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4g | ||
RnJhbmNpc2NvMRkwFwYDVQQKExBvcmcxLmV4YW1wbGUuY29tMQwwCgYDVQQLEwND | ||
T1AxHDAaBgNVBAMTE2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTcxMTEyMTM0MTEx | ||
WhcNMjcxMTEwMTM0MTExWjBpMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv | ||
cm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEMMAoGA1UECxMDQ09QMR8wHQYD | ||
VQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0D | ||
AQcDQgAEZ8S4V71OBJpyMIVZdwYdFXAckItrpvSrCf0HQg40WW9XSoOOO76I+Umf | ||
EkmTlIJXP7/AyRRSRU38oI8Ivtu4M6NNMEswDgYDVR0PAQH/BAQDAgeAMAwGA1Ud | ||
EwEB/wQCMAAwKwYDVR0jBCQwIoAginORIhnPEFZUhXm6eWBkm7K7Zc8R4/z7LW4H | ||
ossDlCswCgYIKoZIzj0EAwIDRwAwRAIgVikIUZzgfuFsGLQHWJUVJCU7pDaETkaz | ||
PzFgsCiLxUACICgzJYlW7nvZxP7b6tbeu3t8mrhMXQs956mD4+BoKuNI | ||
-----END CERTIFICATE----- |