mirror of
https://github.com/atmoz/sftp.git
synced 2025-02-02 13:55:02 -05:00
UPD: user list re-evaluation refactored and tests implemented
This commit is contained in:
parent
ae20b744b8
commit
d825152c64
5 changed files with 41 additions and 19 deletions
|
@ -1,9 +0,0 @@
|
|||
version: '2'
|
||||
|
||||
services:
|
||||
|
||||
sftp:
|
||||
build: .
|
||||
volumes:
|
||||
- ./tests/testusers.conf:/etc/sftp/users.conf
|
||||
|
|
@ -34,14 +34,16 @@ fi
|
|||
# Check for differences between defined and provisioned users
|
||||
if [ -f "$userProvisionedFinalPath" ]; then
|
||||
set +e
|
||||
diff "$userProvisionedFinalPath" "$userConfPath" \
|
||||
| tail -n+3 \
|
||||
| grep -E '^\+.*$' \
|
||||
| cut -c2- \
|
||||
| grep -v -E '^\s*#' > "$userProvisionedTmpPath"
|
||||
_raw_diff="$(diff "$userProvisionedFinalPath" "$userConfPath" || true)"
|
||||
set -e
|
||||
SFTP_USERS="$(cat $userProvisionedTmpPath)"
|
||||
rm -f "$userProvisionedTmpPath"
|
||||
if [ -n "$_raw_diff" ]; then
|
||||
_diff_lines="$(echo "$_raw_diff" | tail -n+2)"
|
||||
_diff_new_entries="$(echo "$_diff_lines" | grep -E '^[+>].*$' | grep -o '^\s*[^#]*')"
|
||||
_new_entries="$(echo "$_diff_new_entries" | cut -c2- | sed -e 's/^[ \t]*//')"
|
||||
echo "$_new_entries" > "$userProvisionedTmpPath"
|
||||
SFTP_USERS="$SFTP_USERS $(cat $userProvisionedTmpPath)"
|
||||
rm -f "$userProvisionedTmpPath"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create users on first run and if new entries are present
|
||||
|
@ -74,6 +76,7 @@ if [ ! -f "$userConfFinalPath" ] || [ -n "$SFTP_USERS" ]; then
|
|||
while IFS= read -r user || [[ -n "$user" ]]; do
|
||||
create-sftp-user "$user"
|
||||
done < "$userConfFinalPath"
|
||||
cp "$userConfFinalPath" "$userProvisionedFinalPath"
|
||||
elif $startSshd; then
|
||||
log "FATAL: No users provided!"
|
||||
exit 3
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
foo:pass:::upload,download
|
||||
bar:pass:::upload,media
|
|
@ -1 +0,0 @@
|
|||
foo1:pass:::upload
|
31
tests/run
31
tests/run
|
@ -200,6 +200,37 @@ function testUsersConf() {
|
|||
assertTrue "dirs exists" $?
|
||||
}
|
||||
|
||||
function testAddUsersConf() {
|
||||
echo "user-from-conf:" > "$testDir/files/changing-users.conf"
|
||||
|
||||
docker run --name "$containerName" -d \
|
||||
-v "$testDir/files/changing-users.conf:/etc/sftp/users.conf:ro" \
|
||||
"$imageName" \
|
||||
> "$redirect" 2>&1
|
||||
|
||||
waitForServer "$containerName"
|
||||
assertTrue "waitForServer" $?
|
||||
|
||||
docker exec "$containerName" id user-from-conf > /dev/null
|
||||
assertTrue "user-from-conf" $?
|
||||
|
||||
echo "add-user-from-conf:" >> "$testDir/files/changing-users.conf"
|
||||
echo "add-user2-from-conf:" >> "$testDir/files/changing-users.conf"
|
||||
|
||||
docker restart "$containerName" > "$redirect" 2>&1
|
||||
|
||||
waitForServer "$containerName"
|
||||
assertTrue "waitForServer" $?
|
||||
|
||||
docker exec "$containerName" id add-user-from-conf > /dev/null
|
||||
assertTrue "add-user-from-conf" $?
|
||||
|
||||
docker exec "$containerName" id add-user2-from-conf > /dev/null
|
||||
assertTrue "add-user2-from-conf" $?
|
||||
|
||||
rm -f "$testDir/files/changing-users.conf"
|
||||
}
|
||||
|
||||
function testLegacyUsersConf() {
|
||||
docker run --name "$containerName" -d \
|
||||
-v "$testDir/files/users.conf:/etc/sftp-users.conf:ro" \
|
||||
|
|
Loading…
Add table
Reference in a new issue