def test_document_without_query_string(self): def check_doc(secret, document): self.assertEquals(secret, 'secret') self.assertEquals(document, 'host.example.com/path/to/file.html\n12345') with mock.patch('fost_authn.signature.sha1_hmac', check_doc): fost_hmac_url_signature('key', 'secret', 'host.example.com', '/path/to/file.html', None, 12345)
def _url_signature(backend, request): if request.GET.has_key("_e"): _e = request.GET["_e"] expires = datetime.utcfromtimestamp(long(_e)) now = datetime.utcnow() logging.info("URL expires at %s and server time is now %s", expires, now) if expires < now: return _forbid("This URL has already expired") else: _e = "" key = request.GET["_k"] secret = settings.FOST_AUTHN_GET_SECRET(request, key) query = filter_query_string(request.META["QUERY_STRING"]) logging.info("Query string %s changed to %s for signing", request.META["QUERY_STRING"], query) signature = fost_hmac_url_signature(key, secret, request.META["HTTP_HOST"], request.path, query, _e) if signature == request.GET["_s"]: return backend.get_user(key) else: return _forbid("Signatures didn't match")
def _url_signature(backend, request): if request.GET.has_key('_e'): _e = request.GET['_e'] expires = datetime.utcfromtimestamp(long(_e)) now = datetime.utcnow() logging.info("URL expires at %s and server time is now %s", expires, now) if expires < now: return _forbid('This URL has already expired') else: _e = '' key = request.GET['_k'] secret = settings.FOST_AUTHN_GET_SECRET(request, key) query = filter_query_string(request.META['QUERY_STRING']) logging.info("Query string %s changed to %s for signing", request.META['QUERY_STRING'], query) signature = fost_hmac_url_signature(key, secret, request.META['HTTP_HOST'], request.path, query, _e) if signature == request.GET['_s']: return backend.get_user(key) else: return _forbid("Signatures didn't match")