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

     1  package types
     2  
     3  import (
     4  	"encoding/hex"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/jcmturner/gokrb5/v8/iana/adtype"
     9  	"github.com/jcmturner/gokrb5/v8/iana/nametype"
    10  	"github.com/jcmturner/gokrb5/v8/test/testdata"
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestUnmarshalAuthorizationData(t *testing.T) {
    15  	t.Parallel()
    16  	var a AuthorizationData
    17  	b, err := hex.DecodeString(testdata.MarshaledKRB5authorization_data)
    18  	if err != nil {
    19  		t.Fatalf("Test vector read error: %v", err)
    20  	}
    21  	err = a.Unmarshal(b)
    22  	if err != nil {
    23  		t.Fatalf("Unmarshal error: %v", err)
    24  	}
    25  	assert.Equal(t, 2, len(a), "Number of authorization data entries not as expected")
    26  	for i, entry := range a {
    27  		assert.Equal(t, adtype.ADIfRelevant, entry.ADType, fmt.Sprintf("Authorization data type of entry %d not as expected", i+1))
    28  		assert.Equal(t, []byte("foobar"), entry.ADData, fmt.Sprintf("Authorization data of entry %d not as expected", i+1))
    29  	}
    30  }
    31  
    32  func TestUnmarshalAuthorizationData_kdcissued(t *testing.T) {
    33  	t.Parallel()
    34  	var a ADKDCIssued
    35  	b, err := hex.DecodeString(testdata.MarshaledKRB5ad_kdcissued)
    36  	if err != nil {
    37  		t.Fatalf("Test vector read error: %v", err)
    38  	}
    39  	err = a.Unmarshal(b)
    40  	if err != nil {
    41  		t.Fatalf("Unmarshal error: %v", err)
    42  	}
    43  	assert.Equal(t, int32(1), a.ADChecksum.CksumType, "Checksum type not as expected")
    44  	assert.Equal(t, []byte("1234"), a.ADChecksum.Checksum, "Checksum not as expected")
    45  	assert.Equal(t, testdata.TEST_REALM, a.IRealm, "Issuing realm not as expected")
    46  	assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.Isname.NameType, "Issuing name type not as expected")
    47  	assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.Isname.NameString, "Issuing name string entries not as expected")
    48  	assert.Equal(t, 2, len(a.Elements), "Number of authorization data elements not as expected")
    49  	for i, ele := range a.Elements {
    50  		assert.Equal(t, adtype.ADIfRelevant, ele.ADType, fmt.Sprintf("Authorization data type of element %d not as expected", i+1))
    51  		assert.Equal(t, []byte(testdata.TEST_AUTHORIZATION_DATA_VALUE), ele.ADData, fmt.Sprintf("Authorization data of element %d not as expected", i+1))
    52  	}
    53  }