mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(storage): record the owning account on putAll, so a cross-account lookup finds the entries (#7520)
This commit is contained in:
1 parent
5762323bb5
commit
fab3e7b923
2 files changed
+34
-4
No files matched your search
+2
-4
@@ -77,10 +77,7 @@ public class AccountAwareStorageBackend<V> implements StorageBackend<String, V>
|
||||
|
||||
@Override
|
||||
public void putAll(Map<String, V> entries) {
|
||||
String prefix = prefix() + "/";
|
||||
Map<String, V> prefixedEntries = new LinkedHashMap<>();
|
||||
entries.forEach((key, value) -> prefixedEntries.put(prefix + key, value));
|
||||
delegate.putAll(prefixedEntries);
|
||||
putAllForAccount(prefix(), entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -448,6 +445,7 @@ public class AccountAwareStorageBackend<V> implements StorageBackend<String, V>
|
||||
Map<String, V> prefixedEntries = new LinkedHashMap<>();
|
||||
entries.forEach((key, value) -> prefixedEntries.put(prefix + key, value));
|
||||
delegate.putAll(prefixedEntries);
|
||||
trackOwner(accountId);
|
||||
}
|
||||
|
||||
public void deleteForAccount(String accountId, String key) {
|
||||
|
||||
+32
@@ -1,5 +1,7 @@
|
||||
package io.github.hectorvent.floci.core.storage;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.RequestContext;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
@@ -20,10 +22,12 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class AccountAwareStorageBackendTest {
|
||||
|
||||
@@ -497,6 +501,34 @@ class AccountAwareStorageBackendTest {
|
||||
assertEquals("333333333333", storage.findAnyAccountEntry("LOADED").orElseThrow().account());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putAllForAccountIntoAnotherAccountIsTracked() {
|
||||
AccountAwareStorageBackend<String> storage =
|
||||
new AccountAwareStorageBackend<>(new InMemoryStorage<>(), null, "111111111111");
|
||||
storage.findAnyAccountEntry("MISSING");
|
||||
|
||||
storage.putAllForAccount("222222222222", Map.of("ASIAKEY", "session"));
|
||||
|
||||
assertEquals("222222222222", storage.findAnyAccountEntry("ASIAKEY").orElseThrow().account());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putAllFromAnotherRequestAccountIsTracked() {
|
||||
RequestContext request = new RequestContext();
|
||||
@SuppressWarnings("unchecked")
|
||||
Instance<RequestContext> context = mock(Instance.class);
|
||||
when(context.get()).thenReturn(request);
|
||||
AccountAwareStorageBackend<String> storage =
|
||||
new AccountAwareStorageBackend<>(new InMemoryStorage<>(), context, "111111111111");
|
||||
storage.findAnyAccountEntry("MISSING");
|
||||
|
||||
request.setAccountId("222222222222");
|
||||
storage.putAll(Map.of("ASIAKEY", "session"));
|
||||
request.setAccountId("111111111111");
|
||||
|
||||
assertEquals("222222222222", storage.findAnyAccountEntry("ASIAKEY").orElseThrow().account());
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyMigrationIntoAnotherAccountIsTracked() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
|
||||
Reference in new issue
Block a user