Exemplo n.º 1
0
    def test_update_scopes_forced(self):
        """Verify that scopes are updated without clients"""

        self._create_client('test0', 0, scopes='')
        self._create_token('test0', 0, scopes='adsws:foo one')
        self._create_token('test0', 1, scopes='adsws:foo one two')

        update_scopes(self.app, 'adsws:foo one', 'foo bar', force_token_update=True)

        self.assertTrue(len(OAuthClient.query.filter_by(_default_scopes='bar foo').all()) == 0)
        self.assertTrue(len(OAuthToken.query.filter_by(_scopes='bar foo').all()) == 1)
Exemplo n.º 2
0
    def test_update_scopes(self):
        """Verify that scopes are updated properly"""

        self._create_client('test0', 0, scopes='adsws:foo')
        self._create_client('test1', 1, scopes='adsws:foo one two')
        self._create_client('test2', 2, scopes='adsws:foo two one')
        self._create_client('test3', 3, scopes='adsws:foo')
        self._create_client('test4', 4, scopes='adsws:foo')

        self._create_token('test0', 0, scopes='adsws:foo one')
        self._create_token('test1', 1, scopes='adsws:foo one two')
        self._create_token('test1', 1, scopes='adsws:foo two one')
        self._create_token('test1', 1, scopes='foo bar')

        # normally, scopes will be sorted alphabetically (but we fake it here)
        self.assertIsNotNone(OAuthClient.query.filter_by(_default_scopes= 'adsws:foo one two').one())
        self.assertIsNotNone(OAuthClient.query.filter_by(_default_scopes= 'adsws:foo two one').one())

        update_scopes(self.app, 'adsws:foo one two', 'foo bar')

        # manager will save tokens alphab sorted
        self.assertTrue(len(OAuthClient.query.filter_by(_default_scopes='bar foo').all()) == 2)
        self.assertTrue(len(OAuthClient.query.filter_by(_default_scopes='adsws:foo').all()) == 3)

        self.assertTrue(len(OAuthToken.query.filter_by(_scopes='bar foo').all()) == 2)
        self.assertTrue(len(OAuthToken.query.filter_by(_scopes='adsws:foo one').all()) == 1)
        self.assertTrue(len(OAuthToken.query.filter_by(_scopes='foo bar').all()) == 1)

        update_scopes(self.app, 'foo bar', 'xxx')

        self.assertTrue(len(OAuthClient.query.filter_by(_default_scopes='bar foo').all()) == 0)
        self.assertTrue(len(OAuthClient.query.filter_by(_default_scopes='xxx').all()) == 2)
        self.assertTrue(len(OAuthClient.query.filter_by(_default_scopes='adsws:foo').all()) == 3)

        self.assertTrue(len(OAuthToken.query.filter_by(_scopes='bar foo').all()) == 0)
        self.assertTrue(len(OAuthToken.query.filter_by(_scopes='adsws:foo one').all()) == 1)
        self.assertTrue(len(OAuthToken.query.filter_by(_scopes='foo bar').all()) == 0)
        self.assertTrue(len(OAuthToken.query.filter_by(_scopes='xxx').all()) == 3)