Skip to content

Commit

Permalink
Merge pull request #1954 from gromeroar/verify-eca-tests
Browse files Browse the repository at this point in the history
ECA Tests Verification - Adding tests to module
  • Loading branch information
srderson committed Jun 24, 2016
2 parents 474bf39 + e1a0d9e commit c242ae4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions membersrvc/ca/eca.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,21 @@ func (ecap *ECAP) ReadCertificatePair(ctx context.Context, in *pb.ECertReadReq)
rows, err := ecap.eca.readCertificates(in.Id.Id)
defer rows.Close()

hasResults := false
var certs [][]byte
if err == nil {
for rows.Next() {
hasResults = true
var raw []byte
err = rows.Scan(&raw)
certs = append(certs, raw)
}
err = rows.Err()
}

if !hasResults {
return nil, errors.New("No certificates for the given identity were found.")
}
return &pb.CertPair{Sign: certs[0], Enc: certs[1]}, err
}

Expand Down
40 changes: 39 additions & 1 deletion membersrvc/ca/eca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,54 @@ func TestReadCertificatePair(t *testing.T) {
}

func TestReadCertificatePairBadIdentity(t *testing.T) {
t.SkipNow() //need to fix error
ecap := &ECAP{eca}

req := &pb.ECertReadReq{Id: &pb.Identity{Id: "badUser"}}

_, err := ecap.ReadCertificatePair(context.Background(), req)

if err == nil {
t.Error("The query result searching by an invalid user identity should have been empty. ")
}

}

func TestReadCertificateByHash(t *testing.T) {
ecap := &ECAP{eca}

req := &pb.ECertReadReq{Id: &pb.Identity{Id: testUser.enrollID}}

cert, err := ecap.ReadCertificatePair(context.Background(), req)

if err != nil {
t.Fatalf("Failed to read certificate pair: [%s]", err.Error())
}

hash := primitives.NewHash()
raw, _ := proto.Marshal(cert)
hash.Write(raw)

hashReq := &pb.Hash{Hash: hash.Sum(nil)}

certByHash, _ := ecap.ReadCertificateByHash(context.Background(), hashReq)

if certByHash == nil {
t.Error("A. ")
}

}

func TestReadCertificateByInvalidHash(t *testing.T) {
ecap := &ECAP{eca}

req := &pb.Hash{Hash: nil}

_, err := ecap.ReadCertificateByHash(context.Background(), req)

if err == nil {
t.Error("The query result searching by an invalid hash value should have been empty. ")
}

}

func TestReadUserSet(t *testing.T) {
Expand Down

0 comments on commit c242ae4

Please sign in to comment.