@@ -12,6 +12,8 @@ import (
1212 "strings"
1313 "sync"
1414 "testing"
15+
16+ "github.com/grafov/m3u8"
1517)
1618
1719func TestSanitizeFilename (t * testing.T ) {
@@ -586,3 +588,40 @@ func TestEmbedMetadata_Fail(t *testing.T) {
586588 t .Error ("expected error when embedding metadata on a directory" )
587589 }
588590}
591+
592+ func TestDecryptSegment_GlobalKey (t * testing.T ) {
593+ client := & Client {
594+ httpClient : & http.Client {
595+ Transport : & mockTransport {
596+ RoundTripFunc : func (req * http.Request ) (* http.Response , error ) {
597+ return & http.Response {StatusCode : 200 , Body : io .NopCloser (strings .NewReader ("keydata012345678" ))}, nil
598+ },
599+ },
600+ },
601+ }
602+ seg := & m3u8.MediaSegment {}
603+ globalKey := & m3u8.Key {URI : "http://key" , IV : "0x00000000000000000000000000000000" }
604+ var cache sync.Map
605+ data := make ([]byte , 16 )
606+ _ , err := client .decryptSegment (context .Background (), data , seg , globalKey , 0 , & cache )
607+ if err != nil {
608+ t .Errorf ("decryptSegment failed: %v" , err )
609+ }
610+ }
611+
612+ func TestDecryptSegment_FetchKeyFail (t * testing.T ) {
613+ client := & Client {
614+ httpClient : & http.Client {
615+ Transport : & mockTransport {
616+ RoundTripFunc : func (req * http.Request ) (* http.Response , error ) {
617+ return nil , fmt .Errorf ("fetch fail" )
618+ },
619+ },
620+ },
621+ }
622+ seg := & m3u8.MediaSegment {Key : & m3u8.Key {URI : "http://key" }}
623+ _ , err := client .decryptSegment (context .Background (), nil , seg , nil , 0 , & sync.Map {})
624+ if err == nil {
625+ t .Error ("expected error" )
626+ }
627+ }
0 commit comments