Unverified Commit edc69d73 authored by Lukas Matt's avatar Lukas Matt Committed by GitHub

Merge pull request #10 from thefederationinfo/add_socialhome

Add socialhome image to repository
parents 7c027be3 2d279baf
......@@ -12,5 +12,6 @@ matrix:
- env: PROJECT=diaspora
- env: PROJECT=ganggo
- env: PROJECT=mastodon
- env: PROJECT=socialhome
install: bash scripts/install.sh
script: bats --tap $(find . -name $PROJECT'*.bats')
......@@ -10,6 +10,7 @@ This repository is about automating federation tests in the network itself!
Following projects are using the testsuite:
* [GangGo](https://github.com/ganggo)
* [Socialhome](https://github.com/jaywink/socialhome)
## Add your project
......
# vim:ft=sh
#
# All API calls are documented here: https://ganggo.github.io/api/
#
load test_helper
load ganggo_helper
load socialhome_helper
endpoint="localhost:9001"
web_endpoint="http://$endpoint"
g1_endpoint="http://localhost:9000"
@test "$btf create databases" {
psql -U postgres -c "create database g1;"
[ "$?" -eq 0 ]
psql -U postgres -c "create database s1;"
[ "$?" -eq 0 ]
}
@test "$btf start ganggo#1 server" {
ganggo_start_server g1 "9000"
}
@test "$btf start socialhome#1 server" {
socialhome_start_server s1 "9001"
}
@test "$btf create ganggo#1 user" {
ganggo_create_user g1 $g1_endpoint
}
@test "$btf create socialhome#1 user" {
socialhome_create_user s1
}
# since socialhome only delivers to subscriped servers
# the ganggo user has to follow the socialhome user
@test "$btf fetch ganggo#1 token" {
ganggo_fetch_token g1 $g1_endpoint
}
@test "$btf setup user relations" {
ganggo_start_sharing "s1@localhost:9001" $g1_endpoint
}
# otherwise the socialhome token request will fail
@test "$btf clean-up ganggo#1 files" {
rm -v $curl_params
[ "$?" -eq 0 ]
}
# according to http://socialhome.readthedocs.io/en/latest/api.html#authenticating
@test "$btf fetch socialhome#1 token" {
socialhome_fetch_token s1 $web_endpoint
}
@test "$btf start sharing" {
socialhome_start_sharing "g1@localhost:9000" $web_endpoint
}
@test "$btf create public entities and check federation" {
post "text=foobar&visibility=public" "$web_endpoint/api/content/"
[ "$?" -eq 0 ]
guid=$(json_value "guid")
echo "guid = $guid"
[ "$guid" != "" ]
# check post in ganggo
function cmd() {
query "g1" "select count(*) from posts
where guid = '$guid' and public = true;"
}
code=$(wait_for cmd "1" 120)
echo "expected 0, got $code"
[ "$code" -eq "0" ]
}
@test "$btf clean-up files, containers and database" {
stop_app "g1 s1"
[ "$?" -eq 0 ]
remove_app "g1 s1"
[ "$?" -eq 0 ]
rm -v $curl_params
[ "$?" -eq 0 ]
psql -U postgres -c "drop database g1;"
[ "$?" -eq 0 ]
psql -U postgres -c "drop database s1;"
[ "$?" -eq 0 ]
}
DATABASE_URL=postgres://postgres@127.0.0.1:5432/NAME
DJANGO_SECRET_KEY=m0jv6^ls^thsm!n%5$uk-347da$3c$14j5aue)g3e)hn8&d6ll
DJANGO_ALLOWED_HOSTS=localhost
DJANGO_SECURE_SSL_REDIRECT=False
DJANGO_ACCOUNT_ALLOW_REGISTRATION=True
SOCIALHOME_DOMAIN=localhost:PORT
SOCIALHOME_HTTPS=False
SOCIALHOME_LOGFILE=/socialhome/socialhome.log
# enable federation
DJANGO_DEBUG=False
FROM python:3
RUN apt-get update
RUN apt-get install -y git-core
RUN git clone https://github.com/jaywink/socialhome.git
WORKDIR /socialhome
RUN bash install_ubuntu_dependencies.sh install
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs
RUN pip install -U pip setuptools==30.4 pip-tools
RUN pip-sync dev-requirements.txt
RUN npm install
RUN npm install -g bower
RUN bower install --allow-root
RUN npm -g install grunt
RUN npm run build
# NOTE workaround for validating localhost domain name
RUN sed -i 's/\\\.//' src/federation/federation/utils/text.py
# NOTE enable key generation in development mode
RUN sed -i 's/SOCIALHOME_GENERATE_USER_RSA_KEYS_ON_SAVE = False/SOCIALHOME_GENERATE_USER_RSA_KEYS_ON_SAVE = True/' config/settings/local.py
# XXX hotfix http fallback support in development mode
# see https://github.com/jaywink/federation/issues/120
RUN sed -i 's/raise_ssl_errors=True/raise_ssl_errors=False/' \
src/federation/federation/utils/network.py
RUN sed -i 's/return "https/return "http/g' \
src/federation/federation/utils/diaspora.py
COPY .env /socialhome/.env
COPY start.sh /start.sh
CMD [ "/bin/bash", "/start.sh" ]
#!/bin/bash
if [ "$PROJECT" == "socialhome" ]; then
# fetch user repo
cd /socialhome && git stash \
&& git remote add custom $PRREPO \
&& git fetch custom \
&& git checkout $PRSHA \
&& git stash pop \
&& git log -1 || {
echo "Cannot find $PRREPO $PRSHA"
exit 1
}
# re-install dependencies
cd /socialhome \
&& pip-sync dev-requirements.txt \
&& npm install \
&& manage.py migrate \
&& npm run dev
fi
sed -i "s/NAME/$DATABASE/g" /socialhome/.env
sed -i "s/PORT/$PORT/g" /socialhome/.env
python manage.py migrate
python manage.py collectstatic
#python manage.py rebuild_index
python manage.py runserver localhost:$PORT &
tail -f /socialhome/socialhome.log
# socialhome_start_server "s1" "9001"
function socialhome_start_server() {
start_app "$1" "$2" "testing_socialhome"$(latest_tag "socialhome")
[ "$?" -eq 0 ]
code=$(wait_for "docker logs $1" "Listening on endpoint tcp")
echo "expected 0, got $code"
[ "$code" -eq "0" ]
}
# socialhome_create_user "s1"
function socialhome_create_user() {
# create superuser via python console
echo "from django.contrib.auth import get_user_model;
User = get_user_model();
User.objects.create_superuser(
'$1', 's1@example.com', 'pppppp'
);" |docker exec $1 python manage.py shell -c "$(cat -)"
}
# socialhome_fetch_token "s1" "http://localhost:9001"
function socialhome_fetch_token() {
post_form "username=$1&password=pppppp" "$2/api-token-auth/"
[ "$?" -eq 0 ]
#echo "expected 200, got $HTTP_STATUS_CODE"
#[ "$HTTP_STATUS_CODE" == "200" ]
token=$(json_value "token")
echo "body = $HTTP_BODY"
echo "token = $token"
[ "$token" != "null" ]
echo "-H 'Authorization: Token $token'" > $curl_params
}
# socialhome_start_sharing "g1@localhost:9000" "http://localhost:9001"
function socialhome_start_sharing() {
# search remote profile first
get "$2/search/?q=$1"
[ "$?" -eq 0 ]
[ "$HTTP_STATUS_CODE" == "302" ]
sleep 5
# start following
user=$(echo $1 |cut -d'@' -f1)
guid=$(query "$user" "select guid from people where author = '$1';")
[ "$?" -eq 0 ]
echo "guid = $guid"
[ "$guid" != "" ]
post "guid=$guid" "$2/api/profiles/1/add_follower/"
[ "$?" -eq 0 ]
sleep 5
}
......@@ -21,18 +21,26 @@ function setup() {
[ "$?" -eq 0 ]
}
# fetch "POST" "data1=one&data2=two" "http://server/endpoint"
# fetch "POST" "data1=one&data2=two" "url" "http://server/endpoint"
function fetch() {
tmp=$(mktemp)
unset params
unset field_params
[ -f "$curl_params" ] && params=$(cat $curl_params)
[ "$2" != "" ] && params="$params -d '$2'"
params="$params -k -D $tmp -s -X $1"
if [[ "$3" == "url" ]]; then field_params="-d '$2'"
else
IFS='&' read -ra reqparams <<< "$2"
for reqparam in ${reqparams[@]}; do
field_params="$field_params -F '$reqparam'"
done
fi
params="$params $field_params -k -D $tmp -s -X $1"
export HTTP_BODY=$(eval "curl $params $3")
echo "curl $params $4"
export HTTP_BODY=$(eval "curl $params $4")
export HTTP_STATUS_CODE=$(head -n1 $tmp |cut -d' ' -f2)
echo "curl = '$params $3'"
echo "HTTP_STATUS_CODE = $HTTP_STATUS_CODE"
echo "HTTP_BODY = $HTTP_BODY"
......@@ -40,14 +48,19 @@ function fetch() {
[ "$?" -eq 0 ]
}
# post_form "data1=one&data2=two" "http://server/endpoint"
function post_form() {
fetch "POST" "$1" "form" "$2"
}
# post "data1=one&data2=two" "http://server/endpoint"
function post() {
fetch "POST" "$1" "$2"
fetch "POST" "$1" "url" "$2"
}
# get "http://server/endpoint?data1=one&data2=two"
function get() {
fetch "GET" "" "$1"
fetch "GET" "" "url" "$1"
}
# start_app "g1" "3000" "testing_diaspora:v1.0.1"
......@@ -99,7 +112,7 @@ function wait_for() {
TIMEOUT_PID=$!
while true; do
$1 |grep -m 1 "$2" >/dev/null 2>&1
$1 2>&1 |grep -m 1 "$2" >/dev/null
if [ "$?" -eq 0 ]; then break; fi
sleep 1
done & >/dev/null 2>&1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment