ListRepositoriesController { @RequestMapping(params = "logout=true") public String logoutBeforeListRepositories(@RequestParam final boolean logout, @RequestParam final String repositoryName, @ModelAttribute final UserContext userContext, final Model model) { if (!application.isConfigured()) { logger.debug("sventon not configured, redirecting to '/repos/listconfigs'"); return "redirect:/repos/listconfigs"; } if (logout && RepositoryName.isValid(repositoryName)) { final UserRepositoryContext userRepositoryContext = userContext.getUserRepositoryContext(new RepositoryName(repositoryName)); if (userRepositoryContext != null) { logger.debug("Clear credential for repository " + repositoryName); userRepositoryContext.clearCredentials(); } } return listRepositoriesOrShowIfOnlyOne(model); } @Autowired  ListRepositoriesController(final Application application); @RequestMapping(params = "logout=true") String logoutBeforeListRepositories(@RequestParam final boolean logout, @RequestParam final String repositoryName,
                                             @ModelAttribute final UserContext userContext, final Model model); @RequestMapping(method = RequestMethod.GET) String listRepositoriesOrShowIfOnlyOne(final Model model);  }
@Test public void logout() throws Exception { final ListRepositoriesController controller = new ListRepositoriesController(application); application.addConfiguration(createTestRepository("test1")); application.addConfiguration(createTestRepository("test2")); application.setConfigured(true); final ExtendedModelMap map = new ExtendedModelMap(); String view = controller.logoutBeforeListRepositories(true, "repo1", userContext, map); assertEquals("listRepositories", view); assertFalse(userContext.getUserRepositoryContext(new RepositoryName("repo1")).hasCredentials()); assertTrue(userContext.getUserRepositoryContext(new RepositoryName("repo2")).hasCredentials()); }
@Test public void logoutIncorrectRepositoryName() throws Exception { final ListRepositoriesController controller = new ListRepositoriesController(application); application.addConfiguration(createTestRepository("test1")); application.addConfiguration(createTestRepository("test2")); application.setConfigured(true); final ExtendedModelMap map = new ExtendedModelMap(); String view = controller.logoutBeforeListRepositories(true, "Pingu", userContext, map); assertEquals("listRepositories", view); assertTrue(userContext.getUserRepositoryContext(new RepositoryName("repo1")).hasCredentials()); assertTrue(userContext.getUserRepositoryContext(new RepositoryName("repo2")).hasCredentials()); }
@Test public void logoutNoRepositoryName() throws Exception { final ListRepositoriesController controller = new ListRepositoriesController(application); application.addConfiguration(createTestRepository("test1")); application.addConfiguration(createTestRepository("test2")); application.setConfigured(true); final ExtendedModelMap map = new ExtendedModelMap(); String view = controller.logoutBeforeListRepositories(true, "", userContext, map); assertEquals("listRepositories", view); assertTrue(userContext.getUserRepositoryContext(new RepositoryName("repo1")).hasCredentials()); assertTrue(userContext.getUserRepositoryContext(new RepositoryName("repo2")).hasCredentials()); }