From nobody Fri Apr 26 02:29:53 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 1519898693225915.4575627073124; Thu, 1 Mar 2018 02:04:53 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 092842B836; Thu, 1 Mar 2018 05:04:52 -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 xXqhuvzETO3P; Thu, 1 Mar 2018 05:04:51 -0500 (EST) Received: from turing.freelists.org (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id B25E9253BE; Thu, 1 Mar 2018 05:04:51 -0500 (EST) Received: with ECARTIS (v1.0.0; list patchew-devel); Thu, 01 Mar 2018 05:04:51 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 755372B836 for ; Thu, 1 Mar 2018 05:04:51 -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 lEIEXT3OFwoV for ; Thu, 1 Mar 2018 05:04:51 -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 0321E253BE for ; Thu, 1 Mar 2018 05:04:50 -0500 (EST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19CA98182D0C for ; Thu, 1 Mar 2018 10:04:50 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-138.pek2.redhat.com [10.72.12.138]) by smtp.corp.redhat.com (Postfix) with ESMTP id A19D510B0F56; Thu, 1 Mar 2018 10:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=freelists.org; s=turing; t=1519898692; bh=d6IrHzCJ5Zq2887iaUtRdiHu7gVt+m84QYONVLk4D/8=; h=From:To:Cc:Subject:Date:Reply-To:List-help:List-unsubscribe: List-Id:List-subscribe:List-owner:List-post:List-archive; b=GRMsneS8+KzhX9nf7/T+kGw8lXpczbdLgFoswUHiDbE/02ko1412zIHbjqPn3WTAI K5I+5WAi+RXMme9BYp9j4szeYXaUrat+kQ/prN6d9uWCjC+5VIEMrtdU5KCGJteKLe /zKaYKiIJP7B4eQ1K4Kd2Va5tnB3ndk0tDVp97IA= 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=1519898691; bh=d6IrHzCJ5Zq2887iaUtRdiHu7gVt+m84QYONVLk4D/8=; h=From:To:Cc:Subject:Date:Reply-To:List-help:List-unsubscribe: List-Id:List-subscribe:List-owner:List-post:List-archive; b=sQlMYPLFLLAPnQTThSf+vur1YiXRuUoF1xl1Rlm/2srPWdQoMxxh5129mGqkvg2M7 qOWqVrtZH9YDY7nUvNH9orwHzf1bfjsOJaYnBfJjWO84x1EawWFFAUFo6+16/Paztu kUvBkYe49r/rjjN72GeY84v0zDNRpL0NKHNa3NJw= X-Original-To: patchew-devel@freelists.org X-Virus-Scanned: Debian amavisd-new at turing.freelists.org From: Fam Zheng To: patchew-devel@freelists.org Cc: pbonzini@redhat.com Subject: [patchew-devel] [PATCH] Set Host header in nginx Date: Thu, 1 Mar 2018 18:04:42 +0800 Message-Id: <20180301100442.30308-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 01 Mar 2018 10:04:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 01 Mar 2018 10:04:50 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-archive-position: 70 X-ecartis-version: Ecartis v1.0.0 Sender: patchew-devel-bounce@freelists.org Errors-to: patchew-devel-bounce@freelists.org X-original-sender: famz@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) (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" From: Paolo Bonzini This fixes absolute URIs in the REST API. Signed-off-by: Paolo Bonzini Signed-off-by: Fam Zheng --- patchew/settings.py | 10 ++++------ scripts/patchew-server.nginx.conf | 2 +- tests/test_rest.py | 10 ++++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/patchew/settings.py b/patchew/settings.py index cca6c79..90a28c3 100644 --- a/patchew/settings.py +++ b/patchew/settings.py @@ -113,12 +113,10 @@ def env_detect(): raise Exception("Unknown running environment") =20 DEBUG, DATA_DIR =3D env_detect() -if DEBUG: - ALLOWED_HOSTS =3D ["*"] -else: - # On deployment environments, we are behind apache/nginx so allow local - # address only - ALLOWED_HOSTS =3D ["127.0.0.1", "localhost"] + +# In production environments, we run in a container, behind nginx, which s= hould +# filter the allowed host names. So be a little flexible here +ALLOWED_HOSTS =3D ["*"] =20 if not os.path.isdir(DATA_DIR): os.makedirs(DATA_DIR) diff --git a/scripts/patchew-server.nginx.conf b/scripts/patchew-server.ngi= nx.conf index d87d8b9..dbac28f 100644 --- a/scripts/patchew-server.nginx.conf +++ b/scripts/patchew-server.nginx.conf @@ -66,7 +66,7 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # enable this if and only if you use HTTPS # proxy_set_header X-Forwarded-Proto https; - proxy_set_header Host localhost; + proxy_set_header Host $host; # we don't want nginx trying to do something clever with # redirects, we set the Host: header above already. proxy_redirect off; diff --git a/tests/test_rest.py b/tests/test_rest.py index 0e43797..1a7285b 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_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