| 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/adtype" |
| 10 | "gopkg.in/jcmturner/gokrb5.v5/iana/nametype" |
| 11 | "gopkg.in/jcmturner/gokrb5.v5/testdata" |
| 12 | ) |
| 13 | |
| 14 | func TestUnmarshalAuthorizationData(t *testing.T) { |
| 15 | t.Parallel() |
| 16 | var a AuthorizationData |
| 17 | v := "encode_krb5_authorization_data" |
| 18 | b, err := hex.DecodeString(testdata.TestVectors[v]) |
| 19 | if err != nil { |
| 20 | t.Fatalf("Test vector read error of %s: %v\n", v, err) |
| 21 | } |
| 22 | err = a.Unmarshal(b) |
| 23 | if err != nil { |
| 24 | t.Fatalf("Unmarshal error of %s: %v\n", v, err) |
| 25 | } |
| 26 | assert.Equal(t, 2, len(a), "Number of authorization data entries not as expected") |
| 27 | for i, entry := range a { |
| 28 | assert.Equal(t, adtype.ADIfRelevant, entry.ADType, fmt.Sprintf("Authorization data type of entry %d not as expected", i+1)) |
| 29 | assert.Equal(t, []byte("foobar"), entry.ADData, fmt.Sprintf("Authorization data of entry %d not as expected", i+1)) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | func TestUnmarshalAuthorizationData_kdcissued(t *testing.T) { |
| 34 | t.Parallel() |
| 35 | var a ADKDCIssued |
| 36 | v := "encode_krb5_ad_kdcissued" |
| 37 | b, err := hex.DecodeString(testdata.TestVectors[v]) |
| 38 | if err != nil { |
| 39 | t.Fatalf("Test vector read error of %s: %v\n", v, err) |
| 40 | } |
| 41 | err = a.Unmarshal(b) |
| 42 | if err != nil { |
| 43 | t.Fatalf("Unmarshal error of %s: %v\n", v, err) |
| 44 | } |
| 45 | assert.Equal(t, int32(1), a.ADChecksum.CksumType, "Checksum type not as expected") |
| 46 | assert.Equal(t, []byte("1234"), a.ADChecksum.Checksum, "Checksum not as expected") |
| 47 | assert.Equal(t, testdata.TEST_REALM, a.IRealm, "Issuing realm not as expected") |
| 48 | assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.Isname.NameType, "Issuing name type not as expected") |
| 49 | assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.Isname.NameString, "Issuing name string entries not as expected") |
| 50 | assert.Equal(t, 2, len(a.Elements), "Number of authorization data elements not as expected") |
| 51 | for i, ele := range a.Elements { |
| 52 | assert.Equal(t, adtype.ADIfRelevant, ele.ADType, fmt.Sprintf("Authorization data type of element %d not as expected", i+1)) |
| 53 | assert.Equal(t, []byte(testdata.TEST_AUTHORIZATION_DATA_VALUE), ele.ADData, fmt.Sprintf("Authorization data of element %d not as expected", i+1)) |
| 54 | } |
| 55 | } |