mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 03:34:50 +00:00
testing travis
This commit is contained in:
35
docker/Dockerfile.testing
Normal file
35
docker/Dockerfile.testing
Normal file
@@ -0,0 +1,35 @@
|
||||
FROM golang:1.10-stretch
|
||||
|
||||
RUN apt-get update && apt-get -y install cron python3 sudo procps
|
||||
|
||||
### Test and build ###
|
||||
# copy source code
|
||||
COPY main.go /go/src/github.com/dominicbreuker/pspy/main.go
|
||||
COPY cmd /go/src/github.com/dominicbreuker/pspy/cmd
|
||||
COPY internal /go/src/github.com/dominicbreuker/pspy/internal
|
||||
COPY vendor /go/src/github.com/dominicbreuker/pspy/vendor
|
||||
|
||||
# run tests
|
||||
WORKDIR /go/src/github.com/dominicbreuker/pspy
|
||||
RUN go test ./...
|
||||
# build executable
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-extldflags "-static"' -o bin/pspy main.go
|
||||
|
||||
### Prepare integration test ###
|
||||
# install root cronjob
|
||||
COPY docker/var/spool/cron/crontabs /var/spool/cron/crontabs
|
||||
RUN chmod 600 /var/spool/cron/crontabs/root
|
||||
COPY docker/root/scripts /root/scripts
|
||||
|
||||
# set up unpriviledged user
|
||||
# allows passwordless sudo to start cron as root on startup
|
||||
RUN useradd -ms /bin/bash myuser && \
|
||||
adduser myuser sudo && \
|
||||
echo 'myuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||
USER myuser
|
||||
|
||||
|
||||
# drop into bash shell
|
||||
COPY docker/entrypoint-testing.sh /entrypoint.sh
|
||||
RUN sudo chmod +x /entrypoint.sh
|
||||
CMD ["/entrypoint.sh"]
|
||||
28
docker/entrypoint-testing.sh
Normal file
28
docker/entrypoint-testing.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
sudo cron -f &
|
||||
sleep 1
|
||||
sudo ps | grep cron 1>/dev/null
|
||||
echo "[+] cron started"
|
||||
|
||||
echo "[+] Running as user `id`"
|
||||
|
||||
echo "[+] Executing test"
|
||||
# exec /bin/bash
|
||||
rm /home/myuser/log.txt
|
||||
bin/pspy > /home/myuser/log.txt &
|
||||
|
||||
for i in `seq 1 25`; do
|
||||
echo "Waiting for cron job detection..."
|
||||
sleep 5;
|
||||
|
||||
QUERY_RESULT=$(grep ' | passwd myuser' /home/myuser/log.txt | grep -v grep)
|
||||
if [ "'$QUERY_RESULT'" != "''" ]; then
|
||||
echo "Cron job execution detected!"
|
||||
echo "Complete log of pspy (may contain commands run in this test):"
|
||||
cat /home/myuser/log.txt
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
echo "Failed to detect cron job..."
|
||||
exit 1
|
||||
Reference in New Issue
Block a user