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