You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2018/12/23 16:08:47 UTC
[pulsar] branch master updated: [Pulsar-Broker-Common] Extend
AuthenticationProviderToken UT Coverages (#3244)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 5dc90b4 [Pulsar-Broker-Common] Extend AuthenticationProviderToken UT Coverages (#3244)
5dc90b4 is described below
commit 5dc90b413cbd9d97614dfe7cbca9c32e6e4457fb
Author: Eren Avsarogullari <er...@gmail.com>
AuthorDate: Sun Dec 23 16:08:41 2018 +0000
[Pulsar-Broker-Common] Extend AuthenticationProviderToken UT Coverages (#3244)
* [Pulsar-Broker-Common] Extend AuthenticationProviderToken UT Coverage
* Add UT to simulate invalid Public Key Path case
---
.../AuthenticationProviderToken.java | 4 ++--
.../AuthenticationProviderTokenTest.java | 24 ++++++++++++++++++++++
.../pulsar/utils/auth/tokens/TokensCliUtils.java | 2 --
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderToken.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderToken.java
index 7e155c3..c2bd63e 100644
--- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderToken.java
+++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderToken.java
@@ -37,7 +37,7 @@ public class AuthenticationProviderToken implements AuthenticationProvider {
final static String HTTP_HEADER_NAME = "Authorization";
final static String HTTP_HEADER_VALUE_PREFIX = "Bearer ";
- // When simmetric key is configured
+ // When symmetric key is configured
final static String CONF_TOKEN_SECRET_KEY = "tokenSecretKey";
// When public/private key pair is configured
@@ -92,7 +92,7 @@ public class AuthenticationProviderToken implements AuthenticationProvider {
}
private String validateToken(final String token) throws AuthenticationException {
- if(StringUtils.isNotBlank(token)) {
+ if (StringUtils.isNotBlank(token)) {
return token;
} else {
throw new AuthenticationException("Blank token found");
diff --git a/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/authentication/AuthenticationProviderTokenTest.java b/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/authentication/AuthenticationProviderTokenTest.java
index 36b14c6..4a5ca2f 100644
--- a/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/authentication/AuthenticationProviderTokenTest.java
+++ b/pulsar-broker-common/src/test/java/org/apache/pulsar/broker/authentication/AuthenticationProviderTokenTest.java
@@ -406,4 +406,28 @@ public class AuthenticationProviderTokenTest {
AuthenticationProviderToken provider = new AuthenticationProviderToken();
provider.initialize(conf);
}
+
+ @Test(expectedExceptions = IOException.class)
+ public void testInitializeWhenSecretKeyFilePathIsInvalid() throws IOException {
+ Properties properties = new Properties();
+ properties.setProperty(AuthenticationProviderToken.CONF_TOKEN_SECRET_KEY,
+ "file://" + "invalid_secret_key_file");
+
+ ServiceConfiguration conf = new ServiceConfiguration();
+ conf.setProperties(properties);
+
+ new AuthenticationProviderToken().initialize(conf);
+ }
+
+ @Test(expectedExceptions = IOException.class)
+ public void testInitializeWhenPublicKeyFilePathIsInvalid() throws IOException {
+ Properties properties = new Properties();
+ properties.setProperty(AuthenticationProviderToken.CONF_TOKEN_PUBLIC_KEY,
+ "file://" + "invalid_public_key_file");
+
+ ServiceConfiguration conf = new ServiceConfiguration();
+ conf.setProperties(properties);
+
+ new AuthenticationProviderToken().initialize(conf);
+ }
}
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/utils/auth/tokens/TokensCliUtils.java b/pulsar-broker/src/main/java/org/apache/pulsar/utils/auth/tokens/TokensCliUtils.java
index 19e71f3..2ebead5 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/utils/auth/tokens/TokensCliUtils.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/utils/auth/tokens/TokensCliUtils.java
@@ -25,7 +25,6 @@ import com.google.common.base.Charsets;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwt;
-import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.io.Decoders;
@@ -44,7 +43,6 @@ import java.util.Optional;
import java.util.concurrent.TimeUnit;
import javax.crypto.SecretKey;
-import javax.naming.AuthenticationException;
import lombok.Cleanup;