Skip to content
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

IGNITE-14786 Authentication ducktest should not use internal api #9131

Merged
merged 17 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,37 @@

import com.fasterxml.jackson.databind.JsonNode;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.internal.ducktest.utils.IgniteAwareApplication;
import org.apache.ignite.internal.processors.authentication.AuthorizationContext;
import org.apache.ignite.internal.processors.authentication.IgniteAuthenticationProcessor;
import org.apache.ignite.internal.processors.rest.GridRestCommand;

/**
* Simple application that modify users.
*/
public class UserModifyingApplication extends IgniteAwareApplication {
/** {@inheritDoc} */
@Override public void run(JsonNode jsonNode) throws IgniteCheckedException {
@Override public void run(final JsonNode jsonNode) throws IgniteCheckedException {
String restKey = jsonNode.get("rest_key").asText();

String authName = jsonNode.get("auth_username").asText();

String authPwd = jsonNode.get("auth_password").asText();

String name = jsonNode.get("username").asText();

String pwd = jsonNode.get("password").asText();

markInitialized();

log.info("Input data: " + jsonNode.toString());

IgniteAuthenticationProcessor auth = ((IgniteEx)ignite).context().authentication();

AuthorizationContext actx = auth.authenticate(authName, authPwd);
AuthorizationContext.context(actx);

GridRestCommand cmd = GridRestCommand.fromKey(restKey);

switch (cmd) {
case ADD_USER:
auth.addUser(name, pwd);
client.query(new SqlFieldsQuery(String.format("CREATE USER %s WITH PASSWORD '%s';", name, pwd))).getAll();
break;

case UPDATE_USER:
auth.updateUser(name, pwd);
client.query(new SqlFieldsQuery(String.format("ALTER USER %s WITH PASSWORD '%s';", name, pwd))).getAll();
break;

case REMOVE_USER:
auth.removeUser(name);
client.query(new SqlFieldsQuery(String.format("DROP USER %s;", name))).getAll();
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class IgniteThinClientConfiguration(NamedTuple):
addresses: str = None
version: IgniteVersion = DEV_BRANCH
ssl_params: SslParams = None
username: str = None
password: str = None

def __prepare_ssl(self, test_globals, shared_root):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
</list>
</property>

{% if config.username %}
<property name="userName" value="{{ config.username }}"/>
<property name="userPassword" value="{{ config.password }}"/>
{% endif %}

{% if config.ssl_params %}
<property name="sslMode" value="REQUIRED"/>
<property name="sslClientCertificateKeyStorePath" value="{{ config.ssl_params.key_store_path }}"/>
Expand Down
17 changes: 10 additions & 7 deletions modules/ducktests/tests/ignitetest/tests/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
from ignitetest.services.utils.ignite_configuration import IgniteConfiguration, DataStorageConfiguration
from ignitetest.services.utils.ignite_configuration.data_storage import DataRegionConfiguration
from ignitetest.utils import ignite_versions, cluster
from ignitetest.services.utils.ignite_configuration.discovery import from_ignite_cluster
from ignitetest.services.utils.ignite_configuration import IgniteThinClientConfiguration
from ignitetest.services.utils.ssl.client_connector_configuration import ClientConnectorConfiguration
from ignitetest.utils.ignite_test import IgniteTest
from ignitetest.utils.version import DEV_BRANCH, LATEST, IgniteVersion

WRONG_PASSWORD = "wrong_password"
TEST_USERNAME = "admin"
TEST_USERNAME = "ADMIN"
map7000 marked this conversation as resolved.
Show resolved Hide resolved
TEST_PASSWORD = "qwe123"
TEST_PASSWORD2 = "123qwe"

Expand Down Expand Up @@ -57,8 +58,8 @@ def test_change_users(self, ignite_version):
auth_enabled=True,
version=IgniteVersion(ignite_version),
data_storage=DataStorageConfiguration(
default=DataRegionConfiguration(persistent=True),
)
default=DataRegionConfiguration(persistent=True)),
client_connector_configuration=ClientConnectorConfiguration()
)

servers = IgniteService(self.test_context, config=config, num_nodes=self.NUM_NODES - 1)
Expand All @@ -67,7 +68,11 @@ def test_change_users(self, ignite_version):

ControlUtility(cluster=servers, username=DEFAULT_AUTH_USERNAME, password=DEFAULT_AUTH_PASSWORD).activate()

client_cfg = config._replace(client_mode=True, discovery_spi=from_ignite_cluster(servers))
client_cfg = IgniteThinClientConfiguration(
addresses=servers.nodes[0].account.hostname + ":" + str(config.client_connector_configuration.port),
version=IgniteVersion(ignite_version),
username=DEFAULT_AUTH_USERNAME,
password=DEFAULT_AUTH_PASSWORD)

# Add new user
check_authenticate(servers, TEST_USERNAME, TEST_PASSWORD, True)
Expand Down Expand Up @@ -95,8 +100,6 @@ def run_with_creds(self, client_configuration, rest_key: str, name: str, passwor
client_configuration,
java_class_name="org.apache.ignite.internal.ducktest.tests.authentication.UserModifyingApplication",
params={"rest_key": rest_key,
"auth_username": DEFAULT_AUTH_USERNAME,
"auth_password": DEFAULT_AUTH_PASSWORD,
"username": name,
"password": password}
)
Expand Down