RDK Documentation (Open Sourced RDK Components)
legacyDrmSessionTest.cpp
1 #include <vector>
2 #include <iostream>
3 #include <iomanip>
4 #include <algorithm>
5 #include <iterator>
6 #include <memory>
7 #include<cjson/cJSON.h>
8 
10 #include "AampDRMSessionManager.h"
11 
12 #include "CppUTest/TestHarness.h"
13 #include "CppUTestExt/MockSupport.h"
14 
15 #include "aampMocks.h"
16 #include "curlMocks.h"
17 
18 TEST_GROUP(AampLegacyDrmSessionTests)
19 {
20  PrivateInstanceAAMP *mAamp;
21  AampDRMSessionManager *sessionManager;
22  AampLogManager mLogging;
23  int mMaxDrmSessions = 1;
24 
25  AampDRMSessionManager* getSessionManager()
26  {
27  if (sessionManager == nullptr)
28  {
29  sessionManager = new AampDRMSessionManager(&mLogging, mMaxDrmSessions);
30  }
31 
32  return sessionManager;
33  }
34 
35  void setupCurlPerformResponse(std::string response)
36  {
37  static string responseStr = response;
38 
39  MockCurlSetPerformCallback([](CURL *curl, MockCurlWriteCallback writeCallback, void* writeData, void* userData) {
40  writeCallback((char*)responseStr.c_str(), 1, responseStr.size(), writeData);
41  }, this);
42  }
43 
44  void setup()
45  {
46  MockAampReset();
47  MockCurlReset();
49  }
50 
51  void teardown()
52  {
53  if (sessionManager != nullptr)
54  {
55  sessionManager->clearSessionData();
56  SAFE_DELETE(sessionManager);
57  }
58 
59  if (NULL != mAamp)
60  {
61  delete mAamp;
62  mAamp = NULL;
63  }
64 
65  MockAampReset();
66  MockCurlReset();
67  }
68 };
69 
70 TEST(AampLegacyDrmSessionTests, TestCreateClearkeySession)
71 {
72  AampDRMSessionManager *sessionManager = getSessionManager();
73 
74  cJSON *keysObj = cJSON_CreateObject();
75  cJSON *keyInstanceObj = cJSON_CreateObject();
76  cJSON_AddStringToObject(keyInstanceObj, "alg", "cbc");
77  cJSON_AddStringToObject(keyInstanceObj, "k", "_u3wDe7erb7v8Lqt8A3QDQ");
78  cJSON_AddStringToObject(keyInstanceObj, "kid", "_u3wDe7erb7v8Lqt8A3QDQ");
79  cJSON *keysArr = cJSON_AddArrayToObject(keysObj, "keys");
80  cJSON_AddItemToArray(keysArr, keyInstanceObj);
81 
82  char *keyResponse = cJSON_PrintUnformatted(keysObj);
83  setupCurlPerformResponse(keyResponse);
84  cJSON_free(keyResponse);
85  cJSON_Delete(keysObj);
86 
87  const unsigned char initData[] = {
88  0x00, 0x00, 0x00, 0x34, 0x70, 0x73, 0x73, 0x68, 0x01, 0x00, 0x00, 0x00, 0x10, 0x77, 0xef, 0xec,
89  0xc0, 0xb2, 0x4d, 0x02, 0xac, 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b, 0x00, 0x00, 0x00, 0x01,
90  0xfe, 0xed, 0xf0, 0x0d, 0xee, 0xde, 0xad, 0xbe, 0xef, 0xf0, 0xba, 0xad, 0xf0, 0x0d, 0xd0, 0x0d,
91  0x00, 0x00, 0x00, 0x00};
92 
93  DrmMetaDataEventPtr aampEvent = std::make_shared<DrmMetaDataEvent>(AAMP_TUNE_FAILURE_UNKNOWN, "", 0, 0, false);
94  AampDrmSession *drmSession = sessionManager->createDrmSession(
95  "1077efec-c0b2-4d02-ace3-3c1e52e2fb4b",
97  initData,
98  sizeof(initData),
100  mAamp,
101  aampEvent,
102  NULL,
103  true);
104  CHECK_TEXT(drmSession != NULL, "Session creation failed");
105 }
AampDRMSessionManager.h
Header file for DRM session manager.
AampDRMSessionManager::createDrmSession
AampDrmSession * createDrmSession(const char *systemId, MediaFormat mediaFormat, const unsigned char *initDataPtr, uint16_t dataLength, MediaType streamType, PrivateInstanceAAMP *aamp, DrmMetaDataEventPtr e, const unsigned char *contentMetadata=nullptr, bool isPrimarySession=false)
Creates and/or returns the DRM session corresponding to keyId (Present in initDataPtr) AampDRMSession...
Definition: AampDRMSessionManager.cpp:875
eMEDIATYPE_VIDEO
@ eMEDIATYPE_VIDEO
Definition: AampMediaType.h:39
gpGlobalConfig
AampConfig * gpGlobalConfig
Global configuration.
Definition: main_aamp.cpp:48
AampDRMSessionManager
Controller for managing DRM sessions.
Definition: AampDRMSessionManager.h:145
eMEDIAFORMAT_DASH
@ eMEDIAFORMAT_DASH
Definition: AampDrmMediaFormat.h:35
AAMP_TUNE_FAILURE_UNKNOWN
@ AAMP_TUNE_FAILURE_UNKNOWN
Definition: AampEvent.h:147
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
aampdrmsessionfactory.h
Header file for AampDrmSessionFactory.
AampDrmSession
Base class for DRM sessions.
Definition: AampDrmSession.h:69
AampDRMSessionManager::clearSessionData
void clearSessionData()
Clean up the memory used by session variables.
Definition: AampDRMSessionManager.cpp:155
PrivateInstanceAAMP
Class representing the AAMP player's private instance, which is not exposed to outside world.
Definition: priv_aamp.h:640