Skip to content

Commit 55f71d5

Browse files
committed
Add a test case for submodules with diff SSH keys
1 parent 29b291e commit 55f71d5

File tree

2 files changed

+93
-7
lines changed

2 files changed

+93
-7
lines changed

_test_tools/sshd/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ COPY sshd.sh /
4747
# manage permissions.
4848
VOLUME /dot_ssh
4949

50+
# Callers should mount a directory with git repos here.
51+
VOLUME /git
52+
5053
# Callers can SSH as user "test"
5154
RUN echo "test:x:65533:65533::/home/test:/usr/bin/git-shell" >> /etc/passwd
5255

test_e2e.sh

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,13 @@ DOT_SSH="$DIR/dot_ssh"
241241
for i in $(seq 1 3); do
242242
mkdir -p "$DOT_SSH/$i"
243243
ssh-keygen -f "$DOT_SSH/$i/id_test" -P "" >/dev/null
244+
cp -a "$DOT_SSH/$i/id_test" "$DOT_SSH/$i/id_local" # for outside-of-container use
244245
mkdir -p "$DOT_SSH/server/$i"
245246
cat "$DOT_SSH/$i/id_test.pub" > "$DOT_SSH/server/$i/authorized_keys"
246247
done
247-
chmod -R g+r "$DOT_SSH"
248+
# Allow files to be read inside containers running as a different UID.
249+
# Note: this does not include the *.local forms.
250+
chmod g+r "$DOT_SSH"/*/id_test* "$DOT_SSH"/server/*
248251

249252
TEST_TOOLS="_test_tools"
250253
SLOW_GIT_FETCH="$TEST_TOOLS/git_slow_fetch.sh"
@@ -2727,23 +2730,20 @@ function e2e::auth_ssh_wrong_key() {
27272730
# Test SSH
27282731
##############################################
27292732
function e2e::auth_ssh() {
2730-
echo "$FUNCNAME" > "$REPO/file"
2731-
27322733
# Run a git-over-SSH server. Use key #3 to exercise the multi-key logic.
27332734
CTR=$(docker_run \
27342735
-v "$DOT_SSH/server/3":/dot_ssh:ro \
2735-
-v "$REPO":/src:ro \
2736+
-v "$REPO":/git/repo:ro \
27362737
e2e/test/sshd)
27372738
IP=$(docker_ip "$CTR")
2738-
git -C "$REPO" commit -qam "$FUNCNAME"
27392739

2740-
# First sync
2740+
# Configure the repo.
27412741
echo "$FUNCNAME 1" > "$REPO/file"
27422742
git -C "$REPO" commit -qam "$FUNCNAME 1"
27432743

27442744
GIT_SYNC \
27452745
--period=100ms \
2746-
--repo="test@$IP:/src" \
2746+
--repo="test@$IP:/git/repo" \
27472747
--root="$ROOT" \
27482748
--link="link" \
27492749
--ssh \
@@ -2752,6 +2752,8 @@ function e2e::auth_ssh() {
27522752
--ssh-key-file="/ssh/secret.3" \
27532753
--ssh-known-hosts=false \
27542754
&
2755+
2756+
# First sync
27552757
wait_for_sync "${MAXWAIT}"
27562758
assert_link_exists "$ROOT/link"
27572759
assert_file_exists "$ROOT/link/file"
@@ -2776,6 +2778,87 @@ function e2e::auth_ssh() {
27762778
assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 3
27772779
}
27782780

2781+
##############################################
2782+
# Test submodules over SSH with different keys
2783+
##############################################
2784+
function e2e::submodule_sync_over_ssh_different_keys() {
2785+
# Init nested submodule repo
2786+
NESTED_SUBMODULE_REPO_NAME="nested-sub"
2787+
NESTED_SUBMODULE="$WORK/$NESTED_SUBMODULE_REPO_NAME"
2788+
mkdir "$NESTED_SUBMODULE"
2789+
2790+
git -C "$NESTED_SUBMODULE" init -q -b "$MAIN_BRANCH"
2791+
config_repo "$NESTED_SUBMODULE"
2792+
echo "nested-submodule" > "$NESTED_SUBMODULE/nested-submodule.file"
2793+
git -C "$NESTED_SUBMODULE" add nested-submodule.file
2794+
git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule.file"
2795+
2796+
# Run a git-over-SSH server. Use key #1.
2797+
CTR_SUBSUB=$(docker_run \
2798+
-v "$DOT_SSH/server/1":/dot_ssh:ro \
2799+
-v "$NESTED_SUBMODULE":/git/repo:ro \
2800+
e2e/test/sshd)
2801+
IP_SUBSUB=$(docker_ip "$CTR_SUBSUB")
2802+
2803+
# Tell local git not to do host checking and to use the test keys.
2804+
export GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i $DOT_SSH/1/id_local -i $DOT_SSH/2/id_local"
2805+
2806+
# Init submodule repo
2807+
SUBMODULE_REPO_NAME="sub"
2808+
SUBMODULE="$WORK/$SUBMODULE_REPO_NAME"
2809+
mkdir "$SUBMODULE"
2810+
2811+
git -C "$SUBMODULE" init -q -b "$MAIN_BRANCH"
2812+
config_repo "$SUBMODULE"
2813+
echo "submodule" > "$SUBMODULE/submodule.file"
2814+
git -C "$SUBMODULE" add submodule.file
2815+
git -C "$SUBMODULE" commit -aqm "init submodule.file"
2816+
2817+
# Add nested submodule to submodule repo
2818+
git -C "$SUBMODULE" submodule add -q "test@$IP_SUBSUB:/git/repo" "$NESTED_SUBMODULE_REPO_NAME"
2819+
git -C "$SUBMODULE" commit -aqm "add nested submodule"
2820+
2821+
# Run a git-over-SSH server. Use key #2.
2822+
CTR_SUB=$(docker_run \
2823+
-v "$DOT_SSH/server/2":/dot_ssh:ro \
2824+
-v "$SUBMODULE":/git/repo:ro \
2825+
e2e/test/sshd)
2826+
IP_SUB=$(docker_ip "$CTR_SUB")
2827+
2828+
# Add the submodule to the main repo
2829+
git -C "$REPO" submodule add -q "test@$IP_SUB:/git/repo" "$SUBMODULE_REPO_NAME"
2830+
git -C "$REPO" commit -aqm "add submodule"
2831+
git -C "$REPO" submodule update --recursive --remote > /dev/null 2>&1
2832+
2833+
# Run a git-over-SSH server. Use key #3.
2834+
CTR=$(docker_run \
2835+
-v "$DOT_SSH/server/3":/dot_ssh:ro \
2836+
-v "$REPO":/git/repo:ro \
2837+
e2e/test/sshd)
2838+
IP=$(docker_ip "$CTR")
2839+
2840+
GIT_SYNC \
2841+
--period=100ms \
2842+
--repo="test@$IP:/git/repo" \
2843+
--root="$ROOT" \
2844+
--link="link" \
2845+
--ssh \
2846+
--ssh-key-file="/ssh/secret.1" \
2847+
--ssh-key-file="/ssh/secret.2" \
2848+
--ssh-key-file="/ssh/secret.3" \
2849+
--ssh-known-hosts=false \
2850+
&
2851+
wait_for_sync "${MAXWAIT}"
2852+
assert_link_exists "$ROOT/link"
2853+
assert_file_exists "$ROOT/link/file"
2854+
assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file"
2855+
assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule.file"
2856+
assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 1
2857+
2858+
rm -rf $SUBMODULE
2859+
rm -rf $NESTED_SUBMODULE
2860+
}
2861+
27792862
##############################################
27802863
# Test sparse-checkout files
27812864
##############################################

0 commit comments

Comments
 (0)