Skip to content

Commit

Permalink
Create concatInitDataIdAndCertificate.test.ts
Browse files Browse the repository at this point in the history
Signed-off-by: Agajan Jumakuliyev <agajan.tm@gmail.com>
  • Loading branch information
agajassi committed Feb 25, 2025
1 parent 18a16bd commit be90e59
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/test/drm/fairplay/concatInitDataIdAndCertificate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { concatInitDataIdAndCertificate } from '@svta/common-media-library/drm/fairplay/concatInitDataIdAndCertificate';
import { base64decode } from '@svta/common-media-library/utils/base64decode';
import { deepStrictEqual } from 'node:assert';
import { describe, it } from 'node:test';

// initData and CKC appCertData from Apple's FairPlay example
const mockInitDataBase64 = `AAAAAgAAAACIiMWpQhMDI6pMnx2nfIiIMoaz9xQolnPlrBsRFKyANk3mGrJ0R1rb476dlbP7gfY5RHrSdUdvEMIMIbCl3hrGj96RIuGb4MDZqIWAo2FGwODnjP7FqW00fMY9kWRiTPngKU3dY3agBnZ8glOEskarDrEQak`;
const mockAppCertDataBase64 = `AAAAAQAAAACt1bxIOvg1vAIIGMHiRWJ+AAAB8AK5R4nipOTa0/xTM8wCdT3LnZV2knbPIhjUkPBalO9vOjZsqRL8EuFzMy8vhfThzSdS/faGZIdj6Izki7v8K85nBNm6PWqwYjKGilecApnwEwBMIQFXh2ihWECoNe1AMDG7BMXgxW7xxt2K9gm4NlSif4uHlASElGAoev0As3CJy3t11DLeVm/B6aKyga0NJ8o2ujeTtjlKtaa7aPT1JQHA8nIdHnfrEFoK8P9melrtn0/CZiMaPYu9W+NF2woOOKuIf3Z2GvIkh4evSlQcSLysoSTxt4xKRyyG87WRrbFhBR1U7ZIsqQfodWLCtJ++/RsUsrjOscml7fqJ1auyMZWflkARsCOQumAz61bWw1oGjWcnbsshnckOBq/wBG6ZZgw7tBaed/gx33PLkNKfnIDNvGU210W9O9ZYPan0A6t8b5DgUlCWvs1JdE08Kw0yLEelvnfPTXJEgoGuD6vpKnCHG9JpAZOWEKbnnrYMnPAMwbKHiOIehb85mJQ7N5nFUCM5oLc01uO8HbB13sxhq+OxrwiSjqBRqEzZj2GXDbc+50I80LjMnboZDSB+EeUn0dHp4yWOr2FG0KQaqLgUs3F6Ylmey9Rf5IilL7f1/YkSl3pea/w+Qi4VcDYTj+2tqOT6gnDmrv5jNJ2uUsViR/g=`;

const initData = base64decode(mockInitDataBase64);
const appCertData = base64decode(mockAppCertDataBase64);
const contentId = new TextEncoder().encode('skd://svta.com/content1234');

describe('concatInitDataIdAndCertificate', () => {
it('concatenates initData, id, and certificate correctly', () => {
const result = concatInitDataIdAndCertificate(initData, contentId, appCertData);

// It should be 8-bit integer type and contain data
deepStrictEqual(result instanceof Uint8Array, true);
deepStrictEqual(result.length > 0, true);
});

it('handles empty certificate and id correctly', () => {
const id = '';
const cert = new Uint8Array([]);
const result = concatInitDataIdAndCertificate(initData, id, cert);

// Length should account for added ID and cert size and
// first part should match initData
deepStrictEqual(result.length, initData.byteLength + 4 + 4);
deepStrictEqual(result.slice(0, initData.byteLength), new Uint8Array(initData));
});
});

0 comments on commit be90e59

Please sign in to comment.