diff options
author | Pierre <pierre.guillot@sonarsource.com> | 2021-08-12 14:47:56 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-08-19 20:08:14 +0000 |
commit | 99542044a382aa87d682f3544e9004b0d2a559d1 (patch) | |
tree | dd5c62a5fc56ad6edf2d6c51e5447975ae531ece /server/sonar-webserver-es | |
parent | f660a790f6d88b5d68bf1f1677cd2bc0ae657309 (diff) | |
download | sonarqube-99542044a382aa87d682f3544e9004b0d2a559d1.tar.gz sonarqube-99542044a382aa87d682f3544e9004b0d2a559d1.zip |
SONAR-15142 add 'name' and 'key' in component context for Audit
Diffstat (limited to 'server/sonar-webserver-es')
-rw-r--r-- | server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java index 4c9eaacef72..20fb3bf8fb9 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java @@ -19,10 +19,10 @@ */ package org.sonar.server.permission.index; +import java.util.Collection; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.System2; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -45,7 +45,6 @@ import static org.sonar.api.web.UserRole.ADMIN; import static org.sonar.api.web.UserRole.USER; import static org.sonar.server.es.ProjectIndexer.Cause.PERMISSION_CHANGE; import static org.sonar.server.permission.index.IndexAuthorizationConstants.TYPE_AUTHORIZATION; -import java.util.Collection; public class PermissionIndexerTest { @@ -91,6 +90,26 @@ public class PermissionIndexerTest { } @Test + public void deletion_resilience_will_deindex_projects() { + ComponentDto project1 = createUnindexedPublicProject(); + ComponentDto project2 = createUnindexedPublicProject(); + // UserDto user1 = db.users().insertUser(); + indexOnStartup(); + assertThat(es.countDocuments(INDEX_TYPE_FOO_AUTH)).isEqualTo(2); + + // Simulate a indexation issue + db.getDbClient().purgeDao().deleteProject(db.getSession(), project1.uuid(), PROJECT, project1.name(), project1.getKey()); + underTest.prepareForRecovery(db.getSession(), asList(project1.uuid()), ProjectIndexer.Cause.PROJECT_DELETION); + assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isEqualTo(1); + Collection<EsQueueDto> esQueueDtos = db.getDbClient().esQueueDao().selectForRecovery(db.getSession(), Long.MAX_VALUE, 2); + + underTest.index(db.getSession(), esQueueDtos); + + assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isZero(); + assertThat(es.countDocuments(INDEX_TYPE_FOO_AUTH)).isEqualTo(1); + } + + @Test public void indexOnStartup_grants_access_to_user() { ComponentDto project = createAndIndexPrivateProject(); UserDto user1 = db.users().insertUser(); @@ -295,7 +314,7 @@ public class PermissionIndexerTest { indexPermissions(project, ProjectIndexer.Cause.PROJECT_CREATION); verifyAuthorized(project, user); - db.getDbClient().purgeDao().deleteProject(db.getSession(), project.uuid(), PROJECT); + db.getDbClient().purgeDao().deleteProject(db.getSession(), project.uuid(), PROJECT, project.name(), project.getKey()); indexPermissions(project, ProjectIndexer.Cause.PROJECT_DELETION); verifyNotAuthorized(project, user); |