1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
package types
import (
"github.com/stretchr/testify/assert"
"gopkg.in/jcmturner/gokrb5.v5/iana/nametype"
"testing"
)
func TestPrincipalName_GetSalt(t *testing.T) {
t.Parallel()
pn := PrincipalName{
NameType: 1,
NameString: []string{"firststring", "secondstring"},
}
assert.Equal(t, "TEST.GOKRB5firststringsecondstring", pn.GetSalt("TEST.GOKRB5"), "Principal name default salt not as expected")
}
func TestParseSPNString(t *testing.T) {
pn, realm := ParseSPNString("HTTP/www.example.com@REALM.COM")
assert.Equal(t, "REALM.COM", realm, "realm value not as expected")
assert.Equal(t, nametype.KRB_NT_PRINCIPAL, pn.NameType, "name type not as expected")
assert.Equal(t, "HTTP", pn.NameString[0], "first element of name string not as expected")
assert.Equal(t, "www.example.com", pn.NameString[1], "second element of name string not as expected")
pn, realm = ParseSPNString("HTTP/www.example.com")
assert.Equal(t, "", realm, "realm value not as expected")
assert.Equal(t, nametype.KRB_NT_PRINCIPAL, pn.NameType, "name type not as expected")
assert.Equal(t, "HTTP", pn.NameString[0], "first element of name string not as expected")
assert.Equal(t, "www.example.com", pn.NameString[1], "second element of name string not as expected")
pn, realm = ParseSPNString("www.example.com@REALM.COM")
assert.Equal(t, "REALM.COM", realm, "realm value not as expected")
assert.Equal(t, nametype.KRB_NT_PRINCIPAL, pn.NameType, "name type not as expected")
assert.Equal(t, "www.example.com", pn.NameString[0], "second element of name string not as expected")
}
|