-
Notifications
You must be signed in to change notification settings - Fork 10
/
pssh_test.go
55 lines (46 loc) · 1.75 KB
/
pssh_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package widevine
import (
"encoding/base64"
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
wvpb "github.com/iyear/gowidevine/widevinepb"
)
func decodeBase64(t require.TestingT, b64 string) []byte {
b, err := base64.StdEncoding.DecodeString(b64)
require.NoError(t, err)
return b
}
func TestNewPSSH(t *testing.T) {
pssh := decodeBase64(t, "AAAAU3Bzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAADMIARIQQATcHlpOAIf1Vdda4clXIBoHc3BvdGlmeSIUQATcHlpOAIf1Vdda4clXIDt20eY=")
p, err := NewPSSH(pssh)
require.NoError(t, err)
assert.Equal(t, byte(0), p.Version())
assert.Equal(t, uint32(0), p.Flags())
assert.Equal(t,
"080112104004dc1e5a4e0087f555d75ae1c957201a0773706f7469667922144004dc1e5a4e0087f555d75ae1c957203b76d1e6",
hex.EncodeToString(p.RawData()))
assert.Equal(t, "spotify", p.Data().GetProvider()) // nolint: staticcheck
assert.Len(t, p.Data().GetKeyIds(), 1)
assert.Equal(t, "4004dc1e5a4e0087f555d75ae1c95720", hex.EncodeToString(p.Data().GetKeyIds()[0]))
assert.Equal(t, "4004dc1e5a4e0087f555d75ae1c957203b76d1e6", hex.EncodeToString(p.Data().GetContentId()))
assert.Equal(t, wvpb.WidevinePsshData_AESCTR, p.Data().GetAlgorithm()) // nolint: staticcheck
}
func TestNewPSSHFail(t *testing.T) {
tests := []struct {
name string
pssh string
}{
{name: "invalid box", pssh: "ZmFpbA=="},
// mp4.CttsBox{EndSampleNr: []uint32{1, 1, 1}, SampleOffset: []int32{1}}
{name: "invalid box type", pssh: "AAAAGGN0dHMAAAAAAAAAAQAAAAAAAAAB"},
{name: "invalid system id", pssh: "AAAAIHBzc2gAAAAAmgTweZhAQoarkuZb4IhflQAAAAA="},
// "foo"
{name: "invalid data", pssh: "AAAAI3Bzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAANmb28="},
}
for _, tt := range tests {
_, err := NewPSSH(decodeBase64(t, tt.pssh))
assert.Error(t, err)
}
}