From nobody Sat Apr 20 09:11:09 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 206.53.239.180 is neither permitted nor denied by domain of freelists.org) client-ip=206.53.239.180; envelope-from=patchew-devel-bounce@freelists.org; helo=turing.freelists.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=none (zoho.com: 206.53.239.180 is neither permitted nor denied by domain of freelists.org) smtp.mailfrom=patchew-devel-bounce@freelists.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from turing.freelists.org (turing.freelists.org [206.53.239.180]) by mx.zohomail.com with SMTPS id 151982170430319.810218651004902; Wed, 28 Feb 2018 04:41:44 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id E748E2B501; Wed, 28 Feb 2018 07:41:42 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id giTR6_NOSVYi; Wed, 28 Feb 2018 07:41:42 -0500 (EST) Received: from turing.freelists.org (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 9BF182B4F9; Wed, 28 Feb 2018 07:41:42 -0500 (EST) Received: with ECARTIS (v1.0.0; list patchew-devel); Wed, 28 Feb 2018 07:41:42 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 4E7A32B501 for ; Wed, 28 Feb 2018 07:41:42 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hEKTRpWhdsju for ; Wed, 28 Feb 2018 07:41:42 -0500 (EST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id C58E82B4F9 for ; Wed, 28 Feb 2018 07:41:41 -0500 (EST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03E3A8182D01 for ; Wed, 28 Feb 2018 12:41:41 +0000 (UTC) Received: from donizetti.redhat.com (unknown [10.36.118.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 324959C042; Wed, 28 Feb 2018 12:41:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freelists.org; s=turing; t=1519821702; bh=UEbsJT0aATPteFL748fbMK3d2gH9iTcAFMxTRnCxuBc=; h=From:To:Cc:Subject:Date:Reply-To:List-help:List-unsubscribe: List-Id:List-subscribe:List-owner:List-post:List-archive; b=CTh7FSGzTZ8do9/VfdYqEpXPDjt1Wqn3tbQVtHaWtxpRUqJbDKOFojR+gAgiGwQgd OsCXq7bWtk+enTdYJ+XaKftU3Va7n2Mgr0bA/SQSi5XI/xj94RWKPyeHHmatOzglec p592GYNmOxIDsl2TbR4gxsS34Myc33lM7Zz/zLhM= X-Virus-Scanned: Debian amavisd-new at turing.freelists.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freelists.org; s=turing; t=1519821702; bh=UEbsJT0aATPteFL748fbMK3d2gH9iTcAFMxTRnCxuBc=; h=From:To:Cc:Subject:Date:Reply-To:List-help:List-unsubscribe: List-Id:List-subscribe:List-owner:List-post:List-archive; b=CTh7FSGzTZ8do9/VfdYqEpXPDjt1Wqn3tbQVtHaWtxpRUqJbDKOFojR+gAgiGwQgd OsCXq7bWtk+enTdYJ+XaKftU3Va7n2Mgr0bA/SQSi5XI/xj94RWKPyeHHmatOzglec p592GYNmOxIDsl2TbR4gxsS34Myc33lM7Zz/zLhM= X-Original-To: patchew-devel@freelists.org X-Virus-Scanned: Debian amavisd-new at turing.freelists.org From: Paolo Bonzini To: patchew-devel@freelists.org Cc: famz@redhat.com Subject: [patchew-devel] [PATCH] use X-Forwarded-Host header in HttpRequest.get_host()/get_port() Date: Wed, 28 Feb 2018 13:41:35 +0100 Message-Id: <20180228124135.586-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 28 Feb 2018 12:41:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 28 Feb 2018 12:41:41 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-archive-position: 56 X-ecartis-version: Ecartis v1.0.0 Sender: patchew-devel-bounce@freelists.org Errors-to: patchew-devel-bounce@freelists.org X-original-sender: pbonzini@redhat.com Precedence: normal Reply-To: patchew-devel@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: patchew-devel X-List-ID: patchew-devel List-subscribe: List-owner: List-post: List-archive: X-list: patchew-devel X-ZohoMail-DKIM: pass (identity @freelists.org) X-ZohoMail: RDKM_0 RSF_4 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes absolute URIs in the REST API. Signed-off-by: Paolo Bonzini --- Fam, can you please apply this patch and re-deploy next.patchew.org? patchew/settings.py | 2 ++ scripts/patchew-server.nginx.conf | 1 + tests/test_rest.py | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/patchew/settings.py b/patchew/settings.py index cca6c79..b5b8019 100644 --- a/patchew/settings.py +++ b/patchew/settings.py @@ -113,6 +113,8 @@ def env_detect(): raise Exception("Unknown running environment") =20 DEBUG, DATA_DIR =3D env_detect() + +USE_X_FORWARDED_HOST =3D True if DEBUG: ALLOWED_HOSTS =3D ["*"] else: diff --git a/scripts/patchew-server.nginx.conf b/scripts/patchew-server.ngi= nx.conf index d87d8b9..890a747 100644 --- a/scripts/patchew-server.nginx.conf +++ b/scripts/patchew-server.nginx.conf @@ -64,6 +64,7 @@ http { =20 location @proxy_to_app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $host; # enable this if and only if you use HTTPS # proxy_set_header X-Forwarded-Proto https; proxy_set_header Host localhost; diff --git a/tests/test_rest.py b/tests/test_rest.py index 0e43797..018a97f 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -36,6 +36,16 @@ class RestTest(PatchewTestCase): self.admin =3D User.objects.get(username=3D'admin') self.USER_BASE =3D '%susers/%d/' % (self.REST_BASE, self.admin.id) =20 + def test_root(self): + resp =3D self.api_client.get(self.REST_BASE) + self.assertEquals(resp.data['users'], self.REST_BASE + 'users/') + self.assertEquals(resp.data['projects'], self.REST_BASE + 'project= s/') + self.assertEquals(resp.data['series'], self.REST_BASE + 'series/') + resp =3D self.api_client.get(self.REST_BASE, HTTP_X_FORWARDED_HOST= =3D'patchew.org') + self.assertEquals(resp.data['users'], 'http://patchew.org/api/v1/u= sers/') + self.assertEquals(resp.data['projects'], 'http://patchew.org/api/v= 1/projects/') + self.assertEquals(resp.data['series'], 'http://patchew.org/api/v1/= series/') + def test_users(self): resp =3D self.api_client.get(self.REST_BASE + 'users/') self.assertEquals(resp.data['count'], 1) --=20 2.14.3