Skip to content

Commit

Permalink
Merge branch 'dev' into flask-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlerch authored Jan 31, 2024
2 parents 3b09f39 + a268bfa commit 65669fb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
# - --py39-plus

- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.0
hooks:
- id: black
language_version: python3
Expand Down
1 change: 1 addition & 0 deletions news/1356.bug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only choose an IPA server that is in the config
5 changes: 3 additions & 2 deletions noggin/security/ipa.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ def choose_server(app, session=None):
server = None
if session is not None:
server = session.get('noggin_ipa_server_hostname', None)
if server is None:
server = random.choice(app.config['FREEIPA_SERVERS'])
available_servers = app.config['FREEIPA_SERVERS']
if server is None or server not in available_servers:
server = random.choice(available_servers)
if session is not None:
session['noggin_ipa_server_hostname'] = server
return server
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/security/test_ipa.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def ipa_call_error():


def test_choose_server(client, mocker):
mocker.patch.dict(
current_app.config, {"FREEIPA_SERVERS": ["a.example.test", "b.example.com"]}
)
random = mocker.patch("noggin.security.ipa.random")
random.choice.side_effect = ["a.example.test", "b.example.test", "c.example.test"]
with client.session_transaction() as sess:
Expand All @@ -48,6 +51,16 @@ def test_choose_server_no_session(client, mocker):
assert random.choice.call_count == 2


def test_choose_server_not_in_config(client, mocker):
mocker.patch.dict(current_app.config, {"FREEIPA_SERVERS": ["a.example.test"]})
with client.session_transaction() as sess:
sess['noggin_ipa_server_hostname'] = "b.example.test"
with client.session_transaction() as sess:
server = choose_server(current_app, sess)
# It should be the one from the config
assert server == "a.example.test"


@pytest.mark.vcr
def test_ipa_session_authed(client, logged_in_dummy_user):
"""Check maybe_ipa_session() when a user is logged in"""
Expand Down

0 comments on commit 65669fb

Please sign in to comment.