Esempio n. 1
0
    def test_userid_is_built_using_password(self):
        auth_password = utils.encode64('user:secret1', encoding='ascii')
        self.request.headers['Authorization'] = 'Basic %s' % auth_password
        user_id1 = self.policy.unauthenticated_userid(self.request)

        auth_password = utils.encode64('user:secret2', encoding='ascii')
        self.request.headers['Authorization'] = 'Basic %s' % auth_password
        user_id2 = self.policy.unauthenticated_userid(self.request)

        self.assertNotEqual(user_id1, user_id2)
Esempio n. 2
0
    def test_userid_is_built_using_password(self):
        auth_password = utils.encode64("user:secret1", encoding="ascii")
        self.request.headers["Authorization"] = "Basic %s" % auth_password
        user_id1 = self.policy.unauthenticated_userid(self.request)

        auth_password = utils.encode64("user:secret2", encoding="ascii")
        self.request.headers["Authorization"] = "Basic %s" % auth_password
        user_id2 = self.policy.unauthenticated_userid(self.request)

        self.assertNotEqual(user_id1, user_id2)
Esempio n. 3
0
    def test_userid_is_built_using_password(self):
        auth_password = utils.encode64('user:secret1', encoding='ascii')
        self.request.headers['Authorization'] = 'Basic %s' % auth_password
        user_id1 = self.policy.unauthenticated_userid(self.request)

        auth_password = utils.encode64('user:secret2', encoding='ascii')
        self.request.headers['Authorization'] = 'Basic %s' % auth_password
        user_id2 = self.policy.unauthenticated_userid(self.request)

        self.assertNotEqual(user_id1, user_id2)
Esempio n. 4
0
    def _build_pagination_token(self, sorting, last_record):
        """Build a pagination token.

        It is a base64 JSON object with the sorting fields values of
        the last_record.

        """
        token = {}

        for field, _ in sorting:
            token[field] = last_record[field]

        return encode64(json.dumps(token))
Esempio n. 5
0
    def _build_pagination_token(self, sorting, last_record, offset):
        """Build a pagination token.

        It is a base64 JSON object with the sorting fields values of
        the last_record.

        """
        token = {'last_record': {}, 'offset': offset}

        for field, _ in sorting:
            token['last_record'][field] = last_record[field]

        return encode64(json.dumps(token))
Esempio n. 6
0
def get_user_headers(user):
    credentials = "%s:secret" % user
    authorization = 'Basic {0}'.format(utils.encode64(credentials))
    return {
        'Authorization': authorization
    }
Esempio n. 7
0
 def test_providing_empty_password_is_supported(self):
     auth_password = utils.encode64("secret:", encoding="ascii")
     self.request.headers["Authorization"] = "Basic %s" % auth_password
     user_id = self.policy.unauthenticated_userid(self.request)
     self.assertIsNotNone(user_id)
Esempio n. 8
0
 def test_returns_none_if_username_is_empty(self):
     auth_password = utils.encode64(":secret", encoding="ascii")
     self.request.headers["Authorization"] = "Basic %s" % auth_password
     user_id = self.policy.unauthenticated_userid(self.request)
     self.assertIsNone(user_id)
Esempio n. 9
0
 def test_providing_empty_password_is_supported(self):
     auth_password = utils.encode64('secret:', encoding='ascii')
     self.request.headers['Authorization'] = 'Basic %s' % auth_password
     user_id = self.policy.unauthenticated_userid(self.request)
     self.assertIsNotNone(user_id)
Esempio n. 10
0
 def test_returns_none_if_username_is_empty(self):
     auth_password = utils.encode64(':secret', encoding='ascii')
     self.request.headers['Authorization'] = 'Basic %s' % auth_password
     user_id = self.policy.unauthenticated_userid(self.request)
     self.assertIsNone(user_id)
Esempio n. 11
0
 def authenticate_as(self, user_id):
     self.resource.request.headers['Authorization'] = 'Basic %s' % (
         utils.encode64('%s:' % user_id)
     )
Esempio n. 12
0
 def test_unicity_is_by_user(self):
     self.create_record()
     self.resource.request.headers['Authorization'] = 'Basic %s' % (
         utils.encode64('alice:')
     )
     self.create_record(user_id='alice')  # not raising
Esempio n. 13
0
 def test_providing_empty_password_is_supported(self):
     auth_password = utils.encode64('secret:', encoding='ascii')
     self.request.headers['Authorization'] = 'Basic %s' % auth_password
     user_id = self.policy.unauthenticated_userid(self.request)
     self.assertIsNotNone(user_id)
Esempio n. 14
0
 def test_returns_none_if_username_is_empty(self):
     auth_password = utils.encode64(':secret', encoding='ascii')
     self.request.headers['Authorization'] = 'Basic %s' % auth_password
     user_id = self.policy.unauthenticated_userid(self.request)
     self.assertIsNone(user_id)