github.com/jcmturner/gokrb5/v8@v8.4.4/messages/APRep_test.go (about)

     1  package messages
     2  
     3  import (
     4  	"encoding/hex"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/jcmturner/gokrb5/v8/iana"
     9  	"github.com/jcmturner/gokrb5/v8/iana/msgtype"
    10  	"github.com/jcmturner/gokrb5/v8/test/testdata"
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestUnmarshalAPRep(t *testing.T) {
    15  	t.Parallel()
    16  	var a APRep
    17  	b, err := hex.DecodeString(testdata.MarshaledKRB5ap_rep)
    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_REP, a.MsgType, "MsgType is not as expected")
    27  	assert.Equal(t, testdata.TEST_ETYPE, a.EncPart.EType, "Ticket encPart etype not as expected")
    28  	assert.Equal(t, iana.PVNO, a.EncPart.KVNO, "Ticket encPart KVNO not as expected")
    29  	assert.Equal(t, []byte(testdata.TEST_CIPHERTEXT), a.EncPart.Cipher, "Ticket encPart cipher not as expected")
    30  }
    31  
    32  func TestUnmarshalEncAPRepPart(t *testing.T) {
    33  	t.Parallel()
    34  	var a EncAPRepPart
    35  	b, err := hex.DecodeString(testdata.MarshaledKRB5ap_rep_enc_part)
    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  	//Parse the test time value into a time.Time type
    44  	tt, _ := time.Parse(testdata.TEST_TIME_FORMAT, testdata.TEST_TIME)
    45  
    46  	assert.Equal(t, tt, a.CTime, "CTime not as expected")
    47  	assert.Equal(t, 123456, a.Cusec, "Client microseconds not as expected")
    48  	assert.Equal(t, int32(1), a.Subkey.KeyType, "Subkey type not as expected")
    49  	assert.Equal(t, []byte("12345678"), a.Subkey.KeyValue, "Subkey value not as expected")
    50  	assert.Equal(t, int64(17), a.SequenceNumber, "Sequence number not as expected")
    51  }
    52  
    53  func TestUnmarshalEncAPRepPart_optionalsNULL(t *testing.T) {
    54  	t.Parallel()
    55  	var a EncAPRepPart
    56  	b, err := hex.DecodeString(testdata.MarshaledKRB5ap_rep_enc_partOptionalsNULL)
    57  	if err != nil {
    58  		t.Fatalf("Test vector read error: %v", err)
    59  	}
    60  	err = a.Unmarshal(b)
    61  	if err != nil {
    62  		t.Fatalf("Unmarshal error: %v", err)
    63  	}
    64  	//Parse the test time value into a time.Time type
    65  	tt, _ := time.Parse(testdata.TEST_TIME_FORMAT, testdata.TEST_TIME)
    66  
    67  	assert.Equal(t, tt, a.CTime, "CTime not as expected")
    68  	assert.Equal(t, 123456, a.Cusec, "Client microseconds not as expected")
    69  }