|
|
@ -22,9 +22,14 @@ import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.mitre.openid.connect.model.BlacklistedSite;
|
|
|
|
import org.mitre.openid.connect.model.BlacklistedSite;
|
|
|
|
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
|
|
|
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
|
|
|
|
|
|
|
|
import org.mockito.InjectMocks;
|
|
|
|
|
|
|
|
import org.mockito.Mock;
|
|
|
|
import org.mockito.Mockito;
|
|
|
|
import org.mockito.Mockito;
|
|
|
|
|
|
|
|
import org.mockito.runners.MockitoJUnitRunner;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.mockito.Mockito.times;
|
|
|
|
import static org.mockito.Mockito.times;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
import com.google.common.collect.Sets;
|
|
|
@ -33,6 +38,7 @@ import com.google.common.collect.Sets;
|
|
|
|
* @author wkim
|
|
|
|
* @author wkim
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.class)
|
|
|
|
public class TestDefaultBlacklistedSiteService {
|
|
|
|
public class TestDefaultBlacklistedSiteService {
|
|
|
|
|
|
|
|
|
|
|
|
private BlacklistedSite site1;
|
|
|
|
private BlacklistedSite site1;
|
|
|
@ -42,9 +48,13 @@ public class TestDefaultBlacklistedSiteService {
|
|
|
|
private String uri2 = "black2";
|
|
|
|
private String uri2 = "black2";
|
|
|
|
private String uri3 = "not-black";
|
|
|
|
private String uri3 = "not-black";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Set<BlacklistedSite> blackListedSitesSet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
private BlacklistedSiteRepository mockRepository;
|
|
|
|
private BlacklistedSiteRepository mockRepository;
|
|
|
|
|
|
|
|
|
|
|
|
private DefaultBlacklistedSiteService service;
|
|
|
|
@InjectMocks
|
|
|
|
|
|
|
|
private DefaultBlacklistedSiteService service = new DefaultBlacklistedSiteService();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @throws java.lang.Exception
|
|
|
|
* @throws java.lang.Exception
|
|
|
@ -58,12 +68,7 @@ public class TestDefaultBlacklistedSiteService {
|
|
|
|
site1.setUri(uri1);
|
|
|
|
site1.setUri(uri1);
|
|
|
|
site2.setUri(uri2);
|
|
|
|
site2.setUri(uri2);
|
|
|
|
|
|
|
|
|
|
|
|
Set<BlacklistedSite> blackListedSitesSet = Sets.newHashSet(site1, site2);
|
|
|
|
blackListedSitesSet = Sets.newHashSet(site1, site2);
|
|
|
|
|
|
|
|
|
|
|
|
mockRepository = Mockito.mock(BlacklistedSiteRepository.class);
|
|
|
|
|
|
|
|
Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
service = new DefaultBlacklistedSiteService(mockRepository);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -72,6 +77,8 @@ public class TestDefaultBlacklistedSiteService {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void isBlacklisted_yes() {
|
|
|
|
public void isBlacklisted_yes() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet);
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(service.isBlacklisted(uri1));
|
|
|
|
assertTrue(service.isBlacklisted(uri1));
|
|
|
|
assertTrue(service.isBlacklisted(uri2));
|
|
|
|
assertTrue(service.isBlacklisted(uri2));
|
|
|
|
|
|
|
|
|
|
|
@ -84,6 +91,8 @@ public class TestDefaultBlacklistedSiteService {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void isBlacklisted_no() {
|
|
|
|
public void isBlacklisted_no() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(mockRepository.getAll()).thenReturn(blackListedSitesSet);
|
|
|
|
|
|
|
|
|
|
|
|
assertFalse(service.isBlacklisted(uri3));
|
|
|
|
assertFalse(service.isBlacklisted(uri3));
|
|
|
|
|
|
|
|
|
|
|
|
Mockito.verify(mockRepository).getAll();
|
|
|
|
Mockito.verify(mockRepository).getAll();
|
|
|
|