def setUp(self): """Prepare for unit test""" self.log = logging.getLogger() self.log.setLevel(logging.DEBUG) # There shouldn't already be a profile, but just in case... profile = Profile.get_by_user_name(self.USER_NAME) if profile: profile.delete() # Create a new profile for tests. self.profile = p = Profile(user_name=self.USER_NAME, user_id='8675309', password=self.PASSWD) self.profile.put() self.auth_header = self.build_auth_header(p.user_name, p.password) self.collection = Collection.get_by_profile_and_name(p, 'testing') self.wbo_values = [ dict(zip(self.value_keys, value_set)) for value_set in self.value_sets ] for w in self.wbo_values: w['payload'] = simplejson.dumps({'stuff': w['payload']}) # Build the app test harness. self.app = webtest.TestApp(sync_api.application())
def setUp(self): """Prepare for unit test""" self.log = logging.getLogger() self.log.setLevel(logging.DEBUG) # There shouldn't already be a profile, but just in case... profile = Profile.get_by_user_name(self.USER_NAME) if profile: profile.delete() # Create a new profile for tests. self.profile = p = Profile( user_name = self.USER_NAME, user_id = '8675309', password = self.PASSWD ) self.profile.put() self.auth_header = self.build_auth_header(p.user_name, p.password) self.collection = Collection.get_by_profile_and_name(p, 'testing') self.wbo_values = [ dict(zip(self.value_keys, value_set)) for value_set in self.value_sets ] for w in self.wbo_values: w['payload'] = simplejson.dumps({ 'stuff': w['payload'] }) # Build the app test harness. self.app = webtest.TestApp(sync_api.application())
def cb(wh, *args, **kwargs): url_user = urllib.unquote(args[0]) auth_header = wh.request.headers.get('Authorization') if auth_header == None: wh.response.set_status(401, message="Authorization Required") wh.response.headers['WWW-Authenticate'] = 'Basic realm="firefox-sync"' return auth_parts = auth_header.split(' ') user_arg, pass_arg = base64.b64decode(auth_parts[1]).split(':') valid_authen = ( (url_user == user_arg) and Profile.authenticate(user_arg, pass_arg) ) if not valid_authen: wh.response.set_status(401, message="Authorization Required") wh.response.headers['WWW-Authenticate'] = 'Basic realm="firefox-sync"' wh.response.out.write("Unauthorized") else: wh.request.profile = Profile.get_by_user_name(user_arg) return func(wh, *args, **kwargs)
def cb(wh, *args, **kwargs): url_user = urllib.unquote(args[0]) auth_header = wh.request.headers.get('Authorization') if auth_header == None: wh.response.set_status(401, message="Authorization Required") wh.response.headers[ 'WWW-Authenticate'] = 'Basic realm="firefox-sync"' return auth_parts = auth_header.split(' ') user_arg, pass_arg = base64.b64decode(auth_parts[1]).split(':') valid_authen = ((url_user == user_arg) and Profile.authenticate(user_arg, pass_arg)) if not valid_authen: wh.response.set_status(401, message="Authorization Required") wh.response.headers[ 'WWW-Authenticate'] = 'Basic realm="firefox-sync"' wh.response.out.write("Unauthorized") else: wh.request.profile = Profile.get_by_user_name(user_arg) return func(wh, *args, **kwargs)