public void should_apply_permission_template() throws Exception {
setupData("should_apply_permission_template");
+ assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", 123L)).isEmpty();
+ assertThat(permissionFacade.selectGroupPermissions("sonar-users", 123L)).isEmpty();
+ assertThat(permissionFacade.selectGroupPermissions("Anyone", 123L)).isEmpty();
+ assertThat(permissionFacade.selectUserPermissions("marius", 123L)).isEmpty();
+
permissionFacade.applyPermissionTemplate("default_20130101_010203", 123L);
- checkTable("should_apply_permission_template", "group_roles", "group_id", "resource_id", "role");
- checkTable("should_apply_permission_template", "user_roles", "group_id", "resource_id", "role");
+ assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", 123L)).containsOnly("admin", "issueadmin");
+ assertThat(permissionFacade.selectGroupPermissions("sonar-users", 123L)).containsOnly("user", "codeviewer");
+ assertThat(permissionFacade.selectGroupPermissions("Anyone", 123L)).containsOnly("user", "codeviewer");
+
+ assertThat(permissionFacade.selectUserPermissions("marius", 123L)).containsOnly("admin");
}
@Test
public class DefaultResourcePermissionsTest extends AbstractDaoTestCase {
+ private final static Long PROJECT_ID = 123L;
+
private Resource project;
private Settings settings;
private DefaultResourcePermissions permissions;
+ private PermissionFacade permissionFacade;
@Rule
public ExpectedException throwable = ExpectedException.none();
@Before
public void initResourcePermissions() {
- project = new Project("project").setId(123);
+ project = new Project("project").setId(PROJECT_ID.intValue());
settings = new Settings();
- PermissionFacade permissionFacade = new PermissionFacade(getMyBatis(),
+ permissionFacade = new PermissionFacade(getMyBatis(),
new RoleDao(getMyBatis()), new UserDao(getMyBatis()), new ResourceDao(getMyBatis()), new PermissionTemplateDao(getMyBatis(), System2.INSTANCE), settings);
permissions = new DefaultResourcePermissions(getMyBatis(), permissionFacade);
}
settings.setProperty("sonar.permission.template.default", "default_template_20130101_010203");
+ assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", PROJECT_ID)).isEmpty();
+ assertThat(permissionFacade.selectGroupPermissions("sonar-users", PROJECT_ID)).isEmpty();
+ assertThat(permissionFacade.selectGroupPermissions("Anyone", PROJECT_ID)).isEmpty();
+ assertThat(permissionFacade.selectUserPermissions("marius", PROJECT_ID)).isEmpty();
+
permissions.grantDefaultRoles(project);
- checkTables("grantDefaultRoles", "user_roles", "group_roles");
+ assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", PROJECT_ID)).containsOnly("admin");
+ assertThat(permissionFacade.selectGroupPermissions("sonar-users", PROJECT_ID)).containsOnly("user", "codeviewer");
+ assertThat(permissionFacade.selectGroupPermissions("Anyone", PROJECT_ID)).containsOnly("user", "codeviewer");
+
+ assertThat(permissionFacade.selectUserPermissions("marius", PROJECT_ID)).isEmpty();
}
@Test
.expectMessage("The \"foo.project\" key matches multiple permission templates: \"Start with foo\", \"Start with foo again\". A system administrator must update these templates so that only one of them matches the key.");
permissions.grantDefaultRoles(project);
-
}
@Test
settings.setProperty("sonar.permission.template.default", "default_20130101_010203");
settings.setProperty("sonar.permission.template.TRK.default", "default_for_trk_20130101_010203");
+ assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", PROJECT_ID)).isEmpty();
+ assertThat(permissionFacade.selectGroupPermissions("sonar-users", PROJECT_ID)).isEmpty();
+ assertThat(permissionFacade.selectGroupPermissions("Anyone", PROJECT_ID)).isEmpty();
+ assertThat(permissionFacade.selectUserPermissions("marius", PROJECT_ID)).isEmpty();
+
permissions.grantDefaultRoles(project);
- checkTables("grantDefaultRolesProject", "user_roles", "group_roles");
+ assertThat(permissionFacade.selectGroupPermissions("sonar-administrators", PROJECT_ID)).containsOnly("admin", "user", "codeviewer");
+ assertThat(permissionFacade.selectGroupPermissions("sonar-users", PROJECT_ID)).containsOnly("admin");
+ assertThat(permissionFacade.selectGroupPermissions("Anyone", PROJECT_ID)).containsOnly("codeviewer");
+
+ assertThat(permissionFacade.selectUserPermissions("marius", PROJECT_ID)).containsOnly("codeviewer");
}
@Test