Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Sep 1, 2018
1 parent 552db9f commit 5bbba2b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
from tljh import user
import os
import os.path
import stat
import uuid
import pwd
import grp
Expand All @@ -23,9 +25,16 @@ def test_ensure_user():
# Create user!
user.ensure_user(username)
# This raises exception if user doesn't exist
ent = pwd.getpwnam(username)
entry = pwd.getpwnam(username)
# Home directory must also exist
assert os.path.exists(ent.pw_dir)
home_dir = entry.pw_dir
assert os.path.exists(home_dir)
# Ensure not word readable/writable especially in teaching context
homedir_stats = os.stat(home_dir).st_mode
assert not (homedir_stats & stat.S_IROTH), "Everyone should not be able to read users home directory"
assert not (homedir_stats & stat.S_IWOTH), "Everyone should not be able to write users home directory"
assert not (homedir_stats & stat.S_IXOTH), "Everyone should not be able to list what is in users home directory"

# Run ensure_user again, should be a noop
user.ensure_user(username)
# User still exists, after our second ensure_user call
Expand Down

0 comments on commit 5bbba2b

Please sign in to comment.