@Test public void shouldContinueWithConfigSaveIfUserIsGroupAdmin() { when(goConfigService.isUserAdmin(currentUser)).thenReturn(false); when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(true); when(entityHashingService.md5ForEntity(any(PackageRepository.class))).thenReturn("md5"); UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand( goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, repoId); assertThat(command.canContinue(cruiseConfig), is(true)); }
@Test public void shouldNotContinueIfTheUserDontHavePermissionsToOperateOnPackageRepositories() throws Exception { when(goConfigService.isUserAdmin(currentUser)).thenReturn(false); UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand( goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, repoId); HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult(); expectedResult.unauthorized( LocalizedMessage.string("UNAUTHORIZED_TO_EDIT"), HealthStateType.unauthorised()); assertThat(command.canContinue(cruiseConfig), is(false)); assertThat(result, is(expectedResult)); }
@Test public void shouldNotContinueIfRepoIdIsChanged() { when(goConfigService.isUserAdmin(currentUser)).thenReturn(true); when(goConfigService.getPackageRepository(repoId)).thenReturn(oldPackageRepo); when(entityHashingService.md5ForEntity(oldPackageRepo)).thenReturn("md5"); HttpLocalizedOperationResult expectResult = new HttpLocalizedOperationResult(); expectResult.unprocessableEntity( LocalizedMessage.string("PACKAGE_REPOSITORY_ID_CHANGED", "repository")); UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand( goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, "old-repo-id"); assertThat(command.canContinue(cruiseConfig), is(false)); assertThat(result, is(expectResult)); }
@Test public void shouldNotContinueIfTheUserSubmittedStaleEtag() throws Exception { when(goConfigService.isUserAdmin(currentUser)).thenReturn(true); when(goConfigService.getPackageRepository(repoId)).thenReturn(oldPackageRepo); when(entityHashingService.md5ForEntity(oldPackageRepo)).thenReturn("foobar"); HttpLocalizedOperationResult expectResult = new HttpLocalizedOperationResult(); expectResult.stale( LocalizedMessage.string("STALE_RESOURCE_CONFIG", "Package Repository", repoId)); UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand( goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, repoId); assertThat(command.canContinue(cruiseConfig), is(false)); assertThat(result, is(expectResult)); }