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

Make AuthenticationTokenTest to run on windows #12329

Merged
merged 1 commit into from
Oct 13, 2021
Merged
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 @@ -30,7 +30,6 @@
import java.util.function.Supplier;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.SerializationUtils;
import org.apache.pulsar.client.api.Authentication;
import org.apache.pulsar.client.api.AuthenticationDataProvider;
import org.apache.pulsar.client.impl.PulsarClientImpl;
Expand Down Expand Up @@ -100,12 +99,12 @@ public void testAuthTokenConfig() throws Exception {

@Test
public void testAuthTokenConfigFromFile() throws Exception {
File tokenFile = File.createTempFile("pular-test-token", ".key");
File tokenFile = File.createTempFile("pulsar-test-token", ".key");
tokenFile.deleteOnExit();
FileUtils.write(tokenFile, "my-test-token-string", Charsets.UTF_8);

AuthenticationToken authToken = new AuthenticationToken();
authToken.configure("file://" + tokenFile);
authToken.configure(getTokenFileUri(tokenFile));
assertEquals(authToken.getAuthMethodName(), "token");

AuthenticationDataProvider authData = authToken.getAuthData();
Expand All @@ -128,12 +127,12 @@ public void testAuthTokenConfigFromFile() throws Exception {
*/
@Test
public void testAuthTokenConfigFromFileWithNewline() throws Exception {
File tokenFile = File.createTempFile("pular-test-token", ".key");
File tokenFile = File.createTempFile("pulsar-test-token", ".key");
tokenFile.deleteOnExit();
FileUtils.write(tokenFile, " my-test-token-string \r\n", Charsets.UTF_8);

AuthenticationToken authToken = new AuthenticationToken();
authToken.configure("file://" + tokenFile);
authToken.configure(getTokenFileUri(tokenFile));
assertEquals(authToken.getAuthMethodName(), "token");

AuthenticationDataProvider authData = authToken.getAuthData();
Expand Down Expand Up @@ -197,10 +196,14 @@ public void testSerializableAuthentication() throws Exception {
assertEquals(tokenSupplier.token, ts.getAuthData().getCommandData());
}

private String getTokenFileUri(File file) {
return "file:///" + file.toString().replace('\\', '/');
}

public static class SerializableSupplier implements Supplier<String>, Serializable {

private static final long serialVersionUID = 6259616338933150683L;
private String token;
private final String token;

public SerializableSupplier(final String token) {
super();
Expand Down