RDK Documentation (Open Sourced RDK Components)
drmUtilsTest.cpp
1 #include <vector>
2 
3 #include "AampDRMutils.h"
4 
5 #include "CppUTest/TestHarness.h"
6 
7 TEST_GROUP(AampDrmUtilsTests)
8 {
9 };
10 
11 TEST(AampDrmUtilsTests, TestGetAbsoluteKeyUri)
12 {
13  struct GetAbsoluteKeyUriTestData
14  {
15  std::string manifestUrl;
16  std::string keyUri;
17  std::string expectedUri;
18  };
19 
20  const std::vector<GetAbsoluteKeyUriTestData> testData = {
21  // manifestUrl // keyUri // expectedUri
22  {"http://stream.example/manifest.m3u8", "basic1.key", "http://stream.example/basic1.key"},
23  {"http://stream.example/manifest.m3u8", "basic2", "http://stream.example/basic2"},
24  {"http://stream.example/manifest", "basic3", "http://stream.example/basic3"},
25  {"http://stream.example/assets/hls/manifest.m3u8", "basic4.key", "http://stream.example/assets/hls/basic4.key"},
26 
27  // Relative path which refers to a parent directory. We copy ../ instances as-is, these can be resolved by curl
28  {"http://stream.example/asset/1080p/manifest.m3u8", "../relkey1.key", "http://stream.example/asset/1080p/../relkey1.key"},
29  {"http://stream.example/asset/1080p/../manifest.m3u8", "../relkey2.key", "http://stream.example/asset/1080p/../../relkey2.key"},
30 
31  // Port number included
32  {"http://stream.example:1234/manifest.m3u8", "port1.key", "http://stream.example:1234/port1.key"},
33 
34  // HTTPS
35  {"https://stream.example/manifest.m3u8", "secure1.key", "https://stream.example/secure1.key"},
36 
37  // Absolute path reference on key URI
38  {"http://stream.example/manifest.m3u8", "/absref1.key", "http://stream.example/absref1.key"},
39  {"http://stream.example/assets/hls/manifest.m3u8", "/absref2.key", "http://stream.example/absref2.key"},
40 
41  // Absolute key URIs
42  {"http://stream.example/manifest.m3u8", "http://key.example/abs1.key", "http://key.example/abs1.key"},
43  {"", "http://key.example/abs2.key", "http://key.example/abs2.key"},
44 
45  // Keys with arguments
46  {"http://stream.example/manifest.m3u8", "arg1.key?a=test", "http://stream.example/arg1.key?a=test"},
47  {"http://stream.example/manifest.m3u8", "arg2.key?a=http://", "http://stream.example/arg2.key?a=http://"},
48 
49  // Only domain present on manifest URL (not normally expected, but should be handled OK)
50  {"http://stream.example", "domonly1.key", "http://stream.example/domonly1.key"},
51  {"http://stream.example/", "domonly2.key", "http://stream.example/domonly2.key"},
52  {"http://stream.example", "/domonly3.key", "http://stream.example/domonly3.key"},
53 
54  // Other protocols for the key (HTTP expected, but this utility is expected to be protocol agnostic)
55  {"http://example/manifest.m3u8", "file://prot1.key", "file://prot1.key"},
56  // Still a valid scheme (- . and + are allowed)
57  {"http://example/manifest.m3u8", "a-b.c+d://prot2.key", "a-b.c+d://prot2.key"},
58  // Not a valid scheme - will default to relative
59  {"http://example/manifest.m3u8", "#abc!://prot3.key", "http://example/#abc!://prot3.key"},
60  // Capitalised protocol accepted
61  {"http://example/manifest.m3u8", "HTTP://key.example/prot4.key", "HTTP://key.example/prot4.key"},
62  };
63 
64  for (auto test : testData)
65  {
66  std::string keyURI;
67  aamp_ResolveURL(keyURI, test.manifestUrl, test.keyUri.c_str(), false);
68  CHECK_EQUAL(test.expectedUri, keyURI.c_str());
69  }
70 }
AampDRMutils.h
Context-free common utility functions.
aamp_ResolveURL
void aamp_ResolveURL(std::string &dst, std::string base, const char *uri, bool bPropagateUriParams)
Resolve file URL from the base and file path.
Definition: AampUtils.cpp:157