Search in sources :

Example 1 with TrustedHttpClient

use of org.opencastproject.security.api.TrustedHttpClient in project opencast by opencast.

the class IngestServiceImplTest method setUp.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
    FileUtils.forceMkdir(ingestTempDir);
    // set up service and mock workspace
    wfr = EasyMock.createNiceMock(WorkingFileRepository.class);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlAttachment);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackage);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackageOld);
    workflowInstance = EasyMock.createNiceMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getId()).andReturn(workflowInstanceID);
    EasyMock.expect(workflowInstance.getState()).andReturn(WorkflowState.STOPPED);
    final Capture<MediaPackage> mp = EasyMock.newCapture();
    workflowService = EasyMock.createNiceMock(WorkflowService.class);
    EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), EasyMock.capture(mp), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
    EasyMock.expect(workflowInstance.getMediaPackage()).andAnswer(new IAnswer<MediaPackage>() {

        @Override
        public MediaPackage answer() throws Throwable {
            return mp.getValue();
        }
    });
    EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject(), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
    EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(workflowInstance);
    EasyMock.expect(workflowService.getWorkflowDefinitionById((String) EasyMock.anyObject())).andReturn(new WorkflowDefinitionImpl());
    EasyMock.expect(workflowService.getWorkflowById(EasyMock.anyLong())).andReturn(workflowInstance);
    SchedulerService schedulerService = EasyMock.createNiceMock(SchedulerService.class);
    Map<String, String> properties = new HashMap<>();
    properties.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, "sample");
    properties.put("agent-name", "matterhorn-agent");
    EasyMock.expect(schedulerService.getCaptureAgentConfiguration(EasyMock.anyString())).andReturn(properties).anyTimes();
    EasyMock.expect(schedulerService.getDublinCore(EasyMock.anyString())).andReturn(DublinCores.read(urlCatalog1.toURL().openStream())).anyTimes();
    MediaPackage schedulerMediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/source-manifest.xml"), "UTF-8"));
    EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(schedulerMediaPackage).anyTimes();
    EasyMock.replay(wfr, workflowInstance, workflowService, schedulerService);
    User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new DefaultOrganization(), "test"));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    EasyMock.replay(userDirectoryService);
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    HttpEntity entity = EasyMock.createMock(HttpEntity.class);
    InputStream is = getClass().getResourceAsStream("/av.mov");
    byte[] movie = IOUtils.toByteArray(is);
    IOUtils.closeQuietly(is);
    EasyMock.expect(entity.getContent()).andReturn(new ByteArrayInputStream(movie)).anyTimes();
    EasyMock.replay(entity);
    StatusLine statusLine = EasyMock.createMock(StatusLine.class);
    EasyMock.expect(statusLine.getStatusCode()).andReturn(200).anyTimes();
    EasyMock.replay(statusLine);
    Header contentDispositionHeader = EasyMock.createMock(Header.class);
    EasyMock.expect(contentDispositionHeader.getValue()).andReturn("attachment; filename=fname.mp4").anyTimes();
    EasyMock.replay(contentDispositionHeader);
    HttpResponse httpResponse = EasyMock.createMock(HttpResponse.class);
    EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLine).anyTimes();
    EasyMock.expect(httpResponse.getFirstHeader("Content-Disposition")).andReturn(contentDispositionHeader).anyTimes();
    EasyMock.expect(httpResponse.getEntity()).andReturn(entity).anyTimes();
    EasyMock.replay(httpResponse);
    TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    EasyMock.expect(httpClient.execute((HttpGet) EasyMock.anyObject())).andReturn(httpResponse).anyTimes();
    EasyMock.replay(httpClient);
    AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(new AccessControlList(), AclScope.Series)).anyTimes();
    EasyMock.replay(authorizationService);
    MediaInspectionService mediaInspectionService = EasyMock.createNiceMock(MediaInspectionService.class);
    EasyMock.expect(mediaInspectionService.enrich(EasyMock.anyObject(MediaPackageElement.class), EasyMock.anyBoolean())).andAnswer(new IAnswer<Job>() {

        private int i = 0;

        @Override
        public Job answer() throws Throwable {
            TrackImpl element = (TrackImpl) EasyMock.getCurrentArguments()[0];
            element.setDuration(20000L);
            if (i % 2 == 0) {
                element.addStream(new VideoStreamImpl());
            } else {
                element.addStream(new AudioStreamImpl());
            }
            i++;
            JobImpl succeededJob = new JobImpl();
            succeededJob.setStatus(Status.FINISHED);
            succeededJob.setPayload(MediaPackageElementParser.getAsXml(element));
            return succeededJob;
        }
    }).anyTimes();
    EasyMock.replay(mediaInspectionService);
    service = new IngestServiceImpl();
    service.setHttpClient(httpClient);
    service.setAuthorizationService(authorizationService);
    service.setWorkingFileRepository(wfr);
    service.setWorkflowService(workflowService);
    service.setSecurityService(securityService);
    service.setSchedulerService(schedulerService);
    service.setMediaInspectionService(mediaInspectionService);
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    serviceRegistry.registerService(service);
    service.setServiceRegistry(serviceRegistry);
    service.defaultWorkflowDefinionId = "sample";
    serviceRegistry.registerService(service);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SchedulerService(org.opencastproject.scheduler.api.SchedulerService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) HttpGet(org.apache.http.client.methods.HttpGet) AudioStreamImpl(org.opencastproject.mediapackage.track.AudioStreamImpl) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaInspectionService(org.opencastproject.inspection.api.MediaInspectionService) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowService(org.opencastproject.workflow.api.WorkflowService) SecurityService(org.opencastproject.security.api.SecurityService) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) JobImpl(org.opencastproject.job.api.JobImpl) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpResponse(org.apache.http.HttpResponse) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) StatusLine(org.apache.http.StatusLine) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) Header(org.apache.http.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 2 with TrustedHttpClient

use of org.opencastproject.security.api.TrustedHttpClient in project opencast by opencast.

the class ServiceRegistryJpaImplTest method setUpServiceRegistryJpaImpl.

public void setUpServiceRegistryJpaImpl() throws PropertyVetoException, NotFoundException, TrustedHttpClientException {
    serviceRegistryJpaImpl = new ServiceRegistryJpaImpl();
    serviceRegistryJpaImpl.setEntityManagerFactory(emf);
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    serviceRegistryJpaImpl.setOrganizationDirectoryService(organizationDirectoryService);
    JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
    User anonymous = new JaxbUser("anonymous", "test", jaxbOrganization, new JaxbRole(jaxbOrganization.getAnonymousRole(), jaxbOrganization));
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    serviceRegistryJpaImpl.setSecurityService(securityService);
    UserDirectoryService userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser(EasyMock.anyString())).andReturn(anonymous).anyTimes();
    EasyMock.replay(userDirectoryService);
    serviceRegistryJpaImpl.setUserDirectoryService(userDirectoryService);
    final Capture<HttpUriRequest> request = EasyMock.newCapture();
    final BasicHttpResponse successRespone = new BasicHttpResponse(new BasicStatusLine(new HttpVersion(1, 1), HttpStatus.SC_NO_CONTENT, "No message"));
    final BasicHttpResponse unavailableResponse = new BasicHttpResponse(new BasicStatusLine(new HttpVersion(1, 1), HttpStatus.SC_SERVICE_UNAVAILABLE, "No message"));
    TrustedHttpClient trustedHttpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    EasyMock.expect(trustedHttpClient.execute(EasyMock.capture(request))).andAnswer(new IAnswer<HttpResponse>() {

        @Override
        public HttpResponse answer() throws Throwable {
            if (!request.hasCaptured())
                return unavailableResponse;
            if (request.getValue().getURI().toString().contains(TEST_PATH))
                return unavailableResponse;
            if (request.getValue().getURI().toString().contains(TEST_PATH_3))
                return unavailableResponse;
            return successRespone;
        }
    }).anyTimes();
    EasyMock.replay(trustedHttpClient);
    serviceRegistryJpaImpl.setTrustedHttpClient(trustedHttpClient);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) BasicStatusLine(org.apache.http.message.BasicStatusLine) IAnswer(org.easymock.IAnswer) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) HttpVersion(org.apache.http.HttpVersion) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService)

Example 3 with TrustedHttpClient

use of org.opencastproject.security.api.TrustedHttpClient in project opencast by opencast.

the class CleanupWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    cleanupWOH = new CleanupWorkflowOperationHandler();
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getBaseUri()).andReturn(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX)).anyTimes();
    EasyMock.replay(workspace);
    cleanupWOH.setWorkspace(workspace);
    List<ServiceRegistration> wfrServiceRegistrations = new ArrayList<ServiceRegistration>();
    wfrServiceRegistrations.add(createWfrServiceRegistration(HOSTNAME_NODE1, WFR_URL_PREFIX));
    wfrServiceRegistrations.add(createWfrServiceRegistration(HOSTNAME_NODE2, WFR_URL_PREFIX));
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getServiceRegistrationsByType(EasyMock.eq(WorkingFileRepository.SERVICE_TYPE))).andReturn(wfrServiceRegistrations).anyTimes();
    Job currentJob = EasyMock.createNiceMock(Job.class);
    currentJob.setArguments((List<String>) EasyMock.anyObject());
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(currentJob).anyTimes();
    EasyMock.expect(serviceRegistry.updateJob((Job) EasyMock.anyObject())).andReturn(currentJob).anyTimes();
    EasyMock.expect(serviceRegistry.getChildJobs(EasyMock.anyLong())).andReturn(new ArrayList<Job>()).anyTimes();
    EasyMock.replay(serviceRegistry, currentJob);
    cleanupWOH.setServiceRegistry(serviceRegistry);
    TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    HttpResponse httpResponse = EasyMock.createNiceMock(HttpResponse.class);
    StatusLine responseStatusLine = EasyMock.createNiceMock(StatusLine.class);
    EasyMock.expect(responseStatusLine.getStatusCode()).andReturn(HttpStatus.SC_OK).anyTimes();
    EasyMock.expect(httpResponse.getStatusLine()).andReturn(responseStatusLine).anyTimes();
    EasyMock.expect(httpClient.execute(StoreUrisArgumentMatcher.createMatcher(deletedFilesURIs, UrlSupport.uri(HOSTNAME_NODE2, WFR_URL_PREFIX)))).andReturn(httpResponse).anyTimes();
    EasyMock.replay(httpClient, httpResponse, responseStatusLine);
    cleanupWOH.setTrustedHttpClient(httpClient);
}
Also used : TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) StatusLine(org.apache.http.StatusLine) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) Workspace(org.opencastproject.workspace.api.Workspace) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Before(org.junit.Before)

Example 4 with TrustedHttpClient

use of org.opencastproject.security.api.TrustedHttpClient in project opencast by opencast.

the class DownloadDistributionServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    final File mediaPackageRoot = new File(getClass().getResource("/mediapackage.xml").toURI()).getParentFile();
    mp = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/mediapackage.xml"), "UTF-8"));
    distributionRoot = new File(mediaPackageRoot, "static");
    service = new DownloadDistributionServiceImpl();
    StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class);
    EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK).anyTimes();
    EasyMock.replay(statusLine);
    HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
    EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes();
    EasyMock.replay(response);
    final TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response).anyTimes();
    EasyMock.expect(httpClient.run((HttpUriRequest) EasyMock.anyObject())).andAnswer(new IAnswer<Function<Function<HttpResponse, Object>, Either<Exception, Object>>>() {

        @Override
        public Function<Function<HttpResponse, Object>, Either<Exception, Object>> answer() throws Throwable {
            HttpUriRequest req = (HttpUriRequest) EasyMock.getCurrentArguments()[0];
            return StandAloneTrustedHttpClientImpl.run(httpClient, req);
        }
    }).anyTimes();
    EasyMock.replay(httpClient);
    defaultOrganization = new DefaultOrganization();
    User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    service.setServiceRegistry(serviceRegistry);
    service.setTrustedHttpClient(httpClient);
    final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    service.setWorkspace(workspace);
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {

        @Override
        public File answer() throws Throwable {
            final URI uri = (URI) EasyMock.getCurrentArguments()[0];
            final String[] pathElems = uri.getPath().split("/");
            final String file = pathElems[pathElems.length - 1];
            return new File(mediaPackageRoot, file);
        }
    }).anyTimes();
    EasyMock.replay(workspace);
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bc.getProperty("org.opencastproject.download.directory")).andReturn(distributionRoot.toString()).anyTimes();
    EasyMock.expect(bc.getProperty("org.opencastproject.download.url")).andReturn(UrlSupport.DEFAULT_BASE_URL).anyTimes();
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    Dictionary<String, Object> p = new Hashtable<String, Object>();
    p.put(DistributionService.CONFIG_KEY_STORE_TYPE, "download");
    EasyMock.expect(cc.getProperties()).andReturn(p).anyTimes();
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.replay(bc, cc);
    service.activate(cc);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) Function(org.opencastproject.util.data.Function) SecurityService(org.opencastproject.security.api.SecurityService) Either(org.opencastproject.util.data.Either) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) HttpResponse(org.apache.http.HttpResponse) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) StatusLine(org.apache.http.StatusLine) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 5 with TrustedHttpClient

use of org.opencastproject.security.api.TrustedHttpClient in project opencast by opencast.

the class WorkspaceImplTest method testLongFilenames.

@Test
public void testLongFilenames() throws Exception {
    WorkingFileRepository repo = EasyMock.createNiceMock(WorkingFileRepository.class);
    EasyMock.expect(repo.getBaseUri()).andReturn(new URI("http://localhost:8080/files")).anyTimes();
    EasyMock.replay(repo);
    workspace.setRepository(repo);
    File source = new File("target/test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/../test-classes/opencast_header.gif");
    URL urlToSource = source.toURI().toURL();
    final TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    HttpEntity entity = EasyMock.createNiceMock(HttpEntity.class);
    EasyMock.expect(entity.getContent()).andReturn(new FileInputStream(source));
    StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class);
    EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK);
    HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
    EasyMock.expect(response.getEntity()).andReturn(entity);
    EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes();
    EasyMock.replay(response, entity, statusLine);
    EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response);
    EasyMock.expect(httpClient.runner((HttpUriRequest) EasyMock.anyObject())).andAnswer(new IAnswer<TrustedHttpClient.RequestRunner<Object>>() {

        @Override
        public RequestRunner<Object> answer() throws Throwable {
            HttpUriRequest req = (HttpUriRequest) EasyMock.getCurrentArguments()[0];
            return StandAloneTrustedHttpClientImpl.runner(httpClient, req);
        }
    });
    EasyMock.replay(httpClient);
    workspace.setTrustedHttpClient(httpClient);
    Assert.assertTrue(urlToSource.toString().length() > 255);
    try {
        Assert.assertNotNull(workspace.get(urlToSource.toURI()));
    } catch (NotFoundException e) {
    // This happens on some machines, so we catch and handle it.
    }
}
Also used : TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) RequestRunner(org.opencastproject.security.api.TrustedHttpClient.RequestRunner) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) URI(java.net.URI) URL(java.net.URL) FileInputStream(java.io.FileInputStream) StatusLine(org.apache.http.StatusLine) File(java.io.File) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) Test(org.junit.Test)

Aggregations

TrustedHttpClient (org.opencastproject.security.api.TrustedHttpClient)6 HttpResponse (org.apache.http.HttpResponse)4 StatusLine (org.apache.http.StatusLine)4 File (java.io.File)3 URI (java.net.URI)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 IAnswer (org.easymock.IAnswer)3 Before (org.junit.Before)3 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)3 JaxbRole (org.opencastproject.security.api.JaxbRole)3 JaxbUser (org.opencastproject.security.api.JaxbUser)3 Organization (org.opencastproject.security.api.Organization)3 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)3 SecurityService (org.opencastproject.security.api.SecurityService)3 User (org.opencastproject.security.api.User)3 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)3 FileInputStream (java.io.FileInputStream)2 HttpEntity (org.apache.http.HttpEntity)2 Test (org.junit.Test)2 RequestRunner (org.opencastproject.security.api.TrustedHttpClient.RequestRunner)2