From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-4.3 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 7FFFA1F8C6 for ; Fri, 13 Aug 2021 06:24:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238831AbhHMGY0 (ORCPT ); Fri, 13 Aug 2021 02:24:26 -0400 Received: from mail-40134.protonmail.ch ([185.70.40.134]:56750 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234011AbhHMGYZ (ORCPT ); Fri, 13 Aug 2021 02:24:25 -0400 Date: Fri, 13 Aug 2021 06:23:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eagain.st; s=protonmail; t=1628835837; bh=2i8rnjkud9KRTipT2pvgN5lT8p91Gw75pk2ulRDLpUg=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=g7LYCH6Q84gAgr6D/bFue2OLEV6UM2TNDQX4+WYEifx6JDWVqiIG3/wgSTXhagqU9 +fsRA2DudT4WXBWx/Yg2ZQB6T9zI1LowS1DMkz9wPKv8Ed+yn1burKLX7KjPUkObR9 /bK/UlTaPepBFdwYq8WQ43ZL5SGcVuyC6BfAtr2GTtvW6mwKi0YaErT84X47TDoOqN zk8IHbGpYwvAEwUBNEsLFDcuC06yRAz1QYUwTHbRZttFcwF/qyjtjcYz9ALF9Vlybx n6foOxFwq3Hka3GCfUS2DZbt2DM8ZDAgzvNNttlPCmtLM2Qg+LrMnQuWKG7alvCYWp WJ/S37g97Y20A== To: git@vger.kernel.org From: Kim Altintop Cc: kim@eagain.st, gitster@pobox.com, jonathantanmy@google.com, bwilliams.eng@gmail.com, johannes.schindelin@gmx.de, jrnieder@gmail.com, sunshine@sunshineco.com Reply-To: Kim Altintop Subject: [PATCH v6 2/3] upload-pack.c: treat want-ref relative to namespace Message-ID: <20210813062237.10403-3-kim@eagain.st> In-Reply-To: <20210809175530.75326-1-kim@eagain.st> References: <20210730135845.633234-1-kim@eagain.st> <20210731203415.618641-1-kim@eagain.st> <20210804203829.661565-1-kim@eagain.st> <20210804205951.668140-1-kim@eagain.st> <20210809175530.75326-1-kim@eagain.st> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When 'upload-pack' runs within the context of a git namespace, treat any 'want-ref' lines the client sends as relative to that namespace. Also check if the wanted ref is hidden via 'hideRefs'. If it is hidden, respond with an error as if the ref didn't exist. Helped-by: Jonathan Tan Signed-off-by: Kim Altintop --- t/t5703-upload-pack-ref-in-want.sh | 135 +++++++++++++++++++++++++++++ upload-pack.c | 18 ++-- 2 files changed, 146 insertions(+), 7 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-i= n-want.sh index 3dad21ff45..220098523a 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -299,6 +299,141 @@ test_expect_success 'fetching with wildcard that matc= hes multiple refs' ' =09grep "want-ref refs/heads/o/bar" log ' +REPO=3D"$(pwd)/repo-ns" + +test_expect_success 'setup namespaced repo' ' +=09( +=09=09git init -b main "$REPO" && +=09=09cd "$REPO" && +=09=09test_commit a && +=09=09test_commit b && +=09=09git checkout a && +=09=09test_commit c && +=09=09git checkout a && +=09=09test_commit d && +=09=09git update-ref refs/heads/ns-no b && +=09=09git update-ref refs/namespaces/ns/refs/heads/ns-yes c && +=09=09git update-ref refs/namespaces/ns/refs/heads/hidden d +=09) && +=09git -C "$REPO" config uploadpack.allowRefInWant true +' + +test_expect_success 'with namespace: want-ref is considered relative to na= mespace' ' +=09wanted_ref=3Drefs/heads/ns-yes && + +=09oid=3D$(git -C "$REPO" rev-parse "refs/namespaces/ns/$wanted_ref") && +=09cat >expected_refs <<-EOF && +=09$oid $wanted_ref +=09EOF +=09cat >expected_commits <<-EOF && +=09$oid +=09$(git -C "$REPO" rev-parse a) +=09EOF + +=09write_fetch_command >pkt <<-EOF && +=09want-ref $wanted_ref +=09EOF +=09test-tool pkt-line pack in && + +=09GIT_NAMESPACE=3Dns test-tool -C "$REPO" serve-v2 --stateless-rpc >out <= in && +=09check_output +' + +test_expect_success 'with namespace: want-ref outside namespace is unknown= ' ' +=09wanted_ref=3Drefs/heads/ns-no && + +=09write_fetch_command >pkt <<-EOF && +=09want-ref $wanted_ref +=09EOF +=09test-tool pkt-line pack in && + +=09test_must_fail env GIT_NAMESPACE=3Dns \ +=09=09test-tool -C "$REPO" serve-v2 --stateless-rpc >out expected_refs <<-EOF && +=09$oid $wanted_ref +=09EOF +=09cat >expected_commits <<-EOF && +=09$oid +=09$(git -C "$REPO" rev-parse a) +=09EOF + +=09write_fetch_command >pkt <<-EOF && +=09want-ref $wanted_ref +=09EOF +=09test-tool pkt-line pack in && + +=09test-tool -C "$REPO" serve-v2 --stateless-rpc >out pkt <<-EOF && +=09want-ref $wanted_ref +=09EOF +=09test-tool pkt-line pack in && + +=09test_must_fail env GIT_NAMESPACE=3Dns \ +=09=09test-tool -C "$REPO" serve-v2 --stateless-rpc >out