Skip to content

Commit 56627d6

Browse files
committed
Issue #198: only warn about file permissions on windows
`os.chmod` does not change group/other permission on Windows, so not useful to fail on that at the moment.
1 parent 27cc5f9 commit 56627d6

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Changed
1212

13+
- Improve OpenID Connect usability on Windows: don't raise exception on file permissions
14+
that can not be changed (by `os.chmod` on Windows) ([#198](https://github.com/Open-EO/openeo-python-client/issues/198))
15+
1316
### Removed
1417

1518
### Fixed

openeo/rest/auth/config.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
import json
1010
import logging
11+
import platform
1112
import stat
13+
import warnings
1214
from datetime import datetime
1315
from pathlib import Path
1416
from typing import Union, Tuple, Dict
@@ -25,10 +27,13 @@ def assert_private_file(path: Path):
2527
"""Check that given file is only readable by user."""
2628
mode = path.stat().st_mode
2729
if (mode & stat.S_IRWXG) or (mode & stat.S_IRWXO):
28-
raise PermissionError(
29-
"File {p} is readable by others: st_mode {a:o} (expected permissions: {e:o}).".format(
30-
p=path, a=mode, e=_PRIVATE_PERMS)
30+
message = "File {p} could be readable by others: mode {a:o} (expected: {e:o}).".format(
31+
p=path, a=mode & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO), e=_PRIVATE_PERMS
3132
)
33+
if platform.system() == 'Windows':
34+
warnings.warn(message)
35+
else:
36+
raise PermissionError(message)
3237

3338

3439
def utcnow_rfc3339() -> str:

tests/rest/auth/test_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def test_wrong_permissions(self, tmp_path):
3939
with private.path.open("w") as f:
4040
json.dump({"foo": "bar"}, f)
4141
assert private.path.stat().st_mode & 0o077 > 0
42-
with pytest.raises(PermissionError, match="readable by others.*expected permissions: 600"):
42+
with pytest.raises(PermissionError, match="readable by others.*expected: 600"):
4343
private.get("foo")
44-
with pytest.raises(PermissionError, match="readable by others.*expected permissions: 600"):
44+
with pytest.raises(PermissionError, match="readable by others.*expected: 600"):
4545
private.set("foo", value="lol")
4646

4747
def test_set_get(self, tmp_path):
@@ -130,9 +130,9 @@ def test_public_file(self, tmp_path):
130130
with path.open("w") as f:
131131
json.dump({}, f)
132132
r = RefreshTokenStore(path=path)
133-
with pytest.raises(PermissionError, match="readable by others.*expected permissions: 600"):
133+
with pytest.raises(PermissionError, match="readable by others.*expected: 600"):
134134
r.get_refresh_token("foo", "bar")
135-
with pytest.raises(PermissionError, match="readable by others.*expected permissions: 600"):
135+
with pytest.raises(PermissionError, match="readable by others.*expected: 600"):
136136
r.set_refresh_token("foo", "bar", "imd6$3cr3t")
137137

138138
def test_permissions(self, tmp_path):

0 commit comments

Comments
 (0)