Redmine#4848: fix peers, peerleader, and peerleaders functions and add tests

see https://cfengine.com/dev/issues/4848