コード例 #1
0
ファイル: authentication.py プロジェクト: timopollmeier/pheme
 def authenticate(self, request: HttpRequest):
     username, role = get_username_role(request)
     if username is None:
         return None
     request.META['GVM_USERNAME'] = username
     request.META['GVM_ROLE'] = username
     return (username, role)
コード例 #2
0
def test_not_call_on_missing_token_gsadsid(request):
    def fake_get(url, params, **kwargs):
        raise Exception("should not be called")

    request.query_params = {}
    request.COOKIES = {}
    username, role = get_username_role(request, get=fake_get)
    assert username is None
    assert role is None
コード例 #3
0
def test_get_username_and_role(request, response):
    # pylint: disable=W0613
    def fake_get(url, params, **kwargs):
        response.text = GSAD_FAKE_RESPONSE
        return response

    request.query_params = dict(token="TOKEN")
    request.COOKIES = dict(GSAD_SID="GSAD_SID")
    username, role = get_username_role(request, get=fake_get)
    assert username == 'admin'
    assert role == 'Admin'
コード例 #4
0
ファイル: renderer.py プロジェクト: timopollmeier/pheme
    def render(self, data, accepted_media_type=None, renderer_context=None):
        request = _get_request(renderer_context)
        if not data:
            return _default_not_found_response(renderer_context, request)

        name = data.get('internal_name')
        cache_key = "{}/{}".format(self.media_type, name) if name else None
        logger.debug("generating report %s", cache_key)

        if cache_key and not DEBUG:
            cached = cache.get(cache_key)
            if cached:
                return cached
        params = load_params()
        # separate user specific parameter
        user_parameter = params.pop('user_specific', {})
        username, _ = get_username_role(request)
        if username:
            params = {**params, **user_parameter.get(username, {})}

        result = self.apply(name, data, params)
        if cache_key:
            cache.set(cache_key, result)
        return result
コード例 #5
0
def test_return_none_on_missing_url(request):
    username, role = get_username_role(request, gsad_url=None)
    assert username is None
    assert role is None