Skip to content

Commit

Permalink
test(ZNTA-2380): user permissions return not found response if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
efloden committed Feb 27, 2018
1 parent d50c532 commit 497bb42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Expand Up @@ -38,6 +38,7 @@
import org.zanata.security.annotations.CheckLoggedIn;
import org.zanata.service.GravatarService;
import com.google.common.base.Strings;
import org.zanata.webtrans.shared.model.Locale;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
Expand Down Expand Up @@ -162,6 +163,9 @@ public Response getTranslationPermission(
HProject project = projectDAO.getBySlug(projectSlug);
LocaleId localeID = new LocaleId(localeId);
HLocale locale = localeDAO.findByLocaleId(localeID);
if (project == null || locale == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
boolean canReview = identity.hasPermissionWithAnyTargets(
"translation-review", project, locale);
boolean canTranslate = identity.hasPermissionWithAnyTargets(
Expand Down Expand Up @@ -243,7 +247,8 @@ protected UserService(final HAccount authenticatedAccount,
final AccountDAO accountDAO, final PersonDAO personDAO,
final ProjectDAO projectDAO, final ZanataIdentity identity,
final ApplicationConfiguration applicationConfiguration,
final IdentityManager identityManager) {
final IdentityManager identityManager,
final LocaleDAO localeDAO) {
this.authenticatedAccount = authenticatedAccount;
this.gravatarServiceImpl = gravatarServiceImpl;
this.accountDAO = accountDAO;
Expand All @@ -252,6 +257,7 @@ protected UserService(final HAccount authenticatedAccount,
this.identity = identity;
this.applicationConfiguration = applicationConfiguration;
this.identityManager = identityManager;
this.localeDAO = localeDAO;
}

/**
Expand Down
Expand Up @@ -16,6 +16,7 @@
import org.zanata.dao.AccountDAO;
import org.zanata.dao.PersonDAO;
import org.zanata.dao.ProjectDAO;
import org.zanata.dao.LocaleDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HPerson;
import org.zanata.rest.dto.User;
Expand Down Expand Up @@ -43,6 +44,8 @@ public class UserServiceTest {
@Mock
private ApplicationConfiguration applicationConfiguration;
private HPerson person;
@Mock
private LocaleDAO localeDAO;

private String username = "a";

Expand All @@ -60,23 +63,31 @@ public void setUp() throws Exception {
service =
new UserService(authenticatedAccount, gravatarService,
accountDAO, personDAO, projectDAO, identity,
applicationConfiguration, identityManager);
applicationConfiguration, identityManager, localeDAO);
}

@Test
public void getTranslationPermissionWillReturnForbiddenIfNotAuthenticated() {
String projectSlug = "projectSlug";
String localeId = "localeId";
service = new UserService(null, gravatarService, accountDAO, personDAO,
projectDAO, identity, applicationConfiguration, identityManager);
projectDAO, identity, applicationConfiguration, identityManager, localeDAO);
Response response = service.getTranslationPermission(projectSlug, localeId);
assertThat(response.getStatus()).isEqualTo(403);
}

@Test
public void getTranslationPermissionWillReturnNotFoundIfNotFound() {
String projectSlug = "projectSlug";
String localeId = "localeId";
Response response = service.getTranslationPermission(projectSlug, localeId);
assertThat(response.getStatus()).isEqualTo(404);
}

@Test
public void getMyInfoWillReturnNotFoundIfNotAuthenticated() {
service = new UserService(null, gravatarService, accountDAO, personDAO,
projectDAO, identity, applicationConfiguration, identityManager);
projectDAO, identity, applicationConfiguration, identityManager, localeDAO);
Response response = service.getMyInfo();
assertThat(response.getStatus()).isEqualTo(404);
}
Expand Down

0 comments on commit 497bb42

Please sign in to comment.