Skip to content

Commit 9a560b9

Browse files
committed
precondition checks for ssl key and cert
1 parent 512c56e commit 9a560b9

6 files changed

Lines changed: 68 additions & 9 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ stop: ## stop the solid-server docker container
2525
attach: ## execute a shell in the running solid-server docker container
2626
docker exec -it solid-server sh
2727

28-
.PHONY: test build inspect run attach
28+
.PHONY: test build inspect run attach

src/checks.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
echo "checking preconditions..."
4+
35
checks_failed=0
46

57
check_failed()
@@ -14,7 +16,6 @@ check_if_writable()
1416
dir=$1
1517
if [ -d "${dir}" ]; then
1618
if [ -w "${dir}" ]; then
17-
ls -lah ${dir};
1819
echo "${dir} is accessible by $(whoami)"
1920
else
2021
echo "${dir} not writable by $(whoami)"
@@ -23,11 +24,35 @@ check_if_writable()
2324
fi
2425
}
2526

27+
check_if_file_readable()
28+
{
29+
# checks if the given dir is writable, if it exists
30+
# it's ok if the dir does not exist at all, because it will be created
31+
# during solid server startup then and have the correct permissions
32+
file=$1
33+
if [ -e "${file}" ]; then
34+
if [ -r "${file}" ]; then
35+
echo "${file} is accessible by $(whoami)"
36+
else
37+
echo "${file} not readable by $(whoami)"
38+
check_failed
39+
fi
40+
else
41+
echo "${file} does not exist"
42+
check_failed
43+
fi
44+
}
45+
2646
check_if_writable "${SOLID_HOME}/config"
2747
check_if_writable "${SOLID_HOME}/data"
2848
check_if_writable "${SOLID_HOME}/.db"
49+
check_if_file_readable "${SOLID_SSL_KEY}"
50+
check_if_file_readable "${SOLID_SSL_CERT}"
2951

3052
if [ "$checks_failed" -gt 0 ]; then
3153
echo "Finished: ERROR"
3254
exit 1
55+
else
56+
echo "Finished: SUCCESS"
57+
exit 0;
3358
fi

src/create-temporary-cert.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@ openssl req -nodes -x509 -days 3 -newkey rsa:2048 \
1212
-keyout ./$NAME.key \
1313
-out ./$NAME.crt \
1414
-subj "/O=$NAME/OU=$NAME/CN=$NAME"
15-
16-
echo "Finished: SUCCESS"
17-
exit 0;

src/entrypoint.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
set -e
44

5-
./checks.sh
6-
75
./create-temporary-cert.sh ${TEMPORARY_CERT_NAME}
6+
./checks.sh
87

98
solid "$@"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# coding=utf-8
2+
import docker
3+
import pytest
4+
import time
5+
6+
import os
7+
8+
testinfra_hosts = ['docker://test_container']
9+
10+
11+
@pytest.fixture(scope="module", autouse=True)
12+
def container(client, image):
13+
container = client.containers.run(
14+
image.id,
15+
name="test_container",
16+
environment=[
17+
# just using to files that exist but are not readable by node
18+
"SOLID_SSL_KEY=/root",
19+
"SOLID_SSL_CERT=/etc/shadow"
20+
],
21+
detach=True,
22+
tty=True
23+
)
24+
# give the solid process some seconds to create the directory structure before making assertions
25+
time.sleep(2)
26+
yield container
27+
container.remove(force=True)
28+
29+
30+
def test_container_fails_with_errors(container):
31+
assert container.status == "created"
32+
logs = container.logs()
33+
assert "✗ /root not readable by node" in logs
34+
assert "✗ /etc/shadow not readable by node" in logs
35+
assert "Finished: ERROR" in logs
36+
assert not "Finished: SUCCESS" in logs

test/test_precondition_checks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def container(client, image):
1717
'missing_config': {'bind': '/opt/solid/config'}
1818
},
1919
environment=[
20-
"SOLID_SERVER_KEY=/missing/key",
21-
"SOLID_SERVER_CERT=/missing/cert"
20+
"SOLID_SSL_KEY=/missing/key",
21+
"SOLID_SSL_CERT=/missing/cert"
2222
],
2323
detach=True,
2424
tty=True
@@ -35,5 +35,7 @@ def test_container_fails_with_errors(container):
3535
assert "✗ /opt/solid/config not writable by node" in logs
3636
assert "✗ /opt/solid/data not writable by node" in logs
3737
assert "✗ /opt/solid/.db not writable by node" in logs
38+
assert "✗ /missing/key does not exist" in logs
39+
assert "✗ /missing/cert does not exist" in logs
3840
assert "Finished: ERROR" in logs
3941
assert not "Finished: SUCCESS" in logs

0 commit comments

Comments
 (0)