def test_oid_store(): assoc = mock.Mock() assoc.handle = 'foo' assoc.serialize = lambda: 'bar' assoc.getExpiresIn = lambda: 0 store = M.OpenIdStore() with h.push_config(Association, deserialize=staticmethod(lambda v: assoc)): store.storeAssociation('http://example.com', assoc) assert assoc == store.getAssociation('http://example.com', 'foo') assert assoc == store.getAssociation('http://example.com') store.removeAssociation('http://example.com', 'foo') t0 = time.time() assert store.useNonce('http://www.example.com', t0, 'abcd') ThreadLocalORMSession.flush_all() assert not store.useNonce('http://www.example.com', t0, 'abcd') assert not store.useNonce('http://www.example.com', t0 - 1e9, 'abcd') assert store.getAssociation('http://example.com') is None store.cleanupNonces()
def __init__(self): self.__dict__ = self.__shared_state if self.__shared_state: return self.allura_templates = pkg_resources.resource_filename( 'allura', 'templates') # Setup SOLR self.solr_server = aslist(config.get('solr.server'), ',') # skip empty strings in case of extra commas self.solr_server = [s for s in self.solr_server if s] self.solr_query_server = config.get('solr.query_server') if asbool(config.get('solr.mock')): self.solr = self.solr_short_timeout = MockSOLR() elif self.solr_server: self.solr = make_solr_from_config(self.solr_server, self.solr_query_server) self.solr_short_timeout = make_solr_from_config( self.solr_server, self.solr_query_server, timeout=int(config.get('solr.short_timeout', 10))) else: # pragma no cover self.solr = None self.solr_short_timeout = None self.use_queue = asbool(config.get('use_queue', False)) # Load login/logout urls; only used for SFX logins self.login_url = config.get('auth.login_url', '/auth/') self.logout_url = config.get('auth.logout_url', '/auth/logout') self.login_fragment_url = config.get('auth.login_fragment_url', '/auth/login_fragment') # Setup Gravatar self.gravatar = gravatar.url self.oid_store = M.OpenIdStore() # Setup pygments self.pygments_formatter = utils.LineAnchorCodeHtmlFormatter( cssclass='codehilite', linenos='table') # Setup Pypeline self.pypeline_markup = pypeline_markup # Setup analytics accounts = config.get('ga.account', 'UA-XXXXX-X') accounts = accounts.split(' ') self.analytics = analytics.GoogleAnalytics(accounts=accounts) self.icons = dict( admin=Icon('x', 'ico-admin'), pencil=Icon('p', 'ico-pencil'), help=Icon('h', 'ico-help'), search=Icon('s', 'ico-search'), history=Icon('N', 'ico-history'), feed=Icon('f', 'ico-feed'), mail=Icon('M', 'ico-mail'), reply=Icon('w', 'ico-reply'), tag=Icon('z', 'ico-tag'), flag=Icon('^', 'ico-flag'), undelete=Icon('+', 'ico-undelete'), delete=Icon('#', 'ico-delete'), close=Icon('D', 'ico-close'), table=Icon('n', 'ico-table'), stats=Icon('Y', 'ico-stats'), pin=Icon('@', 'ico-pin'), folder=Icon('o', 'ico-folder'), fork=Icon('R', 'ico-fork'), merge=Icon('J', 'ico-merge'), plus=Icon('+', 'ico-plus'), conversation=Icon('q', 'ico-conversation'), group=Icon('g', 'ico-group'), user=Icon('U', 'ico-user'), secure=Icon('(', 'ico-lock'), unsecure=Icon(')', 'ico-unlock'), star=Icon('S', 'ico-star'), watch=Icon('E', 'ico-watch'), expand=Icon('`', 'ico-expand'), restore=Icon('J', 'ico-restore'), # Permissions perm_read=Icon('E', 'ico-focus'), perm_update=Icon('0', 'ico-sync'), perm_create=Icon('e', 'ico-config'), perm_register=Icon('e', 'ico-config'), perm_delete=Icon('-', 'ico-minuscirc'), perm_tool=Icon('x', 'ico-config'), perm_admin=Icon('(', 'ico-lock'), perm_has_yes=Icon('3', 'ico-check'), perm_has_no=Icon('d', 'ico-noentry'), perm_has_inherit=Icon('2', 'ico-checkcircle'), ) # Cache some loaded entry points def _cache_eps(section_name, dict_cls=dict): d = dict_cls() for ep in h.iter_entry_points(section_name): value = ep.load() d[ep.name] = value return d class entry_point_loading_dict(dict): def __missing__(self, key): self[key] = _cache_eps(key) return self[key] self.entry_points = entry_point_loading_dict( tool=_cache_eps('allura', dict_cls=utils.CaseInsensitiveDict), auth=_cache_eps('allura.auth'), registration=_cache_eps('allura.project_registration'), theme=_cache_eps('allura.theme'), user_prefs=_cache_eps('allura.user_prefs'), spam=_cache_eps('allura.spam'), stats=_cache_eps('allura.stats'), site_stats=_cache_eps('allura.site_stats'), admin=_cache_eps('allura.admin'), ) # Zarkov logger self._zarkov = None # Set listeners to update stats statslisteners = [] for name, ep in self.entry_points['stats'].iteritems(): statslisteners.append(ep()) self.statsUpdater = PostEvent(statslisteners) self.tmpdir = os.getenv('TMPDIR', '/tmp')
def __init__(self): self.__dict__ = self.__shared_state if self.__shared_state: return self.allura_templates = pkg_resources.resource_filename('allura', 'templates') # Setup SOLR self.solr_server = config.get('solr.server') if asbool(config.get('solr.mock')): self.solr = MockSOLR() elif self.solr_server: self.solr = pysolr.Solr(self.solr_server) else: # pragma no cover self.solr = None self.use_queue = asbool(config.get('use_queue', False)) # Load login/logout urls; only used for SFX logins self.login_url = config.get('auth.login_url', '/auth/') self.logout_url = config.get('auth.logout_url', '/auth/logout') # Setup Gravatar self.gravatar = gravatar.url self.oid_store = M.OpenIdStore() # Setup pygments self.pygments_formatter = utils.LineAnchorCodeHtmlFormatter( cssclass='codehilite', linenos='table') # Setup Pypeline self.pypeline_markup = pypeline_markup # Setup analytics self.analytics = analytics.GoogleAnalytics(account=config.get('ga.account', 'UA-XXXXX-X')) self.icons = dict( admin=Icon('x', 'ico-admin'), pencil=Icon('p', 'ico-pencil'), help=Icon('h', 'ico-help'), search=Icon('s', 'ico-search'), history=Icon('N', 'ico-history'), feed=Icon('f', 'ico-feed'), mail=Icon('M', 'ico-mail'), reply=Icon('w', 'ico-reply'), tag=Icon('z', 'ico-tag'), flag=Icon('^', 'ico-flag'), undelete=Icon('+', 'ico-undelete'), delete=Icon('#', 'ico-delete'), close=Icon('D', 'ico-close'), table=Icon('n', 'ico-table'), stats=Icon('Y', 'ico-stats'), pin=Icon('@', 'ico-pin'), folder=Icon('o', 'ico-folder'), fork=Icon('R', 'ico-fork'), merge=Icon('J', 'ico-merge'), plus=Icon('+', 'ico-plus'), conversation=Icon('q', 'ico-conversation'), group=Icon('g', 'ico-group'), user=Icon('U', 'ico-user'), secure=Icon('(', 'ico-lock'), unsecure=Icon(')', 'ico-unlock'), star=Icon('S', 'ico-star'), watch=Icon('E', 'ico-watch'), # Permissions perm_read=Icon('E', 'ico-focus'), perm_update=Icon('0', 'ico-sync'), perm_create=Icon('e', 'ico-config'), perm_register=Icon('e', 'ico-config'), perm_delete=Icon('-', 'ico-minuscirc'), perm_tool=Icon('x', 'ico-config'), perm_admin=Icon('(', 'ico-lock'), perm_has_yes=Icon('3', 'ico-check'), perm_has_no=Icon('d', 'ico-noentry'), perm_has_inherit=Icon('2', 'ico-checkcircle'), ) # Cache some loaded entry points self.entry_points = dict( tool=self._cache_eps('allura', dict_cls=utils.CaseInsensitiveDict), auth=self._cache_eps('allura.auth'), registration=self._cache_eps('allura.project_registration'), theme=self._cache_eps('allura.theme'), user_prefs=self._cache_eps('allura.user_prefs'), ) # Zarkov logger self._zarkov = None