Skip to content

Commit fd81810

Browse files
committed
Use SET_NON_GRANTED_ROLE error code instead of ACCESS_DENIED
1 parent 665b191 commit fd81810

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/Server/HTTPHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ namespace ErrorCodes
119119
extern const int WRONG_PASSWORD;
120120
extern const int REQUIRED_PASSWORD;
121121
extern const int AUTHENTICATION_FAILED;
122-
extern const int ACCESS_DENIED;
122+
extern const int SET_NON_GRANTED_ROLE;
123123

124124
extern const int INVALID_SESSION_TIMEOUT;
125125
extern const int HTTP_LENGTH_REQUIRED;
@@ -198,7 +198,7 @@ static Poco::Net::HTTPResponse::HTTPStatus exceptionCodeToHTTPStatus(int excepti
198198
else if (exception_code == ErrorCodes::UNKNOWN_USER ||
199199
exception_code == ErrorCodes::WRONG_PASSWORD ||
200200
exception_code == ErrorCodes::AUTHENTICATION_FAILED ||
201-
exception_code == ErrorCodes::ACCESS_DENIED)
201+
exception_code == ErrorCodes::SET_NON_GRANTED_ROLE)
202202
{
203203
return HTTPResponse::HTTP_FORBIDDEN;
204204
}
@@ -748,7 +748,7 @@ void HTTPHandler::processQuery(
748748
if (user->granted_roles.isGranted(role_id))
749749
roles_ids.push_back(role_id);
750750
else
751-
throw Exception(ErrorCodes::ACCESS_DENIED, "Role {} is not granted to the current user", role_params_it->second);
751+
throw Exception(ErrorCodes::SET_NON_GRANTED_ROLE, "Role {} should be granted to set as a current", role_params_it->second);
752752
}
753753
}
754754
context->setCurrentRoles(roles_ids);

tests/queries/0_stateless/03096_http_interface_role_query_param.reference

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ max_result_rows 42
2525
03096_role_query_param_role1
2626
03096_role_query_param_role2
2727
max_result_rows 42
28-
### Cannot set a role that is not granted to the user (single parameter)
29-
Code: 497
30-
ACCESS_DENIED
31-
### Cannot set a role that is not granted to the user (multiple parameters)
32-
Code: 497
33-
ACCESS_DENIED
3428
### Cannot set a role that does not exist (single parameter)
3529
Code: 511
3630
UNKNOWN_ROLE
3731
### Cannot set a role that does not exist (multiple parameters)
3832
Code: 511
3933
UNKNOWN_ROLE
34+
### Cannot set a role that is not granted to the user (single parameter)
35+
Code: 512
36+
SET_NON_GRANTED_ROLE
37+
### Cannot set a role that is not granted to the user (multiple parameters)
38+
Code: 512
39+
SET_NON_GRANTED_ROLE

tests/queries/0_stateless/03096_http_interface_role_query_param.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ echo "### Sets multiple roles when there are other parameters in the query"
7373
$CLICKHOUSE_CURL -u $TEST_USER_AUTH -sS "$CLICKHOUSE_URL&role=$TEST_ROLE1&$CHANGED_SETTING_NAME=$CHANGED_SETTING_VALUE&role=$TEST_ROLE2" --data-binary "$SHOW_CURRENT_ROLES_QUERY"
7474
$CLICKHOUSE_CURL -u $TEST_USER_AUTH -sS "$CLICKHOUSE_URL&role=$TEST_ROLE1&$CHANGED_SETTING_NAME=$CHANGED_SETTING_VALUE&role=$TEST_ROLE2" --data-binary "$SHOW_CHANGED_SETTINGS_QUERY"
7575

76-
echo "### Cannot set a role that is not granted to the user (single parameter)"
77-
OUT=$($CLICKHOUSE_CURL -u $TEST_USER_AUTH -sS "$CLICKHOUSE_URL&role=$TEST_ROLE_NOT_GRANTED" --data-binary "$SHOW_CURRENT_ROLES_QUERY")
78-
echo -ne $OUT | grep -o "Code: 497" || echo "expected code 497, got: $OUT"
79-
echo -ne $OUT | grep -o "ACCESS_DENIED" || echo "expected ACCESS_DENIED error, got: $OUT"
80-
81-
echo "### Cannot set a role that is not granted to the user (multiple parameters)"
82-
OUT=$($CLICKHOUSE_CURL -u $TEST_USER_AUTH -sS "$CLICKHOUSE_URL&role=$TEST_ROLE1&role=$TEST_ROLE_NOT_GRANTED" --data-binary "$SHOW_CURRENT_ROLES_QUERY")
83-
echo -ne $OUT | grep -o "Code: 497" || echo "expected code 497, got: $OUT"
84-
echo -ne $OUT | grep -o "ACCESS_DENIED" || echo "expected ACCESS_DENIED error, got: $OUT"
85-
8676
echo "### Cannot set a role that does not exist (single parameter)"
8777
OUT=$($CLICKHOUSE_CURL -u $TEST_USER_AUTH -sS "$CLICKHOUSE_URL&role=aaaaaaaaaaa" --data-binary "$SHOW_CURRENT_ROLES_QUERY")
8878
echo -ne $OUT | grep -o "Code: 511" || echo "expected code 511, got: $OUT"
@@ -93,6 +83,16 @@ OUT=$($CLICKHOUSE_CURL -u $TEST_USER_AUTH -sS "$CLICKHOUSE_URL&role=$TEST_ROLE1&
9383
echo -ne $OUT | grep -o "Code: 511" || echo "expected code 511, got: $OUT"
9484
echo -ne $OUT | grep -o "UNKNOWN_ROLE" || echo "expected UNKNOWN_ROLE error, got: $OUT"
9585

86+
echo "### Cannot set a role that is not granted to the user (single parameter)"
87+
OUT=$($CLICKHOUSE_CURL -u $TEST_USER_AUTH -sS "$CLICKHOUSE_URL&role=$TEST_ROLE_NOT_GRANTED" --data-binary "$SHOW_CURRENT_ROLES_QUERY")
88+
echo -ne $OUT | grep -o "Code: 512" || echo "expected code 512, got: $OUT"
89+
echo -ne $OUT | grep -o "SET_NON_GRANTED_ROLE" || echo "expected SET_NON_GRANTED_ROLE error, got: $OUT"
90+
91+
echo "### Cannot set a role that is not granted to the user (multiple parameters)"
92+
OUT=$($CLICKHOUSE_CURL -u $TEST_USER_AUTH -sS "$CLICKHOUSE_URL&role=$TEST_ROLE1&role=$TEST_ROLE_NOT_GRANTED" --data-binary "$SHOW_CURRENT_ROLES_QUERY")
93+
echo -ne $OUT | grep -o "Code: 512" || echo "expected code 512, got: $OUT"
94+
echo -ne $OUT | grep -o "SET_NON_GRANTED_ROLE" || echo "expected SET_NON_GRANTED_ROLE error, got: $OUT"
95+
9696
$CLICKHOUSE_CLIENT -n --query "
9797
DROP USER $TEST_USER;
9898
DROP ROLE $TEST_ROLE1;

0 commit comments

Comments
 (0)