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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class PipeParametersTest {

Expand All @@ -33,10 +35,60 @@ public void keyReducerTest() {

Assert.assertEquals(true, parameters.getBoolean("with-quality"));
Assert.assertEquals(true, parameters.getBoolean("opcua.with-quality"));
Assert.assertTrue(parameters.hasAnyAttributes("missing-key", "sink.opcua.with-quality"));

// Invalid
parameters.addAttribute("sink.source.opcua.value-name", "false");
parameters.addAttribute("opcua.sink.value-name", "false");
Assert.assertNull(parameters.getString("value-name"));
}

@Test
public void equivalentAttributeReplacementTest() {
final Map<String, String> attributes = new HashMap<>();
attributes.put("sink.opcua.with-quality", "false");
final PipeParameters parameters = new PipeParameters(attributes);

final Map<String, String> replacements = new HashMap<>();
replacements.put("connector.opcua.with-quality", "true");
parameters.addOrReplaceEquivalentAttributes(new PipeParameters(replacements));

Assert.assertFalse(parameters.getAttribute().containsKey("sink.opcua.with-quality"));
Assert.assertEquals("true", parameters.getAttribute().get("connector.opcua.with-quality"));
}

@Test
public void equivalentAttributeReplacementWithCloneTest() {
final Map<String, String> attributes = new HashMap<>();
attributes.put("sink.opcua.with-quality", "false");
final PipeParameters parameters = new PipeParameters(attributes);

final Map<String, String> replacements = new HashMap<>();
replacements.put("connector.opcua.with-quality", "true");
final PipeParameters clonedParameters =
parameters.addOrReplaceEquivalentAttributesWithClone(new PipeParameters(replacements));

Assert.assertEquals("false", parameters.getAttribute().get("sink.opcua.with-quality"));
Assert.assertEquals("true", clonedParameters.getString("with-quality"));
Assert.assertEquals(
"true",
clonedParameters.getStringOrDefault(
Arrays.asList("missing-key", "sink.opcua.with-quality"), "default"));
}

@Test
public void toStringShouldHideSensitiveValues() {
final Map<String, String> attributes = new HashMap<>();
attributes.put("sink.password", "secret");
attributes.put("connector.ssl.trust-store-pwd", "credential");
attributes.put("visible", "value");

final String parametersString = new PipeParameters(attributes).toString();

Assert.assertTrue(parametersString.contains("sink.password=******"));
Assert.assertTrue(parametersString.contains("connector.ssl.trust-store-pwd=******"));
Assert.assertTrue(parametersString.contains("visible=value"));
Assert.assertFalse(parametersString.contains("secret"));
Assert.assertFalse(parametersString.contains("credential"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class PipeConfigScopeParseVisitorTest {
Expand All @@ -44,38 +46,35 @@ public void testTreeScopeParsing() {

private void testTreeScopeParsing(final ConfigPhysicalPlanType type, final boolean isUser) {
Assert.assertEquals(
new AuthorTreePlan(
type,
isUser ? "user" : "",
isUser ? "" : "role",
"",
"",
new HashSet<>(
Arrays.stream(PrivilegeType.values())
.filter(PrivilegeType::forRelationalSys)
.map(Enum::ordinal)
.collect(Collectors.toList())),
false,
Collections.singletonList(new PartialPath(new String[] {"root", "**"}))),
treeAuthorPlan(
type, isUser, privileges(PrivilegeType::forRelationalSys), false, rootPattern()),
IoTDBConfigRegionSource.TREE_SCOPE_PARSE_VISITOR
.process(
new AuthorTreePlan(
treeAuthorPlan(
type,
isUser ? "user" : "",
isUser ? "" : "role",
"",
"",
new HashSet<>(
Arrays.stream(PrivilegeType.values())
.filter(privilegeType -> !privilegeType.isRelationalPrivilege())
.map(Enum::ordinal)
.collect(Collectors.toList())),
isUser,
privileges(privilegeType -> !privilegeType.isRelationalPrivilege()),
false,
Collections.singletonList(new PartialPath(new String[] {"root", "**"}))),
rootPattern()),
null)
.orElseThrow(AssertionError::new));
}

@Test
public void testTreeScopeParsingSkipsWithoutRelationalSystemPrivilege() {
Assert.assertFalse(
IoTDBConfigRegionSource.TREE_SCOPE_PARSE_VISITOR
.process(
treeAuthorPlan(
ConfigPhysicalPlanType.GrantUser,
true,
Collections.singleton(PrivilegeType.READ_DATA.ordinal()),
false,
rootPattern()),
null)
.isPresent());
}

@Test
public void testTableScopeParsing() {
testTableScopeParsing(
Expand All @@ -93,24 +92,41 @@ private void testTableScopeParsing(
final ConfigPhysicalPlanType inputType,
final boolean isUser) {
Assert.assertEquals(
new AuthorTreePlan(
treeAuthorPlan(
outputType,
isUser ? "user" : "",
isUser ? "" : "role",
"",
"",
new HashSet<>(
Arrays.stream(PrivilegeType.values())
.filter(PrivilegeType::forRelationalSys)
.map(Enum::ordinal)
.collect(Collectors.toList())),
isUser,
privileges(PrivilegeType::forRelationalSys),
true,
Collections.emptyList()),
IoTDBConfigRegionSource.TABLE_SCOPE_PARSE_VISITOR
.process(
new AuthorRelationalPlan(
inputType, isUser ? "user" : "", isUser ? "" : "role", "", "", -1, true),
null)
.process(relationalAuthorPlan(inputType, isUser, true), null)
.orElseThrow(AssertionError::new));
}

private AuthorTreePlan treeAuthorPlan(
final ConfigPhysicalPlanType type,
final boolean isUser,
final Set<Integer> permissions,
final boolean grantOption,
final List<PartialPath> paths) {
return new AuthorTreePlan(
type, isUser ? "user" : "", isUser ? "" : "role", "", "", permissions, grantOption, paths);
}

private AuthorRelationalPlan relationalAuthorPlan(
final ConfigPhysicalPlanType type, final boolean isUser, final boolean grantOption) {
return new AuthorRelationalPlan(
type, isUser ? "user" : "", isUser ? "" : "role", "", "", -1, grantOption);
}

private Set<Integer> privileges(final Predicate<PrivilegeType> predicate) {
return Arrays.stream(PrivilegeType.values())
.filter(predicate)
.map(Enum::ordinal)
.collect(Collectors.toSet());
}

private List<PartialPath> rootPattern() {
return Collections.singletonList(new PartialPath(new String[] {"root", "**"}));
}
}
Loading