relay: some more refactoring and add SASL test