fix blocking query for Keyring.List RPC (#13384)

The blocking query for `Keyring.List` appended the keys for each pass
through the blocking query to the response. This results in mulitple
copies of keys in the response. Overwrite the `reply.Keys` field on
each pass through the blocking query to ensure we only get the
expected page of responses.
This commit is contained in:
Tim Gross
2022-06-20 11:48:13 -04:00
parent 01d19d71d1
commit ca300727da
2 changed files with 4 additions and 3 deletions

View File

@@ -107,14 +107,16 @@ func (k *Keyring) List(args *structs.KeyringListRootKeyMetaRequest, reply *struc
return err
}
keys := []*structs.RootKeyMeta{}
for {
raw := iter.Next()
if raw == nil {
break
}
keyMeta := raw.(*structs.RootKeyMeta)
reply.Keys = append(reply.Keys, keyMeta)
keys = append(keys, keyMeta)
}
reply.Keys = keys
return k.srv.replySetIndex(state.TableRootKeyMeta, &reply.QueryMeta)
},
}

View File

@@ -79,14 +79,13 @@ func TestKeyringEndpoint_CRUD(t *testing.T) {
}()
updateReq.RootKey.Meta.CreateTime = time.Now()
err = msgpackrpc.CallWithCodec(codec, "Keyring.Update", updateReq, &updateResp)
require.NoError(t, err)
require.NotEqual(t, uint64(0), updateResp.Index)
// wait for the blocking query to complete and check the response
wg.Wait()
require.Greater(t, listResp.Index, getResp.Index)
require.Equal(t, listResp.Index, updateResp.Index)
require.Len(t, listResp.Keys, 2) // bootstrap + new one
// Delete the key and verify that it's gone