| 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/addrtype" |
| 10 |
"github.com/jcmturner/gokrb5/v8/iana/msgtype" |
| 11 |
"github.com/jcmturner/gokrb5/v8/test/testdata" |
| 12 |
"github.com/stretchr/testify/assert" |
| 13 |
) |
| 14 |
|
| 15 |
func TestUnmarshalKRBSafe(t *testing.T) { |
| 16 |
t.Parallel() |
| 17 |
var a KRBSafe |
| 18 |
b, err := hex.DecodeString(testdata.MarshaledKRB5safe) |
| 19 |
if err != nil { |
| 20 |
t.Fatalf("Test vector read error: %v", err) |
| 21 |
} |
| 22 |
err = a.Unmarshal(b) |
| 23 |
if err != nil { |
| 24 |
t.Fatalf("Unmarshal error: %v", err) |
| 25 |
} |
| 26 |
//Parse the test time value into a time.Time type |
| 27 |
tt, _ := time.Parse(testdata.TEST_TIME_FORMAT, testdata.TEST_TIME) |
| 28 |
|
| 29 |
assert.Equal(t, iana.PVNO, a.PVNO, "PVNO not as expected") |
| 30 |
assert.Equal(t, msgtype.KRB_SAFE, a.MsgType, "MsgType is not as expected") |
| 31 |
assert.Equal(t, []byte("krb5data"), a.SafeBody.UserData, "Safe body userdata not as expected") |
| 32 |
assert.Equal(t, tt, a.SafeBody.Timestamp, "Safe body timestamp not as expected") |
| 33 |
assert.Equal(t, 123456, a.SafeBody.Usec, "Safe body microseconds not as expected") |
| 34 |
assert.Equal(t, int64(17), a.SafeBody.SequenceNumber, "Safe body sequence number not as expected") |
| 35 |
assert.Equal(t, addrtype.IPv4, a.SafeBody.SAddress.AddrType, "SAddress type not as expected") |
| 36 |
assert.Equal(t, "12d00023", hex.EncodeToString(a.SafeBody.SAddress.Address), "SAddress not as expected") |
| 37 |
assert.Equal(t, addrtype.IPv4, a.SafeBody.RAddress.AddrType, "RAddress type not as expected") |
| 38 |
assert.Equal(t, "12d00023", hex.EncodeToString(a.SafeBody.RAddress.Address), "RAddress not as expected") |
| 39 |
assert.Equal(t, int32(1), a.Cksum.CksumType, "Checksum type not as expected") |
| 40 |
assert.Equal(t, []byte("1234"), a.Cksum.Checksum, "Checksum not as expected") |
| 41 |
} |
| 42 |
|
| 43 |
func TestUnmarshalKRBSafe_optionalsNULL(t *testing.T) { |
| 44 |
t.Parallel() |
| 45 |
var a KRBSafe |
| 46 |
b, err := hex.DecodeString(testdata.MarshaledKRB5safeOptionalsNULL) |
| 47 |
if err != nil { |
| 48 |
t.Fatalf("Test vector read error: %v", err) |
| 49 |
} |
| 50 |
err = a.Unmarshal(b) |
| 51 |
if err != nil { |
| 52 |
t.Fatalf("Unmarshal error: %v", err) |
| 53 |
} |
| 54 |
|
| 55 |
assert.Equal(t, iana.PVNO, a.PVNO, "PVNO not as expected") |
| 56 |
assert.Equal(t, msgtype.KRB_SAFE, a.MsgType, "MsgType is not as expected") |
| 57 |
assert.Equal(t, []byte("krb5data"), a.SafeBody.UserData, "Safe body userdata not as expected") |
| 58 |
assert.Equal(t, addrtype.IPv4, a.SafeBody.SAddress.AddrType, "SAddress type not as expected") |
| 59 |
assert.Equal(t, "12d00023", hex.EncodeToString(a.SafeBody.SAddress.Address), "SAddress not as expected") |
| 60 |
assert.Equal(t, int32(1), a.Cksum.CksumType, "Checksum type not as expected") |
| 61 |
assert.Equal(t, []byte("1234"), a.Cksum.Checksum, "Checksum not as expected") |
| 62 |
} |