Skip to content

Commit

Permalink
[FAB-10419] Incorrect filtering on affiliation
Browse files Browse the repository at this point in the history
SQL query was not constructed correctly around
affiliation filtering. Fixed the SQL query and updated
the test to check for proper results.

Change-Id: Icae9338a5c71ab0046daf09c4f3478d77fc5b681
Signed-off-by: Saad Karim <skarim@us.ibm.com>
  • Loading branch information
Saad Karim committed Jun 1, 2018
1 parent 7c3fc1a commit 5702371
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/certdbaccessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (d *CertDBAccessor) GetCertificates(req server.CertificateRequest, callersA
if callersAffiliation != "" {
getCertificateSQL = "SELECT certificates.pem FROM certificates INNER JOIN users ON users.id = certificates.id"

whereConds = append(whereConds, "users.affiliation = ? OR users.affiliation LIKE ?")
whereConds = append(whereConds, "(users.affiliation = ? OR users.affiliation LIKE ?)")
args = append(args, callersAffiliation)
args = append(args, callersAffiliation+".%")
}
Expand Down
6 changes: 5 additions & 1 deletion lib/certdbaccessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestGetCertificatesDB(t *testing.T) {
certs, err = readRows(rows)
assert.Equal(t, 6, len(certs))

certReq = getCertReq("", "", "", false, false, nil, nil, nil, nil)
certReq = getCertReq("", "1111", "", false, false, nil, nil, nil, nil)
rows, err = ca.certDBAccessor.GetCertificates(certReq, "dept1")
assert.NoError(t, err, "Failed to get certificates from database")
certs, err = readRows(rows)
Expand Down Expand Up @@ -194,6 +194,10 @@ func populateCertificatesTable(t *testing.T, ca *CA) {
}, "testCertificate1", ca)
util.FatalError(t, err, "Failed to insert certificate with serial/AKI")

ca.registry.InsertUser(&spi.UserInfo{
Name: "testCertificate2",
Affiliation: "dept1",
})
err = testInsertCertificate(&certdb.CertificateRecord{
Serial: "1112",
AKI: "9876",
Expand Down

0 comments on commit 5702371

Please sign in to comment.