@@ -118,7 +118,16 @@ export PATH="$MOCK_BIN:$PATH"
118118export HOME=" $TMP /home"
119119export DVM_CONFIG=" $TMP /config"
120120export DVM_STATE=" $TMP /state"
121+ export HOST_DOTFILES=" $TMP /host-dotfiles"
121122mkdir -p " $HOME "
123+ mkdir -p " $HOST_DOTFILES /.git" " $HOST_DOTFILES /.ssh" " $HOST_DOTFILES /.gnupg"
124+ printf ' set -o vi\n' > " $HOST_DOTFILES /bashrc"
125+ printf ' #!/usr/bin/env bash\n' > " $HOST_DOTFILES /install.sh"
126+ printf ' git metadata\n' > " $HOST_DOTFILES /.git/config"
127+ printf ' secret key\n' > " $HOST_DOTFILES /.ssh/id_ed25519"
128+ printf ' gpg material\n' > " $HOST_DOTFILES /.gnupg/private-keys-v1.d"
129+ printf ' token=1\n' > " $HOST_DOTFILES /.env"
130+ printf ' do not copy\n' > " $HOST_DOTFILES /secrets"
122131
123132" $ROOT /install.sh" --prefix " $TMP /local-bin" --name dvm-test --init > /dev/null
124133[ -L " $TMP /local-bin/dvm-test" ]
@@ -127,33 +136,66 @@ mkdir -p "$HOME"
127136
128137cat > " $DVM_CONFIG /config.sh" << CONFIG
129138DVM_PREFIX="testvm"
139+ DVM_GUEST_HOME="$VM_HOME_ROOT /testvm-app"
130140DVM_CODE_DIR="$VM_HOME_ROOT /testvm-app/code"
131141DVM_PACKAGES="git openssh-clients gpg helix"
132142DVM_SETUP_SCRIPTS="$DVM_CONFIG /setup.d/fedora.sh"
143+ DVM_DOTFILES_DIR="$HOST_DOTFILES "
144+ DVM_DOTFILES_TARGET="$VM_HOME_ROOT /testvm-app/.dotfiles"
133145DVM_GPG_DIR="$DVM_STATE /gpg"
134146CONFIG
135147
136148cat > " $DVM_CONFIG /setup.d/fedora.sh" << 'SCRIPT '
137149#!/usr/bin/env bash
138150set -euo pipefail
139151printf '%s\n' "$DVM_NAME" >>"$HOME/setup-ran"
152+ [ -f "$DVM_DOTFILES_TARGET/install.sh" ]
140153SCRIPT
141154
142155" $TMP /local-bin/dvm-test" new app > " $TMP /new.out"
143156grep -Fq ' public key for app' " $TMP /new.out"
144157grep -Fq ' create testvm-app' " $LOG "
145158grep -Fq ' helix' " $LOG "
146159grep -Fq ' app' " $VM_HOME_ROOT /testvm-app/setup-ran"
160+ [ -f " $VM_HOME_ROOT /testvm-app/.dotfiles/bashrc" ]
161+ [ -f " $VM_HOME_ROOT /testvm-app/.dotfiles/install.sh" ]
162+ [ ! -e " $VM_HOME_ROOT /testvm-app/.dotfiles/.git" ]
163+ [ ! -e " $VM_HOME_ROOT /testvm-app/.dotfiles/.ssh" ]
164+ [ ! -e " $VM_HOME_ROOT /testvm-app/.dotfiles/.gnupg" ]
165+ [ ! -e " $VM_HOME_ROOT /testvm-app/.dotfiles/.env" ]
166+ [ ! -e " $VM_HOME_ROOT /testvm-app/.dotfiles/secrets" ]
147167
148168" $TMP /local-bin/dvm-test" list > " $TMP /list.out"
149169grep -Fxq app " $TMP /list.out"
170+ rm -f " $HOST_DOTFILES /bashrc"
171+ printf ' export EDITOR=hx\n' > " $HOST_DOTFILES /zshrc"
150172" $TMP /local-bin/dvm-test" setup-all > /dev/null
151173[ " $( grep -Fc ' app' " $VM_HOME_ROOT /testvm-app/setup-ran" ) " -ge 2 ]
174+ [ ! -e " $VM_HOME_ROOT /testvm-app/.dotfiles/bashrc" ]
175+ [ -f " $VM_HOME_ROOT /testvm-app/.dotfiles/zshrc" ]
152176" $TMP /local-bin/dvm-test" key app > " $TMP /key.out"
153177grep -Fq ' ssh-ed25519' " $TMP /key.out"
154178" $TMP /local-bin/dvm-test" doctor > " $TMP /doctor.out"
155179grep -Fq " prefix: testvm" " $TMP /doctor.out"
156180
181+ cp " $DVM_CONFIG /config.sh" " $DVM_CONFIG /config.safe.sh"
182+ cat > " $DVM_CONFIG /config.sh" << CONFIG
183+ DVM_PREFIX="testvm"
184+ DVM_GUEST_HOME="$VM_HOME_ROOT /testvm-app"
185+ DVM_CODE_DIR="$VM_HOME_ROOT /testvm-app/code"
186+ DVM_PACKAGES="git openssh-clients gpg helix"
187+ DVM_SETUP_SCRIPTS="$DVM_CONFIG /setup.d/fedora.sh"
188+ DVM_DOTFILES_DIR="$HOME "
189+ DVM_DOTFILES_TARGET="$VM_HOME_ROOT /testvm-app/.dotfiles"
190+ DVM_GPG_DIR="$DVM_STATE /gpg"
191+ CONFIG
192+ if " $TMP /local-bin/dvm-test" setup app > " $TMP /dangerous.out" 2> " $TMP /dangerous.err" ; then
193+ echo " setup unexpectedly succeeded with dangerous dotfiles dir" >&2
194+ exit 1
195+ fi
196+ grep -Fq ' refusing dangerous DVM_DOTFILES_DIR' " $TMP /dangerous.err"
197+ mv " $DVM_CONFIG /config.safe.sh" " $DVM_CONFIG /config.sh"
198+
157199mkdir -p " $VM_HOME_ROOT /testvm-app/code/repo"
158200git -C " $VM_HOME_ROOT /testvm-app/code/repo" init -q
159201printf ' dirty\n' > " $VM_HOME_ROOT /testvm-app/code/repo/file.txt"
0 commit comments