| 1 |
package messages |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/hex" |
| 5 |
"testing" |
| 6 |
"time" |
| 7 |
|
| 8 |
"github.com/stretchr/testify/assert" |
| 9 |
"gopkg.in/jcmturner/gokrb5.v5/iana" |
| 10 |
"gopkg.in/jcmturner/gokrb5.v5/iana/errorcode" |
| 11 |
"gopkg.in/jcmturner/gokrb5.v5/iana/msgtype" |
| 12 |
"gopkg.in/jcmturner/gokrb5.v5/iana/nametype" |
| 13 |
"gopkg.in/jcmturner/gokrb5.v5/testdata" |
| 14 |
) |
| 15 |
|
| 16 |
func TestUnmarshalKRBError(t *testing.T) { |
| 17 |
t.Parallel() |
| 18 |
var a KRBError |
| 19 |
v := "encode_krb5_error" |
| 20 |
b, err := hex.DecodeString(testdata.TestVectors[v]) |
| 21 |
if err != nil { |
| 22 |
t.Fatalf("Test vector read error of %s: %v\n", v, err) |
| 23 |
} |
| 24 |
err = a.Unmarshal(b) |
| 25 |
if err != nil { |
| 26 |
t.Fatalf("Unmarshal error of %s: %v\n", v, err) |
| 27 |
} |
| 28 |
|
| 29 |
tt, _ := time.Parse(testdata.TEST_TIME_FORMAT, testdata.TEST_TIME) |
| 30 |
|
| 31 |
assert.Equal(t, iana.PVNO, a.PVNO, "PVNO is not as expected") |
| 32 |
assert.Equal(t, msgtype.KRB_ERROR, a.MsgType, "Message type is not as expected") |
| 33 |
assert.Equal(t, tt, a.CTime, "CTime not as expected") |
| 34 |
assert.Equal(t, 123456, a.Cusec, "Client microseconds not as expected") |
| 35 |
assert.Equal(t, tt, a.STime, "STime not as expected") |
| 36 |
assert.Equal(t, 123456, a.Susec, "Service microseconds not as expected") |
| 37 |
assert.Equal(t, errorcode.KRB_ERR_GENERIC, a.ErrorCode, "Error code not as expected") |
| 38 |
assert.Equal(t, testdata.TEST_REALM, a.CRealm, "CRealm not as expected") |
| 39 |
assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.CName.NameType, "CName NameType not as expected") |
| 40 |
assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.CName.NameString), "CName does not have the expected number of NameStrings") |
| 41 |
assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.CName.NameString, "CName entries not as expected") |
| 42 |
assert.Equal(t, testdata.TEST_REALM, a.Realm, "Realm not as expected") |
| 43 |
assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.SName.NameType, "Ticket SName NameType not as expected") |
| 44 |
assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.SName.NameString), "Ticket SName does not have the expected number of NameStrings") |
| 45 |
assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.SName.NameString, "Ticket SName name string entries not as expected") |
| 46 |
assert.Equal(t, "krb5data", a.EText, "EText not as expected") |
| 47 |
assert.Equal(t, []byte("krb5data"), a.EData, "EData not as expected") |
| 48 |
} |
| 49 |
|
| 50 |
func TestUnmarshalKRBError_optionalsNULL(t *testing.T) { |
| 51 |
t.Parallel() |
| 52 |
var a KRBError |
| 53 |
v := "encode_krb5_error(optionalsNULL)" |
| 54 |
b, err := hex.DecodeString(testdata.TestVectors[v]) |
| 55 |
if err != nil { |
| 56 |
t.Fatalf("Test vector read error of %s: %v\n", v, err) |
| 57 |
} |
| 58 |
err = a.Unmarshal(b) |
| 59 |
if err != nil { |
| 60 |
t.Fatalf("Unmarshal error of %s: %v\n", v, err) |
| 61 |
} |
| 62 |
|
| 63 |
tt, _ := time.Parse(testdata.TEST_TIME_FORMAT, testdata.TEST_TIME) |
| 64 |
|
| 65 |
assert.Equal(t, iana.PVNO, a.PVNO, "PVNO is not as expected") |
| 66 |
assert.Equal(t, msgtype.KRB_ERROR, a.MsgType, "Message type is not as expected") |
| 67 |
assert.Equal(t, 123456, a.Cusec, "Client microseconds not as expected") |
| 68 |
assert.Equal(t, tt, a.STime, "STime not as expected") |
| 69 |
assert.Equal(t, 123456, a.Susec, "Service microseconds not as expected") |
| 70 |
assert.Equal(t, errorcode.KRB_ERR_GENERIC, a.ErrorCode, "Error code not as expected") |
| 71 |
assert.Equal(t, testdata.TEST_REALM, a.Realm, "Realm not as expected") |
| 72 |
assert.Equal(t, nametype.KRB_NT_PRINCIPAL, a.SName.NameType, "Ticket SName NameType not as expected") |
| 73 |
assert.Equal(t, len(testdata.TEST_PRINCIPALNAME_NAMESTRING), len(a.SName.NameString), "Ticket SName does not have the expected number of NameStrings") |
| 74 |
assert.Equal(t, testdata.TEST_PRINCIPALNAME_NAMESTRING, a.SName.NameString, "Ticket SName name string entries not as expected") |
| 75 |
} |