Skip to content

Commit

Permalink
Fix all failing unit tests on Windows
Browse files Browse the repository at this point in the history
Fixes #11
Fixes #24
  • Loading branch information
zdc217 authored and ddriddle committed Jan 12, 2021
1 parent 555adb2 commit b517cb3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/awscli_login/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,6 @@ def secure_touch(path):
path - A path to a file.
"""
fd = os.open(path, os.O_CREAT | os.O_RDONLY, mode=0o600)
os.fchmod(fd, 0o600)
if hasattr(os, "fchmod"):
os.fchmod(fd, 0o600)
os.close(fd)
3 changes: 1 addition & 2 deletions src/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from typing import Any, Callable, List, Optional # NOQA
from unittest.mock import patch

from wurlitzer import pipes

from awscli_login.config import CONFIG_FILE

from .util import exec_awscli, fork, isFileChangedBy, isFileTouchedBy, tree
Expand Down Expand Up @@ -632,6 +630,7 @@ def _assertAwsCliReturns(args, calls):
t_code = None

try:
from wurlitzer import pipes
with pipes() as (out, err):
try:
with patch('builtins.input', return_value='') as mock:
Expand Down
6 changes: 4 additions & 2 deletions src/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ def test_secure_touch_function_creates_file(self):
secure_touch(path)

self.assertTrue(isfile(path), 'Failed to create file!')
self.assertHasFilePerms(path, owner='rw')
if os.name == 'posix':
self.assertHasFilePerms(path, owner='rw')

def test_secure_touch_function_changes_perms(self):
"""File with perms 0x644 should be 0x600 after secure_touch. """
Expand All @@ -339,7 +340,8 @@ def test_secure_touch_function_changes_perms(self):
os.close(fd)

secure_touch(path)
self.assertHasFilePerms(path, owner='rw')
if os.name == 'posix':
self.assertHasFilePerms(path, owner='rw')


if __name__ == '__main__':
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
envlist = py35,py36

[testenv]
# getpass.getuser fails on Windows if these envs are not passed in
passenv = LOGNAME USER LNAME USERNAME
changedir = src
commands = python -m unittest discover
deps =
Expand Down

0 comments on commit b517cb3

Please sign in to comment.