ticket:3 add middleware, fix test