<commit_before>describe "pedant API" do
  let(:mattdamon) { "deadbeefdeadbeefdeadbeefdeadbeef" }

  context "sanity check" do
    # What we are testing:

    # Here we take all of the patterns used in the other tests and
    # verify that the permissions are correctly set up by the helper
    # functions.

    # We are explictly testing:
    #   with_ace_on_actor
    #   with_acl_on_actor
    # And indirectly:
    #   with_actor(s)
    #   with_group(s)
    #   with_members (for actors and groups)
    # We then verify the permissions and memberships with
    #   directly_have_permission
    #   be_a_direct_member_of

    ['CREATE', 'READ', 'UPDATE', 'DELETE', 'GRANT'].each do |action|
      context "for #{action} ACE" do
        context "for single ACE on actor" do
          with_actors :hasselhoff, :shatner

          with_ace_on_actor :shatner, action.downcase.to_sym, :actors => [:hasselhoff]

          it "has permission" do
            :hasselhoff.should directly_have_permission(action.downcase.to_sym).
              on_actor(:shatner)
          end
        end

        context "an actor NOT in the ACE" do
          with_actors :malkovich, :shatner

          # Give malkovich everything EXCEPT action
          acl = {
            :create => {:actors => [:malkovich], :groups => []},
            :read   => {:actors => [:malkovich], :groups => []},
            :update => {:actors => [:malkovich], :groups => []},
            :delete => {:actors => [:malkovich], :groups => []},
            :grant  => {:actors => [:malkovich], :groups => []}
          }
          acl[action.downcase.to_sym] = {:actors => [], :groups => []}
          
          with_acl_on_actor :shatner, acl

          it "does not have permission" do
            :malkovich.should_not directly_have_permission(action.downcase.to_sym).
              on_actor(:shatner)
          end
        end

        context "an actor indirectly in the ACE" do
          with_actors :hasselhoff, :shatner, :malkovich
          with_group :hipsters

          with_ace_on_actor :shatner, action.downcase.to_sym, :groups => [:hipsters]
          with_members :hipsters, :actors => [:hasselhoff]

          it "has only indirect permission" do
            :hasselhoff.should_not directly_have_permission(action.downcase.to_sym).
              on_actor(:shatner)
            :hasselhoff.should be_a_direct_member_of(:hipsters)
            :hipsters.should directly_have_permission(action.downcase.to_sym).
              on_actor(:shatner)
          end
        end

        context "an actor doubly-indirectly in the ACE" do
          with_actors :hasselhoff, :shatner
          with_groups :hipsters, :brogrammers

          with_ace_on_actor :shatner, action.downcase.to_sym, :groups => [:brogrammers]
          with_members :brogrammers, :groups => [:hipsters]
          with_members :hipsters, :actors => [:hasselhoff]

          it "has only doubly-indirect permission" do
            :hasselhoff.should_not directly_have_permission(action.downcase.to_sym).
              on_actor(:shatner)
            :hasselhoff.should be_a_direct_member_of(:hipsters)
            :hipsters.should be_a_direct_member_of(:brogrammers)
            :hipsters.should_not directly_have_permission(action.downcase.to_sym).
              on_actor(:shatner)
            :brogrammers.should directly_have_permission(action.downcase.to_sym).
              on_actor(:shatner)
          end
        end
      end
    end

    context "an actor with NO ACE" do
      with_actors :malkovich, :shatner

      # Give malkovich no access at all
      with_acl_on_actor :shatner, {
        :create => {:actors => [], :groups => []},
        :read   => {:actors => [], :groups => []},
        :update => {:actors => [], :groups => []},
        :delete => {:actors => [], :groups => []},
        :grant  => {:actors => [], :groups => []}
      }

      it "has no permissions" do
        :malkovich.should_not directly_have_permission(:create).on_actor(:shatner) 
        :malkovich.should_not directly_have_permission(:read).on_actor(:shatner)
        :malkovich.should_not directly_have_permission(:update).on_actor(:shatner)
        :malkovich.should_not directly_have_permission(:delete).on_actor(:shatner)
        :malkovich.should_not directly_have_permission(:grant).on_actor(:shatner)
      end
    end

    context "an actor with full ACE" do
      with_actors :hasselhoff, :shatner

      # Give hasselhoff full access
      with_acl_on_actor :shatner, {
        :create => {:actors => [:hasselhoff], :groups => []},
        :read   => {:actors => [:hasselhoff], :groups => []},
        :update => {:actors => [:hasselhoff], :groups => []},
        :delete => {:actors => [:hasselhoff], :groups => []},
        :grant  => {:actors => [:hasselhoff], :groups => []}
      }

      it "has all permissions" do
        :hasselhoff.should directly_have_permission(:create).on_actor(:shatner) 
        :hasselhoff.should directly_have_permission(:read).on_actor(:shatner)
        :hasselhoff.should directly_have_permission(:update).on_actor(:shatner)
        :hasselhoff.should directly_have_permission(:delete).on_actor(:shatner)
        :hasselhoff.should directly_have_permission(:grant).on_actor(:shatner)
      end
    end
  end # sanity check
end<commit_msg>Added sanity tests for groups<commit_after>describe "pedant API" do
  context "sanity check" do
    # What we are testing:

    # Here we take all of the patterns used in the other tests and
    # verify that the permissions are correctly set up by the helper
    # functions.

    # We are explictly testing:
    #   with_ace_on_actor
    #   with_acl_on_actor
    #   with_ace_on_group
    #   with_acl_on_group
    #   (with_ace_on_object) = not yet
    #   (with_acl_on_object)
    #   (with_ace_on_container)
    #   (with_acl_on_container)
    # And indirectly:
    #   with_actor(s)
    #   with_group(s)
    #   (with_object)
    #   (with_container)
    #   with_members (for actors and groups)
    # We then verify the permissions and memberships with
    #   directly_have_permission
    #     on_actor
    #     on_group
    #     (on_object)
    #     (on_container)
    #   be_a_direct_member_of

    context "for actors" do
      ['CREATE', 'READ', 'UPDATE', 'DELETE', 'GRANT'].each do |action|
        context "for #{action} ACE" do
          context "for single ACE on actor" do
            with_actors :hasselhoff, :shatner

            with_ace_on_actor :shatner, action.downcase.to_sym, :actors => [:hasselhoff]

            it "has permission" do
              :hasselhoff.should directly_have_permission(action.downcase.to_sym).
                on_actor(:shatner)
            end
          end

          context "an actor NOT in the ACE" do
            with_actors :malkovich, :shatner

            # Give malkovich everything EXCEPT action
            acl = {
              :create => {:actors => [:malkovich], :groups => []},
              :read   => {:actors => [:malkovich], :groups => []},
              :update => {:actors => [:malkovich], :groups => []},
              :delete => {:actors => [:malkovich], :groups => []},
              :grant  => {:actors => [:malkovich], :groups => []}
            }
            acl[action.downcase.to_sym] = {:actors => [], :groups => []}
          
            with_acl_on_actor :shatner, acl

            it "does not have permission" do
              :malkovich.should_not directly_have_permission(action.downcase.to_sym).
                on_actor(:shatner)
            end
          end

          context "an actor indirectly in the ACE" do
            with_actors :hasselhoff, :shatner
            with_group :hipsters

            with_ace_on_actor :shatner, action.downcase.to_sym, :groups => [:hipsters]
            with_members :hipsters, :actors => [:hasselhoff]

            it "has only indirect permission" do
              :hasselhoff.should_not directly_have_permission(action.downcase.to_sym).
                on_actor(:shatner)
              :hasselhoff.should be_a_direct_member_of(:hipsters)
              :hipsters.should directly_have_permission(action.downcase.to_sym).
                on_actor(:shatner)
            end
          end

          context "an actor doubly-indirectly in the ACE" do
            with_actors :hasselhoff, :shatner
            with_groups :hipsters, :brogrammers

            with_ace_on_actor :shatner, action.downcase.to_sym, :groups => [:brogrammers]
            with_members :brogrammers, :groups => [:hipsters]
            with_members :hipsters, :actors => [:hasselhoff]

            it "has only doubly-indirect permission" do
              :hasselhoff.should_not directly_have_permission(action.downcase.to_sym).
                on_actor(:shatner)
              :hasselhoff.should be_a_direct_member_of(:hipsters)
              :hipsters.should be_a_direct_member_of(:brogrammers)
              :hipsters.should_not directly_have_permission(action.downcase.to_sym).
                on_actor(:shatner)
              :brogrammers.should directly_have_permission(action.downcase.to_sym).
                on_actor(:shatner)
            end
          end
        end
      end

      context "an actor with NO ACE" do
        with_actors :malkovich, :shatner

        # Give malkovich no access at all
        with_acl_on_actor :shatner, {
          :create => {:actors => [], :groups => []},
          :read   => {:actors => [], :groups => []},
          :update => {:actors => [], :groups => []},
          :delete => {:actors => [], :groups => []},
          :grant  => {:actors => [], :groups => []}
        }

        it "has no permissions" do
          :malkovich.should_not directly_have_permission(:create).on_actor(:shatner) 
          :malkovich.should_not directly_have_permission(:read).on_actor(:shatner)
          :malkovich.should_not directly_have_permission(:update).on_actor(:shatner)
          :malkovich.should_not directly_have_permission(:delete).on_actor(:shatner)
          :malkovich.should_not directly_have_permission(:grant).on_actor(:shatner)
        end
      end

      context "an actor with full ACE" do
        with_actors :hasselhoff, :shatner

        # Give hasselhoff full access
        with_acl_on_actor :shatner, {
          :create => {:actors => [:hasselhoff], :groups => []},
          :read   => {:actors => [:hasselhoff], :groups => []},
          :update => {:actors => [:hasselhoff], :groups => []},
          :delete => {:actors => [:hasselhoff], :groups => []},
          :grant  => {:actors => [:hasselhoff], :groups => []}
        }

        it "has all permissions" do
          :hasselhoff.should directly_have_permission(:create).on_actor(:shatner) 
          :hasselhoff.should directly_have_permission(:read).on_actor(:shatner)
          :hasselhoff.should directly_have_permission(:update).on_actor(:shatner)
          :hasselhoff.should directly_have_permission(:delete).on_actor(:shatner)
          :hasselhoff.should directly_have_permission(:grant).on_actor(:shatner)
        end
      end
    end # for actors

    context "for groups" do
      ['CREATE', 'READ', 'UPDATE', 'DELETE', 'GRANT'].each do |action|
        context "for #{action} ACE" do
          context "for single ACE on actor" do
            with_actor :hasselhoff
            with_group :hipsters

            with_ace_on_group :hipsters, action.downcase.to_sym, :actors => [:hasselhoff]

            it "has permission" do
              :hasselhoff.should directly_have_permission(action.downcase.to_sym).
                on_group(:hipsters)
            end
          end

          context "an actor NOT in the ACE" do
            with_actor :malkovich
            with_group :hipsters

            # Give malkovich everything EXCEPT action
            acl = {
              :create => {:actors => [:malkovich], :groups => []},
              :read   => {:actors => [:malkovich], :groups => []},
              :update => {:actors => [:malkovich], :groups => []},
              :delete => {:actors => [:malkovich], :groups => []},
              :grant  => {:actors => [:malkovich], :groups => []}
            }
            acl[action.downcase.to_sym] = {:actors => [], :groups => []}
          
            with_acl_on_group :hipsters, acl

            it "does not have permission" do
              :malkovich.should_not directly_have_permission(action.downcase.to_sym).
                on_group(:hipsters)
            end
          end

          context "an actor indirectly in the ACE" do
            with_actor :hasselhoff
            with_groups :hipsters, :commies

            with_ace_on_group :commies, action.downcase.to_sym, :groups => [:hipsters]
            with_members :hipsters, :actors => [:hasselhoff]

            it "has only indirect permission" do
              :hasselhoff.should_not directly_have_permission(action.downcase.to_sym).
                on_group(:commies)
              :hasselhoff.should be_a_direct_member_of(:hipsters)
              :hipsters.should directly_have_permission(action.downcase.to_sym).
                on_group(:commies)
            end
          end

          context "an actor doubly-indirectly in the ACE" do
            with_actor :hasselhoff
            with_groups :hipsters, :brogrammers, :commies

            with_ace_on_group :commies, action.downcase.to_sym, :groups => [:brogrammers]
            with_members :brogrammers, :groups => [:hipsters]
            with_members :hipsters, :actors => [:hasselhoff]

            it "has only doubly-indirect permission" do
              :hasselhoff.should_not directly_have_permission(action.downcase.to_sym).
                on_group(:commies)
              :hasselhoff.should be_a_direct_member_of(:hipsters)
              :hipsters.should be_a_direct_member_of(:brogrammers)
              :hipsters.should_not directly_have_permission(action.downcase.to_sym).
                on_group(:commies)
              :brogrammers.should directly_have_permission(action.downcase.to_sym).
                on_group(:commies)
            end
          end
        end
      end

      context "an actor with NO ACE" do
        with_actor :malkovich
        with_group :hipsters

        # Give malkovich no access at all
        with_acl_on_group :hipsters, {
          :create => {:actors => [], :groups => []},
          :read   => {:actors => [], :groups => []},
          :update => {:actors => [], :groups => []},
          :delete => {:actors => [], :groups => []},
          :grant  => {:actors => [], :groups => []}
        }

        it "has no permissions" do
          :malkovich.should_not directly_have_permission(:create).on_group(:hipsters) 
          :malkovich.should_not directly_have_permission(:read).on_group(:hipsters)
          :malkovich.should_not directly_have_permission(:update).on_group(:hipsters)
          :malkovich.should_not directly_have_permission(:delete).on_group(:hipsters)
          :malkovich.should_not directly_have_permission(:grant).on_group(:hipsters)
        end
      end

      context "an actor with full ACE" do
        with_actor :hasselhoff
        with_group :hipsters

        # Give hasselhoff full access
        with_acl_on_group :hipsters, {
          :create => {:actors => [:hasselhoff], :groups => []},
          :read   => {:actors => [:hasselhoff], :groups => []},
          :update => {:actors => [:hasselhoff], :groups => []},
          :delete => {:actors => [:hasselhoff], :groups => []},
          :grant  => {:actors => [:hasselhoff], :groups => []}
        }

        it "has all permissions" do
          :hasselhoff.should directly_have_permission(:create).on_group(:hipsters) 
          :hasselhoff.should directly_have_permission(:read).on_group(:hipsters)
          :hasselhoff.should directly_have_permission(:update).on_group(:hipsters)
          :hasselhoff.should directly_have_permission(:delete).on_group(:hipsters)
          :hasselhoff.should directly_have_permission(:grant).on_group(:hipsters)
        end
      end
    end # for groups
  end # sanity check
end
{'fraction_non_alphanumeric': 0.11815812337098175, 'fraction_numerical': 0.0, 'mean_word_length': 2.3042854213655937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 162, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3588563', 'n_tokens_mistral': 5157, 'n_tokens_neox': 4786, 'n_words': 1013}