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