From 32a2a97569fd8ced10a813eacb665b1095213440 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Wed, 7 Apr 2021 08:01:53 +0800 Subject: [PATCH] fix the issue that access key doesn't work if appid passed is in different case (#3627) --- .../configservice/service/AccessKeyServiceWithCache.java | 2 +- .../configservice/service/AccessKeyServiceWithCacheTest.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/service/AccessKeyServiceWithCache.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/service/AccessKeyServiceWithCache.java index 090f7145947..6d8ef423a41 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/service/AccessKeyServiceWithCache.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/service/AccessKeyServiceWithCache.java @@ -63,7 +63,7 @@ private void initialize() { ApolloThreadFactory.create("AccessKeyServiceWithCache", true)); lastTimeScanned = new Date(0L); - ListMultimap multimap = ListMultimapBuilder.hashKeys(128) + ListMultimap multimap = ListMultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER) .arrayListValues().build(); accessKeyCache = Multimaps.synchronizedListMultimap(multimap); accessKeyIdCache = Maps.newConcurrentMap(); diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/service/AccessKeyServiceWithCacheTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/service/AccessKeyServiceWithCacheTest.java index 53644221cfc..c2b0d4dbea3 100644 --- a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/service/AccessKeyServiceWithCacheTest.java +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/service/AccessKeyServiceWithCacheTest.java @@ -81,6 +81,11 @@ public void testGetAvailableSecrets() throws Exception { await().untilAsserted(() -> assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId)) .containsExactly("secret-1", "secret-2")); + // should also work with appid in different case + assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId.toUpperCase())) + .containsExactly("secret-1", "secret-2"); + assertThat(accessKeyServiceWithCache.getAvailableSecrets(appId.toLowerCase())) + .containsExactly("secret-1", "secret-2"); // Update access key, disable the first one firstAccessKey = assembleAccessKey(1L, appId, "secret-1", false, false, 1577808004000L);