github.com/jcmturner/gokrb5/v8@v8.4.4/types/TypedData_test.go (about)

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