Beispiel #1
0
    def test_allow_nonanonymous(self):
        context = BaseContext()
        context.logger = logging.getLogger(__name__)
        context.config = {"auth": {"allow-anonymous": False}}

        async def coro():
            s = Session(None)
            s.username = "******"
            auth_plugin = AnonymousAuthPlugin(context)
            ret = await auth_plugin.authenticate(session=s)
            self.assertTrue(ret)

        anyio.run(coro)
Beispiel #2
0
    def test_create_tables(self):
        dbfile = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                              "test.db")
        context = BaseContext()
        context.logger = logging.getLogger(__name__)
        context.config = {"persistence": {"file": dbfile}}
        SQLitePlugin(context)

        conn = sqlite3.connect(dbfile)
        cursor = conn.cursor()
        rows = cursor.execute(
            "SELECT name FROM sqlite_master where type = 'table'")
        tables = []
        for row in rows:
            tables.append(row[0])
        self.assertIn("session", tables)
Beispiel #3
0
    def test_wrong_password(self):
        context = BaseContext()
        context.logger = logging.getLogger(__name__)
        context.config = {
            "auth": {
                "password-file": os.path.join(
                    os.path.dirname(os.path.realpath(__file__)), "passwd"
                )
            }
        }

        async def coro():
            s = Session(None)
            s.username = "******"
            s.password = "******"
            auth_plugin = FileAuthPlugin(context)
            ret = await auth_plugin.authenticate(session=s)
            self.assertFalse(ret)

        anyio.run(coro)
Beispiel #4
0
    def test_allow(self):
        context = BaseContext()
        context.logger = logging.getLogger(__name__)
        context.config = {
            'auth': {
                'password-file':
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             "passwd")
            }
        }

        async def coro():
            s = Session(None)
            s.username = "******"
            s.password = "******"
            auth_plugin = FileAuthPlugin(context)
            ret = await auth_plugin.authenticate(session=s)
            self.assertTrue(ret)

        anyio.run(coro)