ldap_helpers_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package ldap
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. "gopkg.in/ldap.v3"
  6. )
  7. func TestLDAPHelpers(t *testing.T) {
  8. Convey("isMemberOf()", t, func() {
  9. Convey("Wildcard", func() {
  10. result := isMemberOf([]string{}, "*")
  11. So(result, ShouldBeTrue)
  12. })
  13. Convey("Should find one", func() {
  14. result := isMemberOf([]string{"one", "Two", "three"}, "two")
  15. So(result, ShouldBeTrue)
  16. })
  17. Convey("Should not find one", func() {
  18. result := isMemberOf([]string{"one", "Two", "three"}, "twos")
  19. So(result, ShouldBeFalse)
  20. })
  21. })
  22. Convey("getAttribute()", t, func() {
  23. Convey("Should get username", func() {
  24. value := []string{"roelgerrits"}
  25. entry := &ldap.Entry{
  26. Attributes: []*ldap.EntryAttribute{
  27. {
  28. Name: "username", Values: value,
  29. },
  30. },
  31. }
  32. result := getAttribute("username", entry)
  33. So(result, ShouldEqual, value[0])
  34. })
  35. Convey("Should not get anything", func() {
  36. value := []string{"roelgerrits"}
  37. entry := &ldap.Entry{
  38. Attributes: []*ldap.EntryAttribute{
  39. {
  40. Name: "killa", Values: value,
  41. },
  42. },
  43. }
  44. result := getAttribute("username", entry)
  45. So(result, ShouldEqual, "")
  46. })
  47. })
  48. Convey("getArrayAttribute()", t, func() {
  49. Convey("Should get username", func() {
  50. value := []string{"roelgerrits"}
  51. entry := &ldap.Entry{
  52. Attributes: []*ldap.EntryAttribute{
  53. {
  54. Name: "username", Values: value,
  55. },
  56. },
  57. }
  58. result := getArrayAttribute("username", entry)
  59. So(result, ShouldResemble, value)
  60. })
  61. Convey("Should not get anything", func() {
  62. value := []string{"roelgerrits"}
  63. entry := &ldap.Entry{
  64. Attributes: []*ldap.EntryAttribute{
  65. {
  66. Name: "username", Values: value,
  67. },
  68. },
  69. }
  70. result := getArrayAttribute("something", entry)
  71. So(result, ShouldResemble, []string{})
  72. })
  73. })
  74. }