@Test public void anonymous() { userSession .anonymous() .addPermission(SCAN, db.getDefaultOrganization()) .addPermission(PROVISION_PROJECTS, db.getDefaultOrganization()); CurrentWsResponse response = call(); assertThat(response.getIsLoggedIn()).isFalse(); assertThat(response.getPermissions().getGlobalList()).containsOnly("scan", "provisioning"); assertThat(response) .extracting(CurrentWsResponse::hasLogin, CurrentWsResponse::hasName, CurrentWsResponse::hasEmail, CurrentWsResponse::hasLocal, CurrentWsResponse::hasExternalIdentity, CurrentWsResponse::hasExternalProvider) .containsOnly(false); assertThat(response.getScmAccountsList()).isEmpty(); assertThat(response.getGroupsList()).isEmpty(); }
@Test public void return_minimal_user_info() { UserDto user = db.users().insertUser(u -> u .setLogin("obiwan.kenobi") .setName("Obiwan Kenobi") .setEmail(null) .setLocal(true) .setExternalLogin("obiwan") .setExternalIdentityProvider("sonarqube") .setScmAccounts((String) null)); userSession.logIn(user); CurrentWsResponse response = call(); assertThat(response) .extracting(CurrentWsResponse::getIsLoggedIn, CurrentWsResponse::getLogin, CurrentWsResponse::getName, CurrentWsResponse::hasAvatar, CurrentWsResponse::getLocal, CurrentWsResponse::getExternalIdentity, CurrentWsResponse::getExternalProvider, CurrentWsResponse::hasPersonalOrganization, CurrentWsResponse::getSettingsList) .containsExactly(true, "obiwan.kenobi", "Obiwan Kenobi", false, true, "obiwan", "sonarqube", false, Collections.emptyList()); assertThat(response.hasEmail()).isFalse(); assertThat(response.getScmAccountsList()).isEmpty(); assertThat(response.getGroupsList()).isEmpty(); assertThat(response.getPermissions().getGlobalList()).isEmpty(); }
@Test public void return_permissions() { UserDto user = db.users().insertUser(); userSession .logIn(user) // permissions on default organization .addPermission(SCAN, db.getDefaultOrganization()) .addPermission(ADMINISTER_QUALITY_PROFILES, db.getDefaultOrganization()) // permissions on other organizations are ignored .addPermission(ADMINISTER, db.organizations().insert()); CurrentWsResponse response = call(); assertThat(response.getPermissions().getGlobalList()).containsOnly("profileadmin", "scan"); }