MDL-46099 session: fix references of session globals and add test coverage for session code