Skip to content

Commit

Permalink
Adding some tests for Flash authorization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy Ingulfsen committed Aug 11, 2016
1 parent cef4368 commit 4e10c2a
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 10 deletions.
Binary file added lib/wms-mediacache.jar
Binary file not shown.
28 changes: 18 additions & 10 deletions src/edu/stanford/dlss/wowza/SulWowzaFlash.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,28 @@ public void onHTTPCupertinoStreamingSessionCreate(HTTPStreamerSessionCupertino h
*/
public void play(IClient client, RequestFunction function, AMFDataList params)
{
String queryString = client.getQueryStr();
String clientIP = client.getIp();
String streamName = params.getString(PARAM1);
String streamName = params.getString(PARAM1);

//get the real stream name if this is an alias.
streamName = ((ApplicationInstance)client.getAppInstance()).internalResolvePlayAlias(streamName, client);
//get the real stream name if this is an alias.
streamName = ((ApplicationInstance)client.getAppInstance()).internalResolvePlayAlias(streamName, client);

if (authorizePlay(queryString, clientIP, streamName))
this.invokePrevious(client, function, params);
if (invalidConfiguration)
{
getLogger().error(this.getClass().getSimpleName() + " play: rejecting session due to invalid stacksURL property " + streamName);
client.shutdownClient();
}
else
{
getLogger().error(this.getClass().getSimpleName() + " play: rejecting due to invalid stacksURL property " + streamName);
sendClientOnStatusError((IClient)client, "NetStream.Play.Failed", "Rejected due to invalid token");
client.shutdownClient();
String queryString = client.getQueryStr();
String clientIP = client.getIp();

if (authorizePlay(queryString, clientIP, streamName))
this.invokePrevious(client, function, params);
else
{
sendClientOnStatusError((IClient)client, "NetStream.Play.Failed", "Rejected due to invalid token");
client.shutdownClient();
}
}
}

Expand Down
131 changes: 131 additions & 0 deletions test/edu/stanford/dlss/wowza/TestSulWowzaFlash.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

import org.apache.log4j.*;

import com.wowza.wms.amf.AMFDataList;
import com.wowza.wms.application.ApplicationInstance;
import com.wowza.wms.application.IApplicationInstance;
import com.wowza.wms.application.WMSProperties;
import com.wowza.wms.client.IClient;
import com.wowza.wms.httpstreamer.cupertinostreaming.httpstreamer.HTTPStreamerSessionCupertino;
import com.wowza.wms.httpstreamer.model.IHTTPStreamerSession;
import com.wowza.wms.httpstreamer.mpegdashstreaming.httpstreamer.HTTPStreamerSessionMPEGDash;
import com.wowza.wms.request.RequestFunction;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -206,6 +210,133 @@ public void onHTTPMPEGDashStreamingSessionCreate_rejectsSession_ifInvalidConfigu
verify(spyModule, never()).authorizeSession(sessionMock);
}

@Test
public void play_shutsDownClient_ifInvalidConfiguration()
{
testModule.invalidConfiguration = true;
SulWowzaFlash spyModule = spy(testModule);
IClient clientMock = mock(IClient.class);
RequestFunction rfMock = mock(RequestFunction.class);
AMFDataList amfMock = mock(AMFDataList.class);
ApplicationInstance appInstanceMock = mock(ApplicationInstance.class);
when(clientMock.getAppInstance()).thenReturn(appInstanceMock);
when(appInstanceMock.internalResolvePlayAlias(null, clientMock)).thenReturn("stream.mp4");

spyModule.play(clientMock, rfMock, amfMock);

verify(clientMock).shutdownClient();
verify(spyModule, never()).authorizePlay(null, null, "stream.mp4");
}

@Test
public void play_calls_AuthorizePlay_ifValidConfiguration()
{
testModule.invalidConfiguration = false;
SulWowzaFlash spyModule = spy(testModule);
IClient clientMock = mock(IClient.class);
RequestFunction rfMock = mock(RequestFunction.class);
AMFDataList amfMock = mock(AMFDataList.class);
ApplicationInstance appInstanceMock = mock(ApplicationInstance.class);
when(clientMock.getAppInstance()).thenReturn(appInstanceMock);
when(appInstanceMock.internalResolvePlayAlias(null, clientMock)).thenReturn("stream.mp4");

spyModule.play(clientMock, rfMock, amfMock);

verify(spyModule).authorizePlay(null, null, "stream.mp4");
}

@Test
public void authorizePlay_trueIfAuthorized()
{
String filename = "ignored";
String streamName = "oo/000/oo/0000/" + filename;
String druid = "oo000oo0000";
String queryString = "query";
String userIp = "1.1.1.1";
String token = "abcd";
SulWowzaFlash spyModule = spy(testModule);

when(spyModule.getStacksToken(queryString)).thenReturn(token);
when(spyModule.validateStacksToken(token)).thenReturn(true);
when(spyModule.validateUserIp(userIp)).thenReturn(true);
when(spyModule.validateStreamName(streamName)).thenReturn(true);
when(spyModule.getDruid(streamName)).thenReturn(druid);
when(spyModule.getFilename(streamName)).thenReturn(filename);
when(spyModule.verifyStacksToken(token, druid, filename, userIp)).thenReturn(true);

assertEquals(true, spyModule.authorizePlay(queryString, userIp, streamName));
}

@Test
public void authorizePlay_falseIfAuthorized()
{
String filename = "ignored";
String streamName = "oo/000/oo/0000/" + filename;
String druid = "oo000oo0000";
String queryString = "query";
String userIp = "1.1.1.1";
String token = "abcd";
SulWowzaFlash spyModule = spy(testModule);

when(spyModule.getStacksToken(queryString)).thenReturn(token);
when(spyModule.validateStacksToken(token)).thenReturn(true);
when(spyModule.validateUserIp(userIp)).thenReturn(true);
when(spyModule.validateStreamName(streamName)).thenReturn(true);
when(spyModule.getDruid(streamName)).thenReturn(druid);
when(spyModule.getFilename(streamName)).thenReturn(filename);
when(spyModule.verifyStacksToken(token, druid, filename, userIp)).thenReturn(false);

assertEquals(false, spyModule.authorizePlay(queryString, userIp, streamName));
}

@Test
public void authorizePlay_validatesStacksToken()
{
String queryString = "query";
String userIp = "1.1.1.1";
String streamName = "stream.mp4";
String token = "abcd";

SulWowzaFlash spyModule = spy(testModule);
when(spyModule.getStacksToken(queryString)).thenReturn(token);

spyModule.authorizePlay(queryString, userIp, streamName);
verify(spyModule).validateStacksToken(token);
}

@Test
public void authorizePlay_validatesUserIp()
{
String queryString = "query";
String userIp = "1.1.1.1";
String streamName = "stream.mp4";
String token = "abcd";

SulWowzaFlash spyModule = spy(testModule);
when(spyModule.getStacksToken(queryString)).thenReturn(token);
when(spyModule.validateStacksToken(token)).thenReturn(true);

spyModule.authorizePlay(queryString, userIp, streamName);
verify(spyModule).validateUserIp(userIp);
}

@Test
public void authorizePlay_validatesStreamName()
{
String queryString = "query";
String userIp = "1.1.1.1";
String streamName = "stream.mp4";
String token = "abcd";

SulWowzaFlash spyModule = spy(testModule);
when(spyModule.getStacksToken(queryString)).thenReturn(token);
when(spyModule.validateStacksToken(token)).thenReturn(true);
when(spyModule.validateUserIp(userIp)).thenReturn(true);

spyModule.authorizePlay(queryString, userIp, streamName);
verify(spyModule).validateStreamName(streamName);
}

@Test
public void setStacksConnectionTimeout_validPropertyValue()
{
Expand Down

0 comments on commit 4e10c2a

Please sign in to comment.