Skip to content

Commit 94c319d

Browse files
authored
SNOW-1226666: allow disabling saml url check in okta authentication (#1961)
1 parent 0b2cfbc commit 94c319d

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1212

1313
- Added support for `token_file_path` connection parameter to read an OAuth token from a file when connecting to Snowflake.
1414
- Added support for `debug_arrow_chunk` connection parameter to allow debugging raw arrow data in case of arrow data parsing failure.
15+
- Added support for `disable_saml_url_check` connection parameter to disable SAML URL check in OKTA authentication.
1516
- Fixed a bug that OCSP certificate signed using SHA384 algorithm cannot be verified.
1617
- Fixed a bug that status code shown as uploaded when PUT command failed with 400 error.
1718

src/snowflake/connector/auth/okta.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ def _step5(
315315
host=conn._rest._host,
316316
port=conn._rest._port,
317317
)
318-
if not _is_prefix_equal(post_back_url, full_url):
318+
if not getattr(conn, "_disable_saml_url_check", False) and not _is_prefix_equal(
319+
post_back_url, full_url
320+
):
319321
Error.errorhandler_wrapper(
320322
conn._rest._connection,
321323
None,

src/snowflake/connector/connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ def _get_private_bytes_from_file(
285285
False,
286286
bool,
287287
), # log raw arrow chunk for debugging purpuse in case there is malformed arrow data
288+
"disable_saml_url_check": (
289+
False,
290+
bool,
291+
), # disable saml url check in okta authentication
288292
}
289293

290294
APPLICATION_RE = re.compile(r"[\w\d_]+")

test/unit/mock_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def mock_connection(
3232
network_timeout=None,
3333
socket_timeout=None,
3434
backoff_policy=DEFAULT_BACKOFF_POLICY,
35+
disable_saml_url_check=False,
3536
):
3637
return MagicMock(
3738
_login_timeout=login_timeout,
@@ -42,6 +43,7 @@ def mock_connection(
4243
socket_timeout=socket_timeout,
4344
_backoff_policy=backoff_policy,
4445
backoff_policy=backoff_policy,
46+
_disable_saml_url_check=disable_saml_url_check,
4547
)
4648

4749

test/unit/test_auth_okta.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ def mock_session_request(*args, **kwargs):
248248
assert not rest._connection.errorhandler.called
249249

250250

251-
def test_auth_okta_step5_negative():
251+
@pytest.mark.parametrize("disable_saml_url_check", [True, False])
252+
def test_auth_okta_step5_negative(disable_saml_url_check):
252253
"""Authentication by OKTA step5 negative test case."""
253254
authenticator = "https://testsso.snowflake.net/"
254255
application = "testapplication"
@@ -259,7 +260,9 @@ def test_auth_okta_step5_negative():
259260

260261
ref_sso_url = "https://testsso.snowflake.net/sso"
261262
ref_token_url = "https://testsso.snowflake.net/token"
262-
rest = _init_rest(ref_sso_url, ref_token_url)
263+
rest = _init_rest(
264+
ref_sso_url, ref_token_url, disable_saml_url_check=disable_saml_url_check
265+
)
263266

264267
auth = AuthByOkta(application)
265268
# step 1
@@ -306,10 +309,12 @@ def get_one_time_token():
306309
rest._host = f"{account}.snowflakecomputing.com"
307310
rest._port = 443
308311
auth._step5(rest._connection, ref_response_html)
309-
assert rest._connection.errorhandler.called # error
312+
assert disable_saml_url_check ^ rest._connection.errorhandler.called # error
310313

311314

312-
def _init_rest(ref_sso_url, ref_token_url, success=True, message=None):
315+
def _init_rest(
316+
ref_sso_url, ref_token_url, success=True, message=None, disable_saml_url_check=False
317+
):
313318
def post_request(url, headers, body, **kwargs):
314319
_ = url
315320
_ = headers
@@ -324,7 +329,7 @@ def post_request(url, headers, body, **kwargs):
324329
},
325330
}
326331

327-
connection = mock_connection()
332+
connection = mock_connection(disable_saml_url_check=disable_saml_url_check)
328333
connection.errorhandler = Mock(return_value=None)
329334
connection._ocsp_mode = Mock(return_value=OCSPMode.FAIL_OPEN)
330335
type(connection).application = PropertyMock(return_value=CLIENT_NAME)

test/unit/test_connection.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from cryptography.hazmat.primitives.asymmetric import rsa
2222

2323
import snowflake.connector
24+
from snowflake.connector.connection import DEFAULT_CONFIGURATION
2425
from snowflake.connector.errors import (
2526
Error,
2627
ForbiddenError,
@@ -513,3 +514,23 @@ def test_expired_detection():
513514
with pytest.raises(ProgrammingError):
514515
cur.execute("select 1;")
515516
assert conn.expired
517+
518+
519+
@pytest.mark.skipolddriver
520+
def test_disable_saml_url_check_config():
521+
with mock.patch(
522+
"snowflake.connector.network.SnowflakeRestful._post_request",
523+
return_value={
524+
"data": {
525+
"serverVersion": "a.b.c",
526+
},
527+
"code": None,
528+
"message": None,
529+
"success": True,
530+
},
531+
):
532+
conn = fake_connector()
533+
assert (
534+
conn._disable_saml_url_check
535+
== DEFAULT_CONFIGURATION.get("disable_saml_url_check")[0]
536+
)

0 commit comments

Comments
 (0)