Пример #1
0
    def test_nonces_cleared(self):
        ''' Makes duplicate requests, but with the code patched so the nonce expiry time
            is shorter then the allowed Hawk skew. The second request succeeding gives
            evidence that the cache of nonces was cleared.
        '''
        self.setup_manual()

        now = datetime.datetime.now()
        past = now + datetime.timedelta(seconds=-45)

        with patch('app.NONCE_EXPIRE', 30):
            asyncio.ensure_future(run_application(), loop=self.loop)
            is_http_accepted_eventually()

            url = 'http://127.0.0.1:8080/'
            x_forwarded_for = '1.2.3.4, 4.4.4.4'

            with freeze_time(past):
                auth = auth_header(
                    'incoming-some-id-1',
                    'incoming-some-secret-1',
                    url,
                    'POST',
                    '',
                    '',
                )
                _, status_1 = self.loop.run_until_complete(
                    post_text(url, auth, x_forwarded_for))
            self.assertEqual(status_1, 200)

            with freeze_time(now):
                _, status_2 = self.loop.run_until_complete(
                    post_text(url, auth, x_forwarded_for))
            self.assertEqual(status_2, 200)
Пример #2
0
    def test_repeat_auth_then_401(self):
        self.setup_manual()

        asyncio.ensure_future(run_application(), loop=self.loop)
        is_http_accepted_eventually()

        url = 'http://127.0.0.1:8080/'
        auth = auth_header(
            'incoming-some-id-1',
            'incoming-some-secret-1',
            url,
            'POST',
            '',
            '',
        )
        x_forwarded_for = '1.2.3.4, 4.4.4.4'
        _, status_1 = self.loop.run_until_complete(
            post_text(url, auth, x_forwarded_for))
        self.assertEqual(status_1, 200)

        text_2, status_2 = self.loop.run_until_complete(
            post_text(url, auth, x_forwarded_for))
        self.assertEqual(status_2, 401)
        self.assertEqual(
            text_2, '{"details": "Incorrect authentication credentials."}')
Пример #3
0
    def test_no_auth_then_401(self):
        self.setup_manual()

        asyncio.ensure_future(run_application(), loop=self.loop)
        is_http_accepted_eventually()

        url = 'http://127.0.0.1:8080/'
        text, status = self.loop.run_until_complete(
            post_text_no_auth(url, '1.2.3.4, 4.4.4.4'))
        self.assertEqual(status, 401)
        self.assertEqual(
            text,
            '{"details": "Authentication credentials were not provided."}')
Пример #4
0
    def test_no_content_type_then_401(self):
        self.setup_manual()

        asyncio.ensure_future(run_application(), loop=self.loop)
        is_http_accepted_eventually()

        url = 'http://127.0.0.1:8080/'
        auth = auth_header(
            'incoming-some-id-1',
            'incoming-some-secret-1',
            url,
            'POST',
            '',
            'some-type',
        )
        x_forwarded_for = '1.2.3.4, 4.4.4.4'
        _, status = self.loop.run_until_complete(
            post_text_no_content_type(url, auth, x_forwarded_for))
        self.assertEqual(status, 401)
Пример #5
0
    def test_post_returns_object(self):
        self.setup_manual()

        asyncio.ensure_future(run_application(), loop=self.loop)
        is_http_accepted_eventually()

        url = 'http://127.0.0.1:8080/'
        auth = auth_header(
            'incoming-some-id-1',
            'incoming-some-secret-1',
            url,
            'POST',
            '',
            '',
        )
        x_forwarded_for = '1.2.3.4, 4.4.4.4'
        text, status = self.loop.run_until_complete(
            post_text(url, auth, x_forwarded_for))
        self.assertEqual(status, 200)
        self.assertEqual(text, '{"secret": "to-be-hidden"}')
Пример #6
0
    def test_no_x_forwarded_for_401(self):
        self.setup_manual()

        asyncio.ensure_future(run_application(), loop=self.loop)
        is_http_accepted_eventually()

        url = 'http://127.0.0.1:8080/'
        auth = auth_header(
            'incoming-some-id-1',
            'incoming-some-secret-1',
            url,
            'POST',
            '',
            '',
        )
        text, status = self.loop.run_until_complete(
            post_text_no_x_forwarded_for(url, auth))
        self.assertEqual(status, 401)
        self.assertEqual(
            text, '{"details": "Incorrect authentication credentials."}')
Пример #7
0
    def test_time_skew_then_401(self):
        self.setup_manual()

        asyncio.ensure_future(run_application(), loop=self.loop)
        is_http_accepted_eventually()

        url = 'http://127.0.0.1:8080/'
        past = datetime.datetime.now() + datetime.timedelta(seconds=-61)
        with freeze_time(past):
            auth = auth_header(
                'incoming-some-id-1',
                'incoming-some-secret-1',
                url,
                'POST',
                '',
                '',
            )
        x_forwarded_for = '1.2.3.4, 4.4.4.4'
        text, status = self.loop.run_until_complete(
            post_text(url, auth, x_forwarded_for))
        self.assertEqual(status, 401)
        self.assertEqual(
            text, '{"details": "Incorrect authentication credentials."}')
Пример #8
0
from app import run_application

app = run_application()
Пример #9
0

def run_game(gui_input=None):
    setup_basic_logging(gui_input)

    logger.info('Выбираем пользователя...')

    site = get_site(gui_input)


    Game(site, UserPrompt(gui_input), gui_input=gui_input).start()


MyLogger = None

__version__ = '0.9.2 ' + BRANCH

if __name__ == '__main__':
    print '\n2013 (c) github.com/Vanuan/zombot\n version %s\n\n' % __version__
    import sys
    if len(sys.argv) != 2 or sys.argv[1] != '-c':
        import gui
        MyLogger = gui.MyLogger
        import app
        app.run_application(run_game)

    else:
        import console
        MyLogger = console.MyLogger
        run_game()
Пример #10
0
    return site, settings


def run_game(gui_input=None):
    setup_basic_logging(gui_input)

    logger.info('Выбираем пользователя...')

    site, settings = get_site(gui_input)

    Game(site, settings, UserPrompt(gui_input), gui_input=gui_input).start()


MyLogger = None

__version__ = '0.9.2 ' + BRANCH

if __name__ == '__main__':
    print '\n2013 (c) github.com/Vanuan/zombot\n version %s\n\n' % __version__
    import sys
    if len(sys.argv) != 2 or sys.argv[1] != '-c':
        import gui
        MyLogger = gui.MyLogger
        import app
        app.run_application(run_game)

    else:
        import console
        MyLogger = console.MyLogger
        run_game()
Пример #11
0
 def handle(self, args):
     global _config
     bootstrapped_app = bootstrap.bootstrap_from_cli(
         _config, self.get_application_manager())
     app.run_application(_config, bootstrapped_app)
Пример #12
0
 def test_application_accepts_http(self):
     self.setup_manual()
     asyncio.ensure_future(run_application(), loop=self.loop)
     self.assertTrue(is_http_accepted_eventually())