use of ddf.security.service.impl.SubjectUtils in project ddf by codice.
the class RoleClaimsHandlerTest method testRetrieveClaimsValuesIgnoredReferences.
@Test
public void testRetrieveClaimsValuesIgnoredReferences() throws LdapException, SearchResultReferenceIOException {
BindResult bindResult = mock(BindResult.class);
ClaimsParameters claimsParameters;
Connection connection = mock(Connection.class);
ConnectionEntryReader membershipReader = mock(ConnectionEntryReader.class);
ConnectionEntryReader groupNameReader = mock(ConnectionEntryReader.class);
LinkedAttribute membershipAttribute = new LinkedAttribute("uid");
LinkedAttribute groupNameAttribute = new LinkedAttribute("cn");
ClaimsCollection processedClaims;
RoleClaimsHandler claimsHandler;
SearchResultEntry membershipSearchResult = mock(SearchResultEntry.class);
DN resultDN = DN.valueOf("uid=tstark,");
SearchResultEntry groupNameSearchResult = mock(SearchResultEntry.class);
String groupName = "avengers";
when(bindResult.isSuccess()).thenReturn(true);
membershipAttribute.add("tstark");
when(membershipSearchResult.getAttribute(anyString())).thenReturn(membershipAttribute);
// simulate two items in the list (a reference and an entry)
when(membershipReader.hasNext()).thenReturn(true, true, false);
// test a reference followed by entries thereafter
when(membershipReader.isEntry()).thenReturn(false, true);
when(membershipReader.readEntry()).thenReturn(membershipSearchResult);
when(membershipSearchResult.getName()).thenReturn(resultDN);
groupNameAttribute.add(groupName);
when(groupNameSearchResult.getAttribute(anyString())).thenReturn(groupNameAttribute);
when(groupNameReader.hasNext()).thenReturn(true, true, false);
when(groupNameReader.isEntry()).thenReturn(false, true);
when(groupNameReader.readEntry()).thenReturn(groupNameSearchResult);
when(connection.bind(any())).thenReturn(bindResult);
when(connection.search(any(), any(), eq("(&(objectClass=groupOfNames)(|(member=uid=tstark,)(member=uid=tstark,)))"), any())).thenReturn(groupNameReader);
when(connection.search(anyString(), any(), anyString(), matches("uid"))).thenReturn(membershipReader);
claimsHandler = new RoleClaimsHandler(new AttributeMapLoader(new SubjectUtils()));
ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
when(mockConnectionFactory.getConnection()).thenReturn(connection);
claimsHandler.setLdapConnectionFactory(mockConnectionFactory);
claimsHandler.setBindMethod("Simple");
claimsHandler.setBindUserCredentials("foo");
claimsHandler.setBindUserDN("bar");
claimsParameters = new ClaimsParametersImpl(new UserPrincipal(USER_CN), new HashSet<>(), new HashMap<>());
processedClaims = claimsHandler.retrieveClaims(claimsParameters);
assertThat(processedClaims, hasSize(1));
Claim claim = processedClaims.get(0);
assertThat(claim.getValues(), hasSize(1));
assertThat(claim.getValues().get(0), equalTo(groupName));
}
use of ddf.security.service.impl.SubjectUtils in project ddf by codice.
the class ReliableResourceDownloaderTest method testNullReliableResourceCallableAndStatus.
@Test
public void testNullReliableResourceCallableAndStatus() throws Exception {
ResourceResponse mockResponse = getMockResourceResponse(mockStream);
ResourceRetriever mockResourceRetriever = mock(ResourceRetriever.class);
when(mockResourceRetriever.retrieveResource(anyLong())).thenReturn(mockResponse);
ReliableResourceStatus resourceStatus = new ReliableResourceStatus(DownloadStatus.RESOURCE_DOWNLOAD_INTERRUPTED, 0L);
ReliableResourceCallable mockCallable = mock(ReliableResourceCallable.class);
when(mockCallable.getReliableResourceStatus()).thenReturn(resourceStatus);
int retries = 5;
downloaderConfig.setMaxRetryAttempts(retries);
ReliableResourceDownloader downloader = spy(new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), DOWNLOAD_ID, mockResponse, mockResourceRetriever));
doReturn(mockCallable).when(downloader).constructReliableResourceCallable(any(InputStream.class), any(CountingOutputStream.class), any(), anyInt(), any(Object.class));
doThrow(new CancellationException()).when(downloader).constructResourceRetrievalMonitor();
DownloadStatusInfoImpl downloadStatusInfo = new DownloadStatusInfoImpl();
downloadStatusInfo.setSubjectOperations(new SubjectUtils());
downloader.setupDownload(mockMetacard, downloadStatusInfo);
downloader.run();
verify(mockPublisher, times(retries)).postRetrievalStatus(any(ResourceResponse.class), eq(ProductRetrievalStatus.RETRYING), any(Metacard.class), anyString(), anyLong(), eq(DOWNLOAD_ID));
}
use of ddf.security.service.impl.SubjectUtils in project ddf by codice.
the class ReliableResourceDownloaderTest method testBadKeyName.
@Test
public void testBadKeyName() throws Exception {
Metacard metacard = getMockMetacard(DOWNLOAD_ID, ":badsourcename");
downloaderConfig.setCacheEnabled(true);
ResourceResponse mockResponse = getMockResourceResponse(mockStream);
ResourceCacheImpl mockCache = mock(ResourceCacheImpl.class);
when(mockCache.isPending(anyString())).thenReturn(false);
when(mockCache.getProductCacheDirectory()).thenReturn(productCacheDirectory);
downloaderConfig.setResourceCache(mockCache);
ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), DOWNLOAD_ID, mockResponse, getMockRetriever());
DownloadStatusInfoImpl downloadStatusInfo = new DownloadStatusInfoImpl();
downloadStatusInfo.setSubjectOperations(new SubjectUtils());
downloader.setupDownload(metacard, downloadStatusInfo);
verify(mockCache, never()).addPendingCacheEntry(any(ReliableResource.class));
}
use of ddf.security.service.impl.SubjectUtils in project ddf by codice.
the class DownloadsStatusEventListenerTest method setUp.
@Before
public void setUp() throws IOException {
testFolder.create();
String productCacheDir = testFolder.newFolder("cache").toString();
localResourcePath = testFolder.newFolder("resources").toPath();
ReliableResourceDownloaderConfig downloaderConfig = new ReliableResourceDownloaderConfig();
testDownloadStatusInfo = new DownloadStatusInfoImpl();
testDownloadStatusInfo.setSubjectOperations(new SubjectUtils());
ResourceCacheImpl testResourceCache = new ResourceCacheImpl();
DownloadsStatusEventPublisher testEventPublisher = mock(DownloadsStatusEventPublisher.class);
DownloadsStatusEventListener testEventListener = new DownloadsStatusEventListener();
downloaderConfig.setResourceCache(testResourceCache);
downloaderConfig.setEventPublisher(testEventPublisher);
downloaderConfig.setEventListener(testEventListener);
testDownloadManager = new ReliableResourceDownloadManager(downloaderConfig, testDownloadStatusInfo, Executors.newSingleThreadExecutor());
testDownloadManager.setMaxRetryAttempts(1);
testDownloadManager.setDelayBetweenAttempts(0);
testDownloadManager.setMonitorPeriod(5);
}
use of ddf.security.service.impl.SubjectUtils in project ddf by codice.
the class AbstractDownloadsStatusEventPublisherTest method setupPublisherWithNoNotifications.
private void setupPublisherWithNoNotifications() {
actionProvider = mock(ActionProvider.class);
eventAdmin = mock(EventAdmin.class);
publisher = new DownloadsStatusEventPublisher(eventAdmin, ImmutableList.of(actionProvider));
publisher.setSubjectOperations(new SubjectUtils());
publisher.setNotificationEnabled(false);
publisher.setActivityEnabled(false);
}
Aggregations