Skip to content

Commit

Permalink
Merge pull request #4288 from rmol/ft-vnc
Browse files Browse the repository at this point in the history
Extract VNC changes from Tor Browser functional test branch
  • Loading branch information
emkll authored Apr 4, 2019
2 parents e11503b + e97f1f1 commit 14ddf41
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 16 deletions.
37 changes: 37 additions & 0 deletions devops/scripts/vnc-docker-connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# shellcheck disable=SC2086
#
#
# Connect to a docker test instance's VNC session

set -e

# Bomb out if container not running
docker inspect securedrop-dev >/dev/null 2>&1 || (echo "ERROR: SD container not running."; exit 1)

# Maybe we are running macOS
if [ "$(uname -s)" == "Darwin" ]; then
open "vnc://${USER}:[email protected]:5901" &
exit 0
fi

# Find our securedrop docker ip
SD_DOCKER_IP="$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' securedrop-dev)"

# Quit if the VNC port not found
nc -w5 -z "$SD_DOCKER_IP" 5901 || (echo "ERROR: VNC server not found"; exit 1)

if [ ! "$(which remote-viewer)" ]
then
printf "\nError: We use the remote-viewer utility to reach Docker via VNC,\n"
printf "and it is not installed. On Debian or Ubuntu, install it with\n"
printf "'sudo apt install virt-viewer', or if you use another VNC client,\n"
printf "consider adding it to this script:\n"
printf "\n%s\n\n" "$(realpath $0)"
printf "and submitting a pull request.\n\n"
exit 1
fi

rv_config="${TMPDIR:-/tmp}/func-vnc.ini"
echo -e "[virt-viewer]\ntype=vnc\nhost=${SD_DOCKER_IP}\nport=5901\npassword=freedom" > "${rv_config}"
remote-viewer "${rv_config}" 2>/dev/null &
4 changes: 4 additions & 0 deletions securedrop/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ translate: ## Update POT translation files from sources
./bin/dev-shell ./i18n_tool.py translate-messages --extract-update
./bin/dev-shell ./i18n_tool.py translate-desktop --extract-update

.PHONY: func-vnc
func-vnc: ## Open up a VNC connection to a running docker instance
../devops/scripts/vnc-docker-connect.sh

# For an explanation of this shell magic, see the Makefile in the root of the repository
.PHONY: help
help: ## Print this message and exit.
Expand Down
16 changes: 14 additions & 2 deletions securedrop/bin/dev-deps
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@
export DISPLAY=:1

function run_xvfb() {
setsid Xvfb :1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset >& /tmp/xvfb.out || cat /tmp/xvfb.out
(setsid Xvfb :1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset >& /tmp/xvfb.out || cat /tmp/xvfb.out) &

# give it time to start
for _ in {1..10}
do
xdpyinfo -display :1 >/dev/null 2>&1 && return 0
sleep 1
done
xdpyinfo -display :1 >/dev/null 2>&1 || (echo "Xvfb is not available"; exit 1)
}

function run_redis() {
setsid redis-server >& /tmp/redis.out || cat /tmp/redis.out
}

function setup_vncauth {
x11vnc -storepasswd freedom /tmp/vncpasswd
}

function run_x11vnc() {
setsid x11vnc -display :1 -autoport 5901 -shared >& /tmp/x11vnc.out || cat /tmp/x11vnc.out
setsid x11vnc -display :1 -geometry 1024x768 -rfbauth /tmp/vncpasswd -rfbport 5901 -shared >& /tmp/x11vnc.out || cat /tmp/x11vnc.out
}

function urandom() {
Expand Down
16 changes: 9 additions & 7 deletions securedrop/bin/dev-shell
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function docker_image() {

docker build \
${DOCKER_BUILD_ARGUMENTS:-} \
--build-arg=USER_ID="$(id -u)" \
--build-arg=USER_NAME="${USER:-root}" \
--build-arg=USER_ID="$(id -u)" \
--build-arg=USER_NAME="${USER:-root}" \
-t "securedrop-test-${1}" \
--file "${TOPLEVEL}/securedrop/dockerfiles/${1}/Dockerfile" \
"${TOPLEVEL}/securedrop"
Expand All @@ -40,12 +40,14 @@ function docker_run() {

find . \( -name '*.pyc' -o -name __pycache__ \) -delete
docker run \
--rm \
-p 127.0.0.1:5901:5901 \
--rm \
-e NUM_SOURCES \
--user "${USER:-root}" \
--volume "${TOPLEVEL}:${TOPLEVEL}" \
--workdir "${TOPLEVEL}/securedrop" \
-ti ${DOCKER_RUN_ARGUMENTS:-} "securedrop-test-${1}" "${@:2}"
--user "${USER:-root}" \
--volume "${TOPLEVEL}:${TOPLEVEL}" \
--workdir "${TOPLEVEL}/securedrop" \
--name securedrop-dev \
-ti ${DOCKER_RUN_ARGUMENTS:-} "securedrop-test-${1}" "${@:2}"
}

if test -n "${CIRCLE_SHA1:-}" ; then
Expand Down
1 change: 0 additions & 1 deletion securedrop/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ source "${BASH_SOURCE%/*}/dev-deps"

run_xvfb &
run_redis &
run_x11vnc &
urandom
run_sass --watch &
maybe_create_config_py
Expand Down
4 changes: 3 additions & 1 deletion securedrop/bin/run-test
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ set -euo pipefail

source "${BASH_SOURCE%/*}/dev-deps"

run_xvfb &
run_xvfb
run_redis &
setup_vncauth
run_x11vnc &
urandom
run_sass --force --update
maybe_create_config_py
Expand Down
4 changes: 2 additions & 2 deletions securedrop/dockerfiles/trusty/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ubuntu:14.04 as of 2019-01-22
FROM ubuntu@sha256:cac55e5d97fad634d954d00a5c2a56d80576a08dcc01036011f26b88263f1578
# ubuntu 14.04 image from 2019-03-12
FROM ubuntu@sha256:6612de24437f6f01d6a2988ed9a36b3603df06e8d2c0493678f3ee696bc4bb2d
ARG USER_NAME
ENV USER_NAME ${USER_NAME:-root}
ARG USER_ID
Expand Down
7 changes: 4 additions & 3 deletions securedrop/dockerfiles/xenial/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ubuntu 16.04 image - 2019-01-22
FROM ubuntu@sha256:e4a134999bea4abb4a27bc437e6118fdddfb172e1b9d683129b74d254af51675
# ubuntu 16.04 image from 2019-03-12
FROM ubuntu@sha256:58d0da8bc2f434983c6ca4713b08be00ff5586eb5cdff47bcde4b2e88fd40f88
ARG USER_NAME
ENV USER_NAME ${USER_NAME:-root}
ARG USER_ID
Expand All @@ -14,7 +14,8 @@ RUN apt-get update && \
RUN apt-get install -y devscripts vim \
python-pip libpython2.7-dev libssl-dev secure-delete \
gnupg2 ruby redis-server firefox git xvfb haveged curl \
gettext paxctl x11vnc enchant libffi-dev sqlite3 gettext sudo
gettext paxctl x11vnc enchant libffi-dev sqlite3 gettext sudo \
libgtk2.0

ENV FIREFOX_CHECKSUM=88d25053306d33658580973b063cd459a56e3596a3a298c1fb8ab1d52171d860
RUN curl -LO https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa/+build/9727836/+files/firefox_46.0.1+build1-0ubuntu0.14.04.3_amd64.deb && \
Expand Down

0 comments on commit 14ddf41

Please sign in to comment.