TypedData_test.go 870 B

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