-
Notifications
You must be signed in to change notification settings - Fork 1k
refactor(IP Address): Update all IP Addresses in tests to use RFC-5735 TEST-NET-* addresses. #15470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dc5b052
c6e49e6
31d1613
98c3aa5
0b461a1
a317951
3025736
8f62827
847bce4
27defd1
58491b1
3419cc9
dd441e3
4732e33
d8cd0d8
e9d0787
e43e589
e38bcee
96e3f09
fb078d9
3d60938
6ffd7c9
2211079
e4ce481
b79c494
b0ecff4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,6 +10,7 @@ | |||||
# See the License for the specific language governing permissions and | ||||||
# limitations under the License. | ||||||
|
||||||
import hashlib | ||||||
import os | ||||||
import os.path | ||||||
import re | ||||||
|
@@ -109,26 +110,21 @@ def metrics(): | |||||
) | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
@pytest.fixture(scope="session") | ||||||
def remote_addr(): | ||||||
return "1.2.3.4" | ||||||
return "192.0.2.1" | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def remote_addr_hashed(): | ||||||
""" | ||||||
Static output of `hashlib.sha256(remote_addr.encode("utf8")).hexdigest()` | ||||||
Created statically to prevent needing to calculate it every run. | ||||||
""" | ||||||
return "6694f83c9f476da31f5df6bcc520034e7e57d421d247b9d34f49edbfc84a764c" | ||||||
@pytest.fixture(scope="function") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't all of these be scoped to
Suggested change
|
||||||
def remote_addr_hashed(remote_addr): | ||||||
if remote_addr is None: | ||||||
return None | ||||||
Comment on lines
+120
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: How could |
||||||
return hashlib.sha256(remote_addr.encode("utf8")).hexdigest() | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def remote_addr_salted(): | ||||||
""" | ||||||
Output of `hashlib.sha256((remote_addr + "pepa").encode("utf8")).hexdigest()` | ||||||
""" | ||||||
return "a69a49383d81404e4b1df297c7baa28e1cd6c4ee1495ed5d0ab165a63a147763" | ||||||
@pytest.fixture(scope="session") | ||||||
def remote_addr_salted(remote_addr): | ||||||
return hashlib.sha256((remote_addr + "pepa").encode("utf8")).hexdigest() | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,12 +99,12 @@ def test_identity_credentials_fail(self, monkeypatch): | |
pretend.stub( | ||
matched_route=None, | ||
banned=pretend.stub(by_ip=lambda ip_address: False), | ||
remote_addr="1.2.3.4", | ||
remote_addr="192.0.2.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should also probably be replaced by |
||
), | ||
pretend.stub( | ||
matched_route=pretend.stub(name="an.invalid.route"), | ||
banned=pretend.stub(by_ip=lambda ip_address: False), | ||
remote_addr="1.2.3.4", | ||
remote_addr="192.0.2.1", | ||
), | ||
], | ||
) | ||
|
@@ -186,7 +186,7 @@ def test_forget_and_remember(self, monkeypatch): | |
pretend.call(request, userid, foo=None) | ||
] | ||
|
||
def test_identity_missing_route(self, monkeypatch): | ||
def test_identity_missing_route(self, monkeypatch, remote_addr): | ||
session_helper_obj = pretend.stub() | ||
session_helper_cls = pretend.call_recorder(lambda: session_helper_obj) | ||
monkeypatch.setattr( | ||
|
@@ -203,7 +203,7 @@ def test_identity_missing_route(self, monkeypatch): | |
add_response_callback=pretend.call_recorder(lambda cb: None), | ||
matched_route=None, | ||
banned=pretend.stub(by_ip=lambda ip_address: False), | ||
remote_addr="1.2.3.4", | ||
remote_addr=remote_addr, | ||
) | ||
|
||
assert policy.identity(request) is None | ||
|
@@ -220,7 +220,7 @@ def test_identity_missing_route(self, monkeypatch): | |
"api.echo", | ||
], | ||
) | ||
def test_identity_invalid_route(self, route_name, monkeypatch): | ||
def test_identity_invalid_route(self, route_name, monkeypatch, remote_addr): | ||
session_helper_obj = pretend.stub() | ||
session_helper_cls = pretend.call_recorder(lambda: session_helper_obj) | ||
monkeypatch.setattr( | ||
|
@@ -237,7 +237,7 @@ def test_identity_invalid_route(self, route_name, monkeypatch): | |
add_response_callback=pretend.call_recorder(lambda cb: None), | ||
matched_route=pretend.stub(name=route_name), | ||
banned=pretend.stub(by_ip=lambda ip_address: False), | ||
remote_addr="1.2.3.4", | ||
remote_addr=remote_addr, | ||
) | ||
|
||
assert policy.identity(request) is None | ||
|
@@ -247,7 +247,7 @@ def test_identity_invalid_route(self, route_name, monkeypatch): | |
assert add_vary_cb.calls == [pretend.call("Cookie")] | ||
assert request.add_response_callback.calls == [pretend.call(vary_cb)] | ||
|
||
def test_identity_no_userid(self, monkeypatch): | ||
def test_identity_no_userid(self, monkeypatch, remote_addr): | ||
session_helper_obj = pretend.stub( | ||
authenticated_userid=pretend.call_recorder(lambda r: None) | ||
) | ||
|
@@ -266,7 +266,7 @@ def test_identity_no_userid(self, monkeypatch): | |
add_response_callback=pretend.call_recorder(lambda cb: None), | ||
matched_route=pretend.stub(name="a.permitted.route"), | ||
banned=pretend.stub(by_ip=lambda ip_address: False), | ||
remote_addr="1.2.3.4", | ||
remote_addr=remote_addr, | ||
) | ||
|
||
assert policy.identity(request) is None | ||
|
@@ -277,7 +277,7 @@ def test_identity_no_userid(self, monkeypatch): | |
assert add_vary_cb.calls == [pretend.call("Cookie")] | ||
assert request.add_response_callback.calls == [pretend.call(vary_cb)] | ||
|
||
def test_identity_no_user(self, monkeypatch): | ||
def test_identity_no_user(self, monkeypatch, remote_addr): | ||
userid = pretend.stub() | ||
session_helper_obj = pretend.stub( | ||
authenticated_userid=pretend.call_recorder(lambda r: userid) | ||
|
@@ -299,7 +299,7 @@ def test_identity_no_user(self, monkeypatch): | |
matched_route=pretend.stub(name="a.permitted.route"), | ||
find_service=pretend.call_recorder(lambda i, **kw: user_service), | ||
banned=pretend.stub(by_ip=lambda ip_address: False), | ||
remote_addr="1.2.3.4", | ||
remote_addr=remote_addr, | ||
) | ||
|
||
assert policy.identity(request) is None | ||
|
@@ -312,7 +312,7 @@ def test_identity_no_user(self, monkeypatch): | |
assert add_vary_cb.calls == [pretend.call("Cookie")] | ||
assert request.add_response_callback.calls == [pretend.call(vary_cb)] | ||
|
||
def test_identity_password_outdated(self, monkeypatch): | ||
def test_identity_password_outdated(self, monkeypatch, remote_addr): | ||
userid = pretend.stub() | ||
session_helper_obj = pretend.stub( | ||
authenticated_userid=pretend.call_recorder(lambda r: userid) | ||
|
@@ -345,7 +345,7 @@ def test_identity_password_outdated(self, monkeypatch): | |
flash=pretend.call_recorder(lambda *a, **kw: None), | ||
), | ||
banned=pretend.stub(by_ip=lambda ip_address: False), | ||
remote_addr="1.2.3.4", | ||
remote_addr=remote_addr, | ||
) | ||
|
||
assert policy.identity(request) is None | ||
|
@@ -364,7 +364,7 @@ def test_identity_password_outdated(self, monkeypatch): | |
assert add_vary_cb.calls == [pretend.call("Cookie")] | ||
assert request.add_response_callback.calls == [pretend.call(vary_cb)] | ||
|
||
def test_identity_is_disabled(self, monkeypatch): | ||
def test_identity_is_disabled(self, monkeypatch, remote_addr): | ||
userid = pretend.stub() | ||
session_helper_obj = pretend.stub( | ||
authenticated_userid=pretend.call_recorder(lambda r: userid) | ||
|
@@ -397,7 +397,7 @@ def test_identity_is_disabled(self, monkeypatch): | |
flash=pretend.call_recorder(lambda *a, **kw: None), | ||
), | ||
banned=pretend.stub(by_ip=lambda ip_address: False), | ||
remote_addr="1.2.3.4", | ||
remote_addr=remote_addr, | ||
) | ||
|
||
assert policy.identity(request) is None | ||
|
@@ -417,7 +417,7 @@ def test_identity_is_disabled(self, monkeypatch): | |
assert add_vary_cb.calls == [pretend.call("Cookie")] | ||
assert request.add_response_callback.calls == [pretend.call(vary_cb)] | ||
|
||
def test_identity(self, monkeypatch): | ||
def test_identity(self, monkeypatch, remote_addr): | ||
userid = pretend.stub() | ||
session_helper_obj = pretend.stub( | ||
authenticated_userid=pretend.call_recorder(lambda r: userid) | ||
|
@@ -448,7 +448,7 @@ def test_identity(self, monkeypatch): | |
password_outdated=pretend.call_recorder(lambda ts: False) | ||
), | ||
banned=pretend.stub(by_ip=lambda ip_address: False), | ||
remote_addr="1.2.3.4", | ||
remote_addr=remote_addr, | ||
) | ||
|
||
assert policy.identity(request) is user | ||
|
@@ -463,7 +463,7 @@ def test_identity(self, monkeypatch): | |
assert add_vary_cb.calls == [pretend.call("Cookie")] | ||
assert request.add_response_callback.calls == [pretend.call(vary_cb)] | ||
|
||
def test_identity_ip_banned(self, monkeypatch): | ||
def test_identity_ip_banned(self, monkeypatch, remote_addr): | ||
userid = pretend.stub() | ||
session_helper_obj = pretend.stub( | ||
authenticated_userid=pretend.call_recorder(lambda r: userid) | ||
|
@@ -493,7 +493,7 @@ def test_identity_ip_banned(self, monkeypatch): | |
password_outdated=pretend.call_recorder(lambda ts: False) | ||
), | ||
banned=pretend.stub(by_ip=lambda ip_address: True), | ||
remote_addr="1.2.3.4", | ||
remote_addr=remote_addr, | ||
) | ||
|
||
assert policy.identity(request) is None | ||
|
Uh oh!
There was an error while loading. Please reload this page.