示例#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)
示例#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)
示例#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)
示例#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))
示例#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))
示例#6
0
def get_user_headers(user):
    credentials = "%s:secret" % user
    authorization = 'Basic {0}'.format(utils.encode64(credentials))
    return {
        'Authorization': authorization
    }
示例#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)
示例#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)
示例#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)
示例#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)
示例#11
0
 def authenticate_as(self, user_id):
     self.resource.request.headers['Authorization'] = 'Basic %s' % (
         utils.encode64('%s:' % user_id)
     )
示例#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
示例#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)
示例#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)