MCPcopy
hub / github.com/hyperledger/fabric / TestEnvelopeAsSignedData

Function TestEnvelopeAsSignedData

protoutil/signeddata_test.go:87–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestEnvelopeAsSignedData(t *testing.T) {
88 identity := []byte("Foo")
89 sig := []byte("Bar")
90
91 shdrbytes, err := proto.Marshal(&common.SignatureHeader{Creator: identity})
92 if err != nil {
93 t.Fatalf("%s", err)
94 }
95
96 env := &common.Envelope{
97 Payload: marshalOrPanic(&common.Payload{
98 Header: &common.Header{
99 SignatureHeader: shdrbytes,
100 },
101 }),
102 Signature: sig,
103 }
104
105 signedData, err := protoutil.EnvelopeAsSignedData(env)
106 if err != nil {
107 t.Fatalf("Unexpected error converting envelope to SignedData: %s", err)
108 }
109
110 if len(signedData) != 1 {
111 t.Fatalf("Expected 1 entry of signed data, but got %d", len(signedData))
112 }
113
114 if !bytes.Equal(signedData[0].Identity, identity) {
115 t.Errorf("Wrong identity bytes")
116 }
117 if !bytes.Equal(signedData[0].Data, env.Payload) {
118 t.Errorf("Wrong data bytes")
119 }
120 if !bytes.Equal(signedData[0].Signature, sig) {
121 t.Errorf("Wrong data bytes")
122 }
123}
124
125func TestLogMessageForSerializedIdentity(t *testing.T) {
126 pem, err := readPemFile(filepath.Join("testdata", "peer-expired.pem"))

Callers

nothing calls this directly

Calls 6

EnvelopeAsSignedDataFunction · 0.92
FatalfMethod · 0.80
marshalOrPanicFunction · 0.70
MarshalMethod · 0.65
ErrorfMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected