-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Subscription: support encrypted password auth in consumer builder #17480
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
Open
VGalaxies
wants to merge
3
commits into
apache:master
Choose a base branch
from
VGalaxies:codex/subscription-encrypted-password-auth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
174 changes: 174 additions & 0 deletions
174
...bscription/it/triple/treemodel/regression/param/IoTDBEncryptedPasswordPullConsumerIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iotdb.subscription.it.triple.treemodel.regression.param; | ||
|
|
||
| import org.apache.iotdb.commons.utils.AuthUtils; | ||
| import org.apache.iotdb.it.framework.IoTDBTestRunner; | ||
| import org.apache.iotdb.itbase.category.MultiClusterIT2SubscriptionTreeRegressionMisc; | ||
| import org.apache.iotdb.rpc.IoTDBConnectionException; | ||
| import org.apache.iotdb.rpc.StatementExecutionException; | ||
| import org.apache.iotdb.session.subscription.consumer.tree.SubscriptionTreePullConsumer; | ||
| import org.apache.iotdb.subscription.it.triple.treemodel.regression.AbstractSubscriptionTreeRegressionIT; | ||
|
|
||
| import org.apache.thrift.TException; | ||
| import org.apache.tsfile.enums.TSDataType; | ||
| import org.apache.tsfile.file.metadata.enums.CompressionType; | ||
| import org.apache.tsfile.file.metadata.enums.TSEncoding; | ||
| import org.apache.tsfile.write.record.Tablet; | ||
| import org.apache.tsfile.write.schema.IMeasurementSchema; | ||
| import org.apache.tsfile.write.schema.MeasurementSchema; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Ignore; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| @Ignore("TODO: enable after encrypted password subscription IT stabilizes") | ||
| @RunWith(IoTDBTestRunner.class) | ||
| @Category({MultiClusterIT2SubscriptionTreeRegressionMisc.class}) | ||
| public class IoTDBEncryptedPasswordPullConsumerIT extends AbstractSubscriptionTreeRegressionIT { | ||
|
|
||
| private static final String DATABASE = "root.TestEncryptedPasswordPullConsumer"; | ||
| private static final String DEVICE = DATABASE + ".d_0"; | ||
| private static final String TOPIC_NAME = "TestEncryptedPasswordPullConsumerTopic"; | ||
| private static final String USERNAME = "encrypted_user"; | ||
| private static final String PASSWORD = "EncryptedUser@123"; | ||
| private static final String ENCRYPTED_PASSWORD = AuthUtils.encryptPassword(PASSWORD); | ||
| private static final String WRONG_ENCRYPTED_PASSWORD = | ||
| AuthUtils.encryptPassword("WrongEncryptedUser@123"); | ||
|
|
||
| private static final List<IMeasurementSchema> SCHEMA_LIST = new ArrayList<>(); | ||
|
|
||
| static { | ||
| SCHEMA_LIST.add(new MeasurementSchema("s_0", TSDataType.INT64)); | ||
| SCHEMA_LIST.add(new MeasurementSchema("s_1", TSDataType.DOUBLE)); | ||
| } | ||
|
|
||
| private SubscriptionTreePullConsumer consumer; | ||
|
|
||
| @Override | ||
| @Before | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| createDB(DATABASE); | ||
| createTopic_s(TOPIC_NAME, "root.**", null, null, false); | ||
| session_src.createTimeseries( | ||
| DEVICE + ".s_0", TSDataType.INT64, TSEncoding.GORILLA, CompressionType.LZ4); | ||
| session_src.createTimeseries( | ||
| DEVICE + ".s_1", TSDataType.DOUBLE, TSEncoding.TS_2DIFF, CompressionType.LZ4); | ||
| session_dest.createTimeseries( | ||
| DEVICE + ".s_0", TSDataType.INT64, TSEncoding.GORILLA, CompressionType.LZ4); | ||
| session_dest.createTimeseries( | ||
| DEVICE + ".s_1", TSDataType.DOUBLE, TSEncoding.TS_2DIFF, CompressionType.LZ4); | ||
| session_src.executeNonQueryStatement("create user " + USERNAME + " '" + PASSWORD + "'"); | ||
| session_src.executeNonQueryStatement("grant read,write on root.** to user " + USERNAME); | ||
| assertTrue(subs.getTopic(TOPIC_NAME).isPresent()); | ||
| } | ||
|
|
||
| @Override | ||
| @After | ||
| public void tearDown() throws Exception { | ||
| try { | ||
| if (consumer != null) { | ||
| consumer.close(); | ||
| } | ||
| } catch (final Exception ignored) { | ||
| } | ||
| try { | ||
| subs.dropTopic(TOPIC_NAME); | ||
| } catch (final Exception ignored) { | ||
| } | ||
| try { | ||
| session_src.executeNonQueryStatement("drop user " + USERNAME); | ||
| } catch (final Exception ignored) { | ||
| } | ||
| dropDB(DATABASE); | ||
| super.tearDown(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSubscribeWithEncryptedPassword() | ||
| throws TException, | ||
| IoTDBConnectionException, | ||
| IOException, | ||
| StatementExecutionException, | ||
| InterruptedException { | ||
| consumer = createConsumer("encrypted-password-group", ENCRYPTED_PASSWORD); | ||
|
|
||
| consumer.open(); | ||
| consumer.subscribe(TOPIC_NAME); | ||
| assertEquals(1, subs.getSubscriptions().size(), "subscribe with encrypted password"); | ||
|
|
||
| insertData(1706659200000L); | ||
| consume_data(consumer, session_dest); | ||
| check_count( | ||
| 4, | ||
| "select count(s_0) from " + DEVICE + " where time >= 1706659200000", | ||
| "encrypted password consumption"); | ||
|
Comment on lines
+128
to
+132
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mind code style |
||
| } | ||
|
|
||
| @Test | ||
| public void testSubscribeFailsWithWrongEncryptedPassword() | ||
| throws IoTDBConnectionException, StatementExecutionException { | ||
| consumer = createConsumer("wrong-encrypted-password-group", WRONG_ENCRYPTED_PASSWORD); | ||
|
|
||
| try { | ||
| consumer.open(); | ||
| consumer.subscribe(TOPIC_NAME); | ||
| fail("subscribe should fail when encrypted password mismatches"); | ||
| } catch (final Exception ignored) { | ||
| assertTrue(subs.getSubscriptions().isEmpty()); | ||
| } | ||
| } | ||
|
|
||
| private SubscriptionTreePullConsumer createConsumer( | ||
| final String consumerGroupId, final String encryptedPassword) { | ||
| return new SubscriptionTreePullConsumer.Builder() | ||
| .host(SRC_HOST) | ||
| .port(SRC_PORT) | ||
| .username(USERNAME) | ||
| .password(PASSWORD) | ||
| .encryptedPassword(encryptedPassword) | ||
|
Comment on lines
+151
to
+156
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is weird to set both password and encryptedPassword. |
||
| .consumerId("consumer_" + consumerGroupId) | ||
| .consumerGroupId(consumerGroupId) | ||
| .buildPullConsumer(); | ||
| } | ||
|
|
||
| private void insertData(long timestamp) | ||
| throws IoTDBConnectionException, StatementExecutionException { | ||
| final Tablet tablet = new Tablet(DEVICE, SCHEMA_LIST, 10); | ||
| for (int row = 0; row < 5; row++) { | ||
| final int rowIndex = tablet.getRowSize(); | ||
| tablet.addTimestamp(rowIndex, timestamp); | ||
| tablet.addValue("s_0", rowIndex, row * 20L + row); | ||
| tablet.addValue("s_1", rowIndex, row + 2.45); | ||
| timestamp += row * 2000; | ||
| } | ||
| session_src.insertTablet(tablet); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this unstable?