-
Notifications
You must be signed in to change notification settings - Fork 10
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
Factor User into a top-level repeatable annotation #8
Open
tombentley
wants to merge
1
commit into
kroxylicious:main
Choose a base branch
from
tombentley:user
base: main
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
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
This file contains 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 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 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
37 changes: 37 additions & 0 deletions
37
impl/src/main/java/io/kroxylicious/testing/kafka/common/User.java
This file contains 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,37 @@ | ||
/* | ||
* Copyright Kroxylicious Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.kroxylicious.testing.kafka.common; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import io.kroxylicious.testing.kafka.api.KafkaClusterConstraint; | ||
|
||
@Target({ ElementType.PARAMETER, ElementType.FIELD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Repeatable(User.List.class) | ||
@KafkaClusterConstraint | ||
public @interface User { | ||
/** | ||
* @return A user name. | ||
*/ | ||
String user(); | ||
|
||
/** | ||
* @return A password. | ||
*/ | ||
String password(); | ||
|
||
@Target({ ElementType.PARAMETER, ElementType.FIELD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@KafkaClusterConstraint | ||
@interface List { | ||
User[] value(); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import io.kroxylicious.testing.kafka.common.KRaftCluster; | ||
import io.kroxylicious.testing.kafka.common.SaslPlainAuth; | ||
import io.kroxylicious.testing.kafka.common.Tls; | ||
import io.kroxylicious.testing.kafka.common.User; | ||
import io.kroxylicious.testing.kafka.common.ZooKeeperCluster; | ||
import io.kroxylicious.testing.kafka.invm.InVMKafkaCluster; | ||
import kafka.server.KafkaConfig; | ||
|
@@ -141,11 +142,25 @@ public void kraftBasedClusterParameter(@BrokerCluster @KRaftCluster KafkaCluster | |
} | ||
|
||
@Test | ||
public void saslPlainAuthenticatingClusterParameter( | ||
@BrokerCluster @SaslPlainAuth({ | ||
@SaslPlainAuth.UserPassword(user = "alice", password = "foo"), | ||
@SaslPlainAuth.UserPassword(user = "bob", password = "bar") | ||
}) KafkaCluster cluster) | ||
public void saslPlainAuthenticatingClusterParameterOneUser( | ||
@BrokerCluster @SaslPlainAuth @User(user = "alice", password = "foo") KafkaCluster cluster) | ||
throws ExecutionException, InterruptedException { | ||
var dc = describeCluster(cluster.getKafkaClientConfiguration("alice", "foo")); | ||
assertEquals(1, dc.nodes().get().size()); | ||
assertEquals(cluster.getClusterId(), dc.clusterId().get()); | ||
|
||
var ee = assertThrows(ExecutionException.class, () -> describeCluster(cluster.getKafkaClientConfiguration("alice", "FOO")), | ||
"Expect bad password to throw"); | ||
assertInstanceOf(SaslAuthenticationException.class, ee.getCause()); | ||
|
||
ee = assertThrows(ExecutionException.class, () -> describeCluster(cluster.getKafkaClientConfiguration("eve", "quux")), | ||
"Expect unknown user to throw"); | ||
assertInstanceOf(SaslAuthenticationException.class, ee.getCause()); | ||
} | ||
|
||
@Test | ||
public void saslPlainAuthenticatingClusterParameterTwoUsers( | ||
@BrokerCluster @SaslPlainAuth @User(user = "alice", password = "foo") @User(user = "bob", password = "bar") KafkaCluster cluster) | ||
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. I found the old version easier to think about. @SaslPlainAuth({
@SaslPlainAuth.UserPassword(user = "alice", password = "foo"),
@SaslPlainAuth.UserPassword(user = "bob", password = "bar")
} Clearly says to me that these users are authenticated via Sasl Plain. Where as the new version you can assume the same but it's less explicit. |
||
throws ExecutionException, InterruptedException { | ||
var dc = describeCluster(cluster.getKafkaClientConfiguration("alice", "foo")); | ||
assertEquals(1, dc.nodes().get().size()); | ||
|
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.
How about
Credentials
rather thanUser
?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.
User seems okay to me.