acl_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package acl
  2. import "testing"
  3. func TestACLRead(t *testing.T) {
  4. readp := []byte("foobar")
  5. acl := newTestEmpty()
  6. acl.GrantRead(readp)
  7. for i := 0; i < len(readp); i++ {
  8. r := acl.Read(readp[:i])
  9. if r == true {
  10. t.Errorf("#%d.deny: r = %t, want %t", i, r, false)
  11. }
  12. }
  13. for i := 0; i < len(readp); i++ {
  14. r := acl.Read(append(readp, readp[:i]...))
  15. if r == false {
  16. t.Errorf("#%d.allow: r = %t, want %t", i, r, true)
  17. }
  18. }
  19. }
  20. func TestACLWrite(t *testing.T) {
  21. writep := []byte("foobar")
  22. acl := newTestEmpty()
  23. acl.GrantWrite(writep)
  24. for i := 0; i < len(writep); i++ {
  25. w := acl.Write(writep[:i])
  26. if w == true {
  27. t.Errorf("#%d.deny: w = %t, want %t", i, w, false)
  28. }
  29. }
  30. for i := 0; i < len(writep); i++ {
  31. w := acl.Write(append(writep, writep[:i]...))
  32. if w == false {
  33. t.Errorf("#%d.allow: w = %t, want %t", i, w, true)
  34. }
  35. }
  36. }
  37. func TestACLManage(t *testing.T) {
  38. managep := []byte("foobar")
  39. acl := newTestEmpty()
  40. acl.GrantManage(managep)
  41. for i := 0; i < len(managep); i++ {
  42. m := acl.Manage(managep[:i])
  43. if m == true {
  44. t.Errorf("#%d.deny: m = %t, want %t", i, m, false)
  45. }
  46. }
  47. for i := 0; i < len(managep); i++ {
  48. m := acl.Manage(append(managep, managep[:i]...))
  49. if m == false {
  50. t.Errorf("#%d.allow: m = %t, want %t", i, m, true)
  51. }
  52. }
  53. }
  54. func TestACLRevoke(t *testing.T) {
  55. readp := []byte("foobar")
  56. acl := newTestEmpty()
  57. acl.GrantRead(readp)
  58. if !acl.Read(readp) {
  59. t.Errorf("r = %t, want %t", false, true)
  60. }
  61. acl.RevokeRead(readp)
  62. if acl.Read(readp) {
  63. t.Errorf("r = %t, want %t", true, false)
  64. }
  65. }
  66. func newTestEmpty() ACL {
  67. return &acl{}
  68. }