<commit_before>package org.zanata.security;

import javax.faces.event.PhaseEvent;
import javax.inject.Provider;
import javax.servlet.http.HttpServletRequest;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.zanata.ApplicationConfiguration;
import org.zanata.exception.NotLoggedInException;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;

public class AnonymousAccessControlPhaseListenerTest {

    private AnonymousAccessControlPhaseListener checker;
    @Mock private Provider<Boolean> anonymousAccessProvider;
    @Mock private ZanataIdentity identity;
    @Mock private HttpServletRequest request;
    @Mock private PhaseEvent phaseEvent;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        checker = new AnonymousAccessControlPhaseListener(
                anonymousAccessProvider, identity, request);
        when(request.getContextPath()).thenReturn("");

        // set up the authentication state to unauthenticated
        doThrow(new NotLoggedInException()).when(identity).checkLoggedIn();
    }

    @Test
    public void anonymousAccessToAnyPageUnderAccountIsAllowed() {
        when(request.getRequestURI()).thenReturn("/account/login.xhtml");
        checker.beforePhase(phaseEvent);
    }

    @Test
    public void anonymousAccessToAnyPageUnderPublicIsAllowed() {
        when(request.getRequestURI()).thenReturn("/public/info.xhtml");
        checker.beforePhase(phaseEvent);
    }

    @Test
    public void anonymousAccessToUnprotectedPageIsAllowed() {
        when(request.getRequestURI()).thenReturn("home.xhtml");
        when(anonymousAccessProvider.get()).thenReturn(true);
<commit_msg>ZNTA-1527 - test name change<commit_after>package org.zanata.security;

import javax.faces.event.PhaseEvent;
import javax.inject.Provider;
import javax.servlet.http.HttpServletRequest;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.zanata.exception.NotLoggedInException;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;

public class AnonymousAccessControlPhaseListenerTest {

    private AnonymousAccessControlPhaseListener checker;
    @Mock private Provider<Boolean> anonymousAccessProvider;
    @Mock private ZanataIdentity identity;
    @Mock private HttpServletRequest request;
    @Mock private PhaseEvent phaseEvent;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        checker = new AnonymousAccessControlPhaseListener(
                anonymousAccessProvider, identity, request);
        when(request.getContextPath()).thenReturn("");

        // set up the authentication state to unauthenticated
        doThrow(new NotLoggedInException()).when(identity).checkLoggedIn();
    }

    @Test
    public void anonymousAccessToPageUnderAccountIsAllowed() {
        when(request.getRequestURI()).thenReturn("/account/login.xhtml");
        checker.beforePhase(phaseEvent);
    }

    @Test
    public void anonymousAccessToPageUnderPublicIsAllowed() {
        when(request.getRequestURI()).thenReturn("/public/info.xhtml");
        checker.beforePhase(phaseEvent);
    }

    @Test
    public void anonymousAccessToUnprotectedPageIsAllowed() {
        when(request.getRequestURI()).thenReturn("home.xhtml");
        when(anonymousAccessProvider.get()).thenReturn(true);

{'fraction_non_alphanumeric': 0.09350579358663433, 'fraction_numerical': 0.0010778765831312314, 'mean_word_length': 4.418978102189781, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2376110', 'n_tokens_mistral': 1007, 'n_tokens_neox': 983, 'n_words': 188}