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