PrincipalName_test.go 1.5 KB

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