Skip to content

Commit

Permalink
Created docker-based blackbox test script for context/grant and remot…
Browse files Browse the repository at this point in the history
…e access
  • Loading branch information
BjarniRunar committed Sep 29, 2022
1 parent b88a051 commit 8594f5f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion moggie/app/cli/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ async def get_roles(self, want_context=True):
for t, e in adata.get('tokens', {}).items()])
urls = []
if with_tokens and tokens:
urls.extend((tokens[0][0], '%s/%s/' % (u, tokens[0][1]))
urls.extend((tokens[0][0], '%s/%s' % (u, tokens[0][1]))
for u in cfg['config']['urls'])

if ctxs:
Expand Down
18 changes: 18 additions & 0 deletions tools/Dockerfile_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:devel
MAINTAINER Bjarni R. Einarsson <[email protected]>

RUN apt-get update \
&& apt install -y git curl vim \
python3-cryptography \
python3-urwid \
python3-websockets \
python3-numpy \
python3-appdirs \
python3-setproctitle

RUN curl 'https://lists.apache.org/api/[email protected]&date=2022-01' \
>/root/test.mbx

VOLUME /mnt/code
WORKDIR /root
CMD /mnt/code/tools/docker-internal.sh
69 changes: 69 additions & 0 deletions tools/docker-internal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
#
# This script runs inside a Docker container that has Moggie's reuirements
# installed, the git workspace mounted at /mnt/code, and some test e-mails
# downloaded to /root/test.mbx.
#
# It currently tests the following things:
#
# - Launching moggie as a background process
# - Importing mail
# - Creating a context with an isolating namespace
# - Granting HTTP-based remote access
# - Using lots/curl to fetch and count search results
# - Verify that context namespacing and search scoping correctly
# excludes results that should not be exposed.
#
export PATH=$PATH:/mnt/code/tools

#cd /root
#mkdir -p .local/share/Moggie/default
#cat <<tac >.local/share/Moggie/default/config.rc
#[App]
#port=32025
#tac

cd /mnt/code

python3 -m moggie start
python3 -m moggie import /root/test.mbx

python3 -m moggie context create Testspace --tag-namespace=Testspace
python3 -m moggie grant create Tester user --context=Testspace
python3 -m moggie grant login Tester --output=urls
TESTER_URL=$(python3 -m moggie grant list Tester --output=urls |grep http: |cut -b40-)

while [ $(lots count in:incoming) -gt 0 ]; do
echo "Waiting for importer... $(lots count in:incoming) incoming still"
sleep 1
done
echo
lots search gitbox
echo

TOTAL=$(lots count gitbox)
[ $TOTAL -gt 0 ] && echo -ne 'OK\t' || echo -n 'FAIL\t'
echo "Have $TOTAL hits for gitbox"

PRETAG=$(curl -s "$TESTER_URL/cli/count/gitbox?format=text")
[ $PRETAG = 0 ] && echo -ne 'OK\t' || echo -n 'FAIL\t'
echo "Tester sees $PRETAG hits for gitbox, before tagging."

lots tag +in:@testspace -- gitbox >/dev/null \
&& echo -ne 'OK\t' || echo -n 'FAIL\t'
echo "Tagged gitbox hits into namespace 'testspace'"

POSTTAG=$(curl -s "$TESTER_URL/cli/count/gitbox?format=text")
[ $POSTTAG = $TOTAL ] && echo -ne 'OK\t' || echo -n 'FAIL\t'
echo "Tester sees $POSTTAG hits for gitbox, after tagging."

python3 -m moggie context update Testspace --forbid=superusers --output=scope >/dev/null \
&& echo -ne 'OK\t' || echo -n 'FAIL\t'
echo "Forbidding 'superusers' results in Testspace..."

POSTFB=$(curl -s "$TESTER_URL/cli/count/gitbox?format=text")
[ $POSTFB -lt $POSTTAG ] && echo -ne 'OK\t' || echo -n 'FAIL\t'
echo "Tester sees $POSTFB hits for gitbox, after forbidding."

echo
python3 -m moggie stop
8 changes: 8 additions & 0 deletions tools/docker-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#
# Launch and run `docker-internal.sh` in a pristine test environment.
# See comments in the internal script for details.
#
WORKDIR=$(cd $(dirname $0)/.. && pwd)
docker build -t moggie-test -f $WORKDIR/tools/Dockerfile_tests .
docker run --rm --volume $WORKDIR:/mnt/code moggie-test

0 comments on commit 8594f5f

Please sign in to comment.