TypedData_test.go 813 B

123456789101112131415161718192021222324252627
  1. package types
  2. import (
  3. "encoding/hex"
  4. "github.com/stretchr/testify/assert"
  5. "testing"
  6. "github.com/jcmturner/gokrb5/testdata"
  7. "fmt"
  8. )
  9. func TestUnmarshalTypedData(t *testing.T) {
  10. var a TypedDataSequence
  11. v := "encode_krb5_typed_data"
  12. b, err := hex.DecodeString(testdata.TestVectors[v])
  13. if err != nil {
  14. t.Fatalf("Test vector read error of %s: %v\n", v, err)
  15. }
  16. err = a.Unmarshal(b)
  17. if err != nil {
  18. t.Fatalf("Unmarshal error of %s: %v\n", v, err)
  19. }
  20. assert.Equal(t, 2, len(a), "Number of typed data elements not as expected")
  21. for i, d := range a {
  22. assert.Equal(t, testdata.TEST_PADATA_TYPE, d.DataType, fmt.Sprintf("Data type of element %d not as expected", i+1))
  23. assert.Equal(t, []byte(testdata.TEST_PADATA_VALUE), d.DataValue, fmt.Sprintf("Data value of element %d not as expected", i+1))
  24. }
  25. }