com.brightcove.test.upload.HLS.Encrypted.HLSEncryptionIntegrationTest.java Source code

Java tutorial

Introduction

Here is the source code for com.brightcove.test.upload.HLS.Encrypted.HLSEncryptionIntegrationTest.java

Source

/**
 * Copyright (C) 2011 Brightcove Inc. All Rights Reserved. No use, copying or distribution of this
 * work may be made except in accordance with a valid license agreement from Brightcove Inc. This
 * notice must be included on all copies, modifications and derivatives of this work.
 * 
 * Brightcove Inc MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. BRIGHTCOVE SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS
 * SOFTWARE OR ITS DERIVATIVES.
 * 
 * "Brightcove" is a registered trademark of Brightcove Inc.
 */
package com.brightcove.test.upload.HLS.Encrypted;

import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Vector;

import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;

import com.brightcove.com.uploader.verifier.AppleStreamingCheck;
import com.brightcove.com.uploader.waiter.WaiterHelper;
import com.brightcove.common.logging.BrightcoveLog;
import com.brightcove.test.upload.HLS.HLSBaseClass;
import com.brightcove.uploader.config.Account;
import com.brightcove.uploader.config.Environment;
import com.brightcove.uploader.config.ParameterList;
import com.brightcove.uploader.exception.BadEnvironmentException;
import com.brightcove.uploader.exception.MediaAPIError;
import com.brightcove.uploader.upload.IngestFile;
import com.brightcove.uploader.upload.Options;

/**
 * Test to verify TTL and SSL on rendition and KeyFile
 * 
 * @author ppasad
 * 
 */
public class HLSEncryptionIntegrationTest extends HLSBaseClass {

    private BrightcoveLog mLog = BrightcoveLog.getLogger(this.getClass());
    public Account mAccountInfo;
    public Environment mEnvironment;

    public static final String SOURCE_FILE_NAME = "10sec.mp4";
    IngestFile videoFile;
    Long videoId = 123L;
    String refId = "HLSE";
    String readToken;
    String writeToken;
    int noOfRenditionVideoContains = 3;
    HLSEConfiguration hlsConfig = new HLSEConfiguration();

    @Before
    public void setup() throws URISyntaxException, IOException, MediaAPIError, JSONException,
            BadEnvironmentException, InterruptedException {
        readToken = "84xzLDZQOh6SCuzTeFcgn146rwFaaWCL6EwIS_51Oh500zVWltNkSw..";
        writeToken = "QE7M90_ZbHqxI9CN_j8tzXWUB24VQId49NSiRjWd8WNa7gy0VvlmFA..";
        mAccountInfo = setAccountInfo("qa+appleSecurity@brightcove.com", "joejoe", "1136918641001", readToken,
                writeToken);
        mEnvironment = setEnvironmentsInfo("test.environment", "kong");
        setTecondeAttributes(mEnvironment, hlsConfig.getAttributesForTencodeConfig());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForGobblesCache());
        setGobblesSeedCache(mEnvironment, hlsConfig.getAttributesForGobblesCache());
        if (!videoExistByRefId(mAccountInfo, mEnvironment, refId)) {
            uploadMBRVideo();
        } else {
            videoId = Long
                    .parseLong(retrivePropertyValueFromJSONResponse(mAccountInfo, mEnvironment, refId, "", "id"));
        }

    }

    public void uploadMBRVideo() throws URISyntaxException, MalformedURLException, MediaAPIError, JSONException,
            BadEnvironmentException, InterruptedException {
        Options uploadOpts = new Options();
        uploadOpts.setMBR(true);
        videoFile = new IngestFile(getAbsoluteVideoFilePath(SOURCE_FILE_NAME), refId, uploadOpts);
        videoId = uploadVideo(videoFile, mAccountInfo, mEnvironment);
        ParameterList paramList = new ParameterList(mAccountInfo, "find_video_by_id", "video_id",
                videoId.toString(), "", "IOSRenditions");
        WaiterHelper renditionComplete = new WaiterHelper();
        renditionComplete.renditionWaiter(mAccountInfo, mEnvironment, paramList, noOfRenditionVideoContains,
                1200000L);
        assertNotNull(videoId);
    }

    /**
     * Verify the output when TTL features switch is enabled for KeyFiles
     * @throws MediaAPIError 
     */
    @Test
    public void testTTLOnKeyFile() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesAllKeyFileTTL());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForTTLGobblesConfig());
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        mLog.debug("TTl : " + videoId);
        appleCheck.assertTTL(retriveKeyFilesURLS(mAccountInfo, mEnvironment, videoId));
    }

    /**
     * Verify the output when TTL on keyFile has expired
     * @throws MediaAPIError 
     */
    @Test
    public void testTTLExpirationOnKeyFile() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesAllKeyFileTTL());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForTTLGobblesConfig());
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        mLog.debug("TTl : " + videoId);
        appleCheck.assertTTLExpiration(retriveKeyFilesURLS(mAccountInfo, mEnvironment, videoId));

    }

    /**
     * Verify the result when TTL is disabled on origin but the TTLEnforcement Check is enabled on
     * gobbles and origin
     * @throws MediaAPIError 
     */
    @Test
    public void testTTLEncforcementCheckOnKeyFile() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesForTTLEnformentCheckOnKeyFile());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForTTLGobblesConfig());
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        appleCheck.assetEnforcementCheck(retriveKeyFilesURLS(mAccountInfo, mEnvironment, videoId));
    }

    /**
     * Verify that all keyfile url are https and points to secure.nrightcove.com
     * @throws MediaAPIError 
     */

    @Test
    public void testSSLOnKeyFile() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesAllKeyFileSSL());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForSSLGobblesConfig());
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        appleCheck.assertURLAreSSLSecured(retriveKeyFilesURLS(mAccountInfo, mEnvironment, videoId));
    }

    /**
     * Verify the SSL Enforcement Check on KeyFile URL
     * @throws MediaAPIError 
     */
    @Test
    public void testSSLEnforcementCheckOnKeyFile() throws MediaAPIError {

        setOriginAttributes(mEnvironment, hlsConfig.getAttributesForSSLEnformentCheckOnKeyFile());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForSSLGobblesConfig());
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        appleCheck.assetEnforcementCheck(retriveKeyFilesURLS(mAccountInfo, mEnvironment, videoId));

    }

    /**
     * Test does following checks 1. Verify the output when TTL on keyfiles are valid 2. Verify if
     * keyfile contain SSL support 3. Verify the output when TTL on keyFiles have expired
     * @throws MediaAPIError 
     */
    @Test
    public void testSSLTTLOnKeyFile() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesAllKeyFileSSLTTL());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForTTLSSLGobblesConfig());
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        Vector keyFile = retriveKeyFilesURLS(mAccountInfo, mEnvironment, videoId);
        appleCheck.assertTTL(keyFile);
        appleCheck.assertURLAreSSLSecured(keyFile);
        appleCheck.assertTTLExpiration(keyFile);
    }

    /**
     * Verify the TTL on Rendition Urls
     * @throws MediaAPIError 
     */

    @Test
    public void testTTLOnRendition() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesAllRenditionFileTTL());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForTTLGobblesConfig());
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        Vector rendition = retriveRenditionURL(mAccountInfo, mEnvironment, videoId);
        if (!rendition.isEmpty()) {
            appleCheck.assertTTL(rendition);
        }
    }

    /**
     * Verify the output when ttl on rendition url have expired
     * @throws MediaAPIError 
     */
    @Test
    public void testTTLExpirationOnRendition() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesAllRenditionFileTTL());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForTTLGobblesConfig());
        Vector rendition = retriveRenditionURL(mAccountInfo, mEnvironment, videoId);
        if (!rendition.isEmpty()) {
            AppleStreamingCheck appleCheck = new AppleStreamingCheck();
            appleCheck.assertTTLExpiration(rendition);
        }

    }

    /**
     * Verify the output when TTL are not enabled on origin by enforcement check is enabled on
     * gobbles and origin
     * @throws MediaAPIError 
     */
    @Test
    public void testTTLEncforcementCheckOnRendition() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesForTTLEnformentCheckOnRendition());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForTTLGobblesConfig());
        Vector rendition = retriveRenditionURL(mAccountInfo, mEnvironment, videoId);
        if (!rendition.isEmpty()) {
            AppleStreamingCheck appleCheck = new AppleStreamingCheck();

            appleCheck.assetEnforcementCheck(rendition);
        }
    }

    /**
     * Verify the SSL support on Rendition URL
     * @throws MediaAPIError 
     */
    @Test
    public void testSSLOnRenditionURL() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesAllRenditionFileSSL());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForSSLGobblesConfig());
        Vector rendition = retriveRenditionURL(mAccountInfo, mEnvironment, videoId);
        if (!rendition.isEmpty()) {
            AppleStreamingCheck appleCheck = new AppleStreamingCheck();
            appleCheck.assertURLAreSSLSecured(rendition);
        }
    }

    /**
     * Verify the SSL Enforcement Check on Rendition URL
     * @throws MediaAPIError 
     */
    @Test
    public void testSSLEnforcementCheckOnRenditionURL() throws MediaAPIError {

        setOriginAttributes(mEnvironment, hlsConfig.getAttributesForSSLEnformentCheckOnRendition());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForSSLGobblesConfig());
        Vector rendition = retriveRenditionURL(mAccountInfo, mEnvironment, videoId);
        if (!rendition.isEmpty()) {
            AppleStreamingCheck appleCheck = new AppleStreamingCheck();
            appleCheck.assetEnforcementCheck(rendition);
        }

    }

    /**
     * Test does following checks 1. Verify the output when TTL Token on rendition is valid 2.
     * Verify the Rendition url has SSL support 3. Verify the output when TTL Token on rendition URL
     * are expired
     * @throws MediaAPIError 
     */

    @Test
    public void testSSLTTLOnRendition() throws MediaAPIError {
        setOriginAttributes(mEnvironment, hlsConfig.getAttributesAllRenditionSSLTTL());
        setGobblesEdgeAttributes(mEnvironment, hlsConfig.getAttributesForTTLSSLGobblesConfig());
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        Vector rendition = retriveRenditionURL(mAccountInfo, mEnvironment, videoId);
        if (!rendition.isEmpty()) {
            appleCheck.assertTTL(rendition);
            appleCheck.assertURLAreSSLSecured(rendition);
            appleCheck.assertTTLExpiration(rendition);
        }
    }

}