|
1 | 1 | import fsspec |
| 2 | +import os |
2 | 3 | import uuid |
3 | 4 | import pandas as pd |
4 | 5 | import pytest |
5 | 6 |
|
6 | | -from pins.tests.helpers import DEFAULT_CREATION_DATE |
7 | | -from pins.errors import PinsError |
| 7 | +from pins.tests.helpers import DEFAULT_CREATION_DATE, rm_env |
| 8 | +from pins.errors import PinsError, PinsInsecureReadError |
8 | 9 | from pins.meta import MetaRaw |
9 | 10 |
|
10 | 11 | from datetime import datetime, timedelta |
@@ -111,15 +112,44 @@ def test_board_pin_write_rsc_index_html(board, tmp_dir2, snapshot): |
111 | 112 | "obj, type_", [(df, "csv"), (df, "joblib"), ({"a": 1, "b": [2, 3]}, "joblib")] |
112 | 113 | ) |
113 | 114 | def test_board_pin_write_type(board, obj, type_, request): |
114 | | - meta = board.pin_write(obj, "test_pin", type=type_, title="some title") |
115 | | - dst_obj = board.pin_read("test_pin") |
| 115 | + with rm_env("PINS_ALLOW_INSECURE_READ"): |
| 116 | + os.environ["PINS_ALLOW_INSECURE_READ"] = "1" |
| 117 | + meta = board.pin_write(obj, "test_pin", type=type_, title="some title") |
| 118 | + dst_obj = board.pin_read("test_pin") |
116 | 119 |
|
117 | | - assert meta.type == type_ |
| 120 | + assert meta.type == type_ |
118 | 121 |
|
119 | | - if isinstance(obj, pd.DataFrame): |
120 | | - assert obj.equals(dst_obj) |
| 122 | + if isinstance(obj, pd.DataFrame): |
| 123 | + assert obj.equals(dst_obj) |
121 | 124 |
|
122 | | - obj == dst_obj |
| 125 | + obj == dst_obj |
| 126 | + |
| 127 | + |
| 128 | +def test_board_pin_read_insecure_fail_default(board): |
| 129 | + board.pin_write({"a": 1}, "test_pin", type="joblib", title="some title") |
| 130 | + with pytest.raises(PinsInsecureReadError) as exc_info: |
| 131 | + board.pin_read("test_pin") |
| 132 | + |
| 133 | + assert "joblib" in exc_info.value.args[0] |
| 134 | + |
| 135 | + |
| 136 | +def test_board_pin_read_insecure_fail_board_flag(board): |
| 137 | + # board flag prioritized over env var |
| 138 | + with rm_env("PINS_ALLOW_INSECURE_READ"): |
| 139 | + os.environ["PINS_ALLOW_INSECURE_READ"] = "1" |
| 140 | + board.allow_insecure_read = False |
| 141 | + board.pin_write({"a": 1}, "test_pin", type="joblib", title="some title") |
| 142 | + with pytest.raises(PinsInsecureReadError): |
| 143 | + board.pin_read("test_pin") |
| 144 | + |
| 145 | + |
| 146 | +def test_board_pin_read_insecure_succeed_board_flag(board): |
| 147 | + # board flag prioritized over env var |
| 148 | + with rm_env("PINS_ALLOW_INSECURE_READ"): |
| 149 | + os.environ["PINS_ALLOW_INSECURE_READ"] = "0" |
| 150 | + board.allow_insecure_read = True |
| 151 | + board.pin_write({"a": 1}, "test_pin", type="joblib", title="some title") |
| 152 | + board.pin_read("test_pin") |
123 | 153 |
|
124 | 154 |
|
125 | 155 | # pin_delete ================================================================== |
|
0 commit comments