def test_str(self):
     rule = CasbinRule(ptype='p', v0='alice', v1='data1', v2='read')
     self.assertEqual(str(rule), 'p, alice, data1, read')
     rule = CasbinRule(ptype='p', v0='bob', v1='data2', v2='write')
     self.assertEqual(str(rule), 'p, bob, data2, write')
     rule = CasbinRule(ptype='p', v0='data2_admin', v1='data2', v2='read')
     self.assertEqual(str(rule), 'p, data2_admin, data2, read')
     rule = CasbinRule(ptype='p', v0='data2_admin', v1='data2', v2='write')
     self.assertEqual(str(rule), 'p, data2_admin, data2, write')
     rule = CasbinRule(ptype='g', v0='alice', v1='data2_admin')
     self.assertEqual(str(rule), 'g, alice, data2_admin')
def get_enforcer():
    engine = create_engine("sqlite://")
    adapter = Adapter(engine)

    session = sessionmaker(bind=engine)
    Base.metadata.create_all(engine)
    s = session()

    s.add(CasbinRule(ptype='p', v0='alice', v1='data1', v2='read'))
    s.add(CasbinRule(ptype='p', v0='bob', v1='data2', v2='write'))
    s.add(CasbinRule(ptype='p', v0='data2_admin', v1='data2', v2='read'))
    s.add(CasbinRule(ptype='p', v0='data2_admin', v1='data2', v2='write'))
    s.add(CasbinRule(ptype='g', v0='alice', v1='data2_admin'))
    s.commit()
    s.close()

    return casbin.Enforcer(get_fixture('rbac_model.conf'), adapter, True)
Beispiel #3
0
def get_enforcer():
    engine = create_engine("sqlite://")
    # engine = create_engine('sqlite:///' + os.path.split(os.path.realpath(__file__))[0] + '/test.db', echo=True)
    adapter = Adapter(engine)

    session = sessionmaker(bind=engine)
    Base.metadata.create_all(engine)
    s = session()
    s.query(CasbinRule).delete()
    s.add(CasbinRule(ptype="p", v0="alice", v1="data1", v2="read"))
    s.add(CasbinRule(ptype="p", v0="bob", v1="data2", v2="write"))
    s.add(CasbinRule(ptype="p", v0="data2_admin", v1="data2", v2="read"))
    s.add(CasbinRule(ptype="p", v0="data2_admin", v1="data2", v2="write"))
    s.add(CasbinRule(ptype="g", v0="alice", v1="data2_admin"))
    s.commit()
    s.close()

    return casbin.Enforcer(get_fixture("rbac_model.conf"), adapter)
def get_enforcer():
    engine = create_engine("sqlite://")
    # engine = create_engine('sqlite:///' + os.path.split(os.path.realpath(__file__))[0] + '/test.db', echo=True)
    adapter = Adapter(engine)

    session = sessionmaker(bind=engine)
    Base.metadata.create_all(engine)
    s = session()
    s.query(CasbinRule).delete()
    s.add(CasbinRule(ptype='p', v0='alice', v1='data1', v2='read'))
    s.add(CasbinRule(ptype='p', v0='bob', v1='data2', v2='write'))
    s.add(CasbinRule(ptype='p', v0='data2_admin', v1='data2', v2='read'))
    s.add(CasbinRule(ptype='p', v0='data2_admin', v1='data2', v2='write'))
    s.add(CasbinRule(ptype='g', v0='alice', v1='data2_admin'))
    s.commit()
    s.close()

    return casbin.Enforcer(get_fixture('rbac_model.conf'), adapter)
Beispiel #5
0
    def test_repr(self):
        rule = CasbinRule(ptype="p", v0="alice", v1="data1", v2="read")
        self.assertEqual(repr(rule), '<CasbinRule None: "p, alice, data1, read">')
        engine = create_engine("sqlite://")

        session = sessionmaker(bind=engine)
        Base.metadata.create_all(engine)
        s = session()

        s.add(rule)
        s.commit()
        self.assertRegex(repr(rule), r'<CasbinRule \d+: "p, alice, data1, read">')
        s.close()
def enforcer(app_fixture):
    engine = create_engine("sqlite://")
    adapter = Adapter(engine)

    session = sessionmaker(bind=engine)
    Base.metadata.create_all(engine)
    s = session()
    s.query(CasbinRule).delete()
    s.add(CasbinRule(ptype="p", v0="alice", v1="/item", v2="GET"))
    s.add(CasbinRule(ptype="p", v0="bob", v1="/item", v2="GET"))
    s.add(CasbinRule(ptype="p", v0="data2_admin", v1="/item", v2="POST"))
    s.add(CasbinRule(ptype="p", v0="data2_admin", v1="/item", v2="DELETE"))
    s.add(CasbinRule(ptype="p", v0="data2_admin", v1="/item", v2="GET"))
    s.add(CasbinRule(ptype="g", v0="alice", v1="data2_admin"))
    s.add(CasbinRule(ptype="g", v0="users", v1="data2_admin"))
    s.add(CasbinRule(ptype="g", v0="group with space", v1="data2_admin"))
    s.commit()
    s.close()

    yield CasbinEnforcer(app_fixture, adapter)
Beispiel #7
0
 def test_str(self):
     rule = CasbinRule(ptype="p", v0="alice", v1="data1", v2="read")
     self.assertEqual(str(rule), "p, alice, data1, read")
 def test_str(self):
     rule = CasbinRule(ptype='p', v0='alice', v1='data1', v2='read')
     self.assertEqual(str(rule), 'p, alice, data1, read')