def testSimpleAccess(self):
    """Tests that simple access requires a token."""

    client_urn = rdf_client.ClientURN("C.%016X" % 0)

    # These should raise for a lack of token
    for urn, mode in [("aff4:/ACL", "r"),
                      ("aff4:/config/drivers", "r"),
                      ("aff4:/", "rw"),
                      (client_urn, "r")]:
      self.assertRaises(access_control.UnauthorizedAccess, aff4.FACTORY.Open,
                        urn, mode=mode)

    # These should raise for trying to get write access.
    for urn, mode in [("aff4:/ACL", "rw"),
                      (client_urn, "rw")]:
      fd = aff4.FACTORY.Open(urn, mode=mode, token=self.token)
      # Force cache flush.
      fd._dirty = True
      self.assertRaises(access_control.UnauthorizedAccess, fd.Close)

    # These should raise for access without a token:
    for urn, mode in [(client_urn.Add("flows").Add("W:1234"), "r"),
                      (client_urn.Add("/fs"), "r")]:
      self.assertRaises(access_control.UnauthorizedAccess, aff4.FACTORY.Open,
                        urn, mode=mode)

      # Even if a token is provided - it is not authorized.
      self.assertRaises(access_control.UnauthorizedAccess, aff4.FACTORY.Open,
                        urn, mode=mode, token=self.token)
dataset/ETHPy150Open google/grr/grr/lib/aff4_objects/user_managers_test.py/FullAccessControlManagerIntegrationTest.testSimpleAccess/original