github.com/jcmturner/gokrb5/v8@v8.4.4/messages/APReq_test.go (about) 1 package messages 2 3 import ( 4 "encoding/hex" 5 "testing" 6 7 "github.com/jcmturner/gokrb5/v8/iana" 8 "github.com/jcmturner/gokrb5/v8/iana/msgtype" 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 TestUnmarshalAPReq(t *testing.T) { 15 t.Parallel() 16 var a APReq 17 b, err := hex.DecodeString(testdata.MarshaledKRB5ap_req) 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, iana.PVNO, a.PVNO, "PVNO not as expected") 26 assert.Equal(t, msgtype.KRB_AP_REQ, a.MsgType, "MsgType is not as expected") 27 assert.Equal(t, "fedcba98", hex.EncodeToString(a.APOptions.Bytes), "AP Options not as expected") 28 assert.Equal(t, iana.PVNO, a.Ticket.TktVNO, "Ticket VNO not as expected") 29 assert.Equal(t, testdata.TEST_REALM, a.Ticket.Realm, "Ticket realm not as expected") 30 assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.Ticket.SName.NameType, "Ticket SName NameType not as expected") 31 assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.Ticket.SName.NameString), "Ticket SName does not have the expected number of NameStrings") 32 assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.Ticket.SName.NameString, "Ticket SName name string entries not as expected") 33 assert.Equal(t, testdata.TEST_ETYPE, a.Ticket.EncPart.EType, "Ticket encPart etype not as expected") 34 assert.Equal(t, iana.PVNO, a.Ticket.EncPart.KVNO, "Ticket encPart KVNO not as expected") 35 assert.Equal(t, []byte(testdata.TEST_CIPHERTEXT), a.Ticket.EncPart.Cipher, "Ticket encPart cipher not as expected") 36 } 37 38 func TestMarshalAPReq(t *testing.T) { 39 t.Parallel() 40 var a APReq 41 b, err := hex.DecodeString(testdata.MarshaledKRB5ap_req) 42 if err != nil { 43 t.Fatalf("Test vector read error: %v", err) 44 } 45 err = a.Unmarshal(b) 46 if err != nil { 47 t.Fatalf("Unmarshal error: %v", err) 48 } 49 mb, err := a.Marshal() 50 if err != nil { 51 t.Fatalf("Marshal of ticket errored: %v", err) 52 } 53 assert.Equal(t, b, mb, "Marshal bytes of Authenticator not as expected") 54 }