TypedData_test.go 831 B

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