Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cpp/lib/Authenticator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ extern "C" {
try
{
static_cast<Snowflake::Client::IAuthenticator*>(conn->auth_object)->authenticate();

// Based on the Okta and external browser implementation, we avoid using try-catch in order to follow the Google C++ Style Guide.
// As a result, we handle errors using boolean flags and defer final error handling to the C API level.
if ((conn->error).error_code != SF_STATUS_SUCCESS) {
return SF_STATUS_ERROR_GENERAL;
}
}
catch (...)
{
Expand Down Expand Up @@ -438,7 +444,7 @@ namespace Client
void AuthenticatorOKTA::authenticate()
{
IAuthenticatorOKTA::authenticate();
if ((m_connection->error).error_code == SF_STATUS_SUCCESS && (isError() || m_idp->isError()))
if (isError() || m_idp->isError())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe this hides real IDP error message?

{
const char* err = isError() ? getErrorMessage() : m_idp->getErrorMessage();
SET_SNOWFLAKE_ERROR(&m_connection->error, SF_STATUS_ERROR_GENERAL, err, SF_SQLSTATE_GENERAL_ERROR);
Expand Down
10 changes: 7 additions & 3 deletions cpp/lib/IAuth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace Client
}
else {
CXX_LOG_INFO("sf::IDPAuthenticator::getIDPInfo::Fail to get authenticator info.");
m_errMsg = "Fail to get authenticator info.";
m_errMsg = "Fail to get authenticator info in getIDPInfo.";
ret = false;
}
return ret;
Expand Down Expand Up @@ -359,6 +359,8 @@ namespace Client
{
CXX_LOG_WARN("sf::IAuthenticatorOKTA::authenticate::Fail to get one time token response, response body=%s.",
picojson::value(respData).serialize().c_str());
m_errMsg = "SFAuthenticatorVerificationFailed::authenticate::Fail to get one time token response.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hides real reason in m_idp->m_errMsg. Auth tests failed:

[2025-08-07T18:01:37.120Z] 78: [  ERROR   ] --- "SFAuthenticatorVerificationFailed::authenticate::Fail to get one time token response." != "Incorrect username or password was specified."
[2025-08-07T18:01:37.120Z] 78: [  FAILED  ] test_okta_wrong_credentials

and

[2025-08-07T18:01:58.084Z] 78: [  ERROR   ] --- strstr(error->msg, "SAML response is invalid or matching user is not found. Contact your local system administrator and provide the error code") != NULL
[2025-08-07T18:01:58.084Z] 78: [  FAILED  ] test_external_browser_wrong_credentials


return;
}

Expand All @@ -379,6 +381,8 @@ namespace Client
m_idp->m_retriedCount, m_idp->m_retryTimeout);
continue;
}
CXX_LOG_ERROR("SF::IAuthenticatorOKTA::authenticate::Failed to get the saml response. response body=%s.", picojson::value(resp).serialize().c_str());
m_errMsg = "SFAuthenticatorVerificationFailed::authenticate::Failed to get the saml response.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, m_idp->m_errMsg will be ignored if we set m_errMsg.

return;
}
break;
Expand All @@ -391,10 +395,10 @@ namespace Client
if ((!m_disableSamlUrlCheck) &&
(!urlHasSamePrefix(post_back_url, server_url)))
{
CXX_LOG_ERROR("sf","IAuthenticatorOKTA::authenticate::The specified authenticator and destination URL in Saml Assertion did not match, expected=%s, post back=%s.",
CXX_LOG_ERROR("sf::IAuthenticatorOKTA::authenticate::The specified authenticator and destination URL in Saml Assertion did not match, expected=%s, post back=%s.",
server_url.c_str(),
post_back_url.c_str());
m_errMsg = "SFSamlResponseVerificationFailed.";
m_errMsg = "SFSamlResponseVerificationFailed: The specified authenticator and destination URL in Saml Assertion did not match.";
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test_unit_okta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void test_idp_authenticator(void**)

idp.isCurrentCallFailed = true;
idp.getIDPInfo(dataMap);
assert_string_equal(idp.getErrorMessage(), "Fail to get authenticator info.");
assert_string_equal(idp.getErrorMessage(), "Fail to get authenticator info in getIDPInfo.");

snowflake_term(sf);
}
Expand Down Expand Up @@ -271,7 +271,7 @@ void test_okta_authenticator_fail(void**)

MockOkta okta = MockOkta(sf);
okta.authenticate();
assert_string_equal(okta.getErrorMessage(), "SFSamlResponseVerificationFailed.");
assert_string_equal(okta.getErrorMessage(), "SFSamlResponseVerificationFailed: The specified authenticator and destination URL in Saml Assertion did not match.");

okta.setCurlGetRequestFailed(true);
okta.authenticate();
Expand Down
Loading