Search in sources :

Example 16 with Policy

use of org.opencastproject.urlsigning.common.Policy in project opencast by opencast.

the class UrlSigningFilterTest method testCorrectPolicyAndSignature.

@Test
public void testCorrectPolicyAndSignature() throws Exception {
    String encryptionKeyId = "theKey";
    String acceptedUrl = "http://accepted.com";
    String acceptedKey = "ThisIsTheKey";
    String acceptedIp = "10.0.0.1";
    DateTime future = new DateTime(4749125399000L);
    Policy policy = Policy.mkSimplePolicy(acceptedUrl, future);
    String acceptedQueryString = ResourceRequestUtil.policyToResourceRequestQueryString(policy, encryptionKeyId, acceptedKey);
    ResourceRequest acceptedRequest = new ResourceRequest();
    acceptedRequest.setStatus(Status.Ok);
    // Setup the Mock Url Signing Service
    UrlSigningVerifier urlSigningVerifier = EasyMock.createMock(UrlSigningVerifier.class);
    EasyMock.expect(urlSigningVerifier.verify(acceptedQueryString, acceptedIp, acceptedUrl, true)).andReturn(acceptedRequest);
    EasyMock.replay(urlSigningVerifier);
    UrlSigningFilter filter = new UrlSigningFilter();
    filter.setUrlSigningVerifier(urlSigningVerifier);
    // Setup the Mock Request
    HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
    EasyMock.expect(request.getMethod()).andStubReturn("GET");
    EasyMock.expect(request.getRequestURL()).andStubReturn(new StringBuffer(acceptedUrl));
    EasyMock.expect(request.getQueryString()).andStubReturn(acceptedQueryString);
    EasyMock.expect(request.getRemoteAddr()).andStubReturn(acceptedIp);
    EasyMock.replay(request);
    HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
    // Setup the mock filter chain.
    FilterChain chain = EasyMock.createMock(FilterChain.class);
    chain.doFilter(request, response);
    EasyMock.expectLastCall();
    EasyMock.replay(chain);
    filter.doFilter(request, response, chain);
    EasyMock.verify(chain);
}
Also used : Policy(org.opencastproject.urlsigning.common.Policy) HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) UrlSigningVerifier(org.opencastproject.security.urlsigning.verifier.UrlSigningVerifier) HttpServletResponse(javax.servlet.http.HttpServletResponse) ResourceRequest(org.opencastproject.urlsigning.common.ResourceRequest) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 17 with Policy

use of org.opencastproject.urlsigning.common.Policy in project opencast by opencast.

the class UrlSigningFilterTest method createSignedHttpServletRequest.

private HttpServletRequest createSignedHttpServletRequest(String method, String path) throws Exception {
    String fullUrl = BASE_URL + path;
    Policy policy = Policy.mkSimplePolicy(fullUrl, new DateTime(2056, 05, 13, 14, 32));
    HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
    EasyMock.expect(request.getMethod()).andStubReturn(method);
    EasyMock.expect(request.getRequestURL()).andStubReturn(new StringBuffer(fullUrl));
    EasyMock.expect(request.getQueryString()).andStubReturn(ResourceRequestUtil.policyToResourceRequestQueryString(policy, keyId, key));
    EasyMock.expect(request.getRemoteAddr()).andStubReturn(clientIp);
    return request;
}
Also used : Policy(org.opencastproject.urlsigning.common.Policy) HttpServletRequest(javax.servlet.http.HttpServletRequest) DateTime(org.joda.time.DateTime)

Aggregations

Policy (org.opencastproject.urlsigning.common.Policy)17 DateTime (org.joda.time.DateTime)16 Test (org.junit.Test)14 ResourceRequest (org.opencastproject.urlsigning.common.ResourceRequest)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 FilterChain (javax.servlet.FilterChain)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 UrlSigningVerifier (org.opencastproject.security.urlsigning.verifier.UrlSigningVerifier)5 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Properties (java.util.Properties)1 NameValuePair (org.apache.http.NameValuePair)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 UrlSigningException (org.opencastproject.security.urlsigning.exception.UrlSigningException)1 UrlSigningProvider (org.opencastproject.security.urlsigning.provider.UrlSigningProvider)1