ARTEMIS-4742 decoding PersistedSecuritySetting fails after upgrade

This commit is contained in:
Justin Bertram 2024-04-22 17:41:30 -05:00 committed by Gary Tully
parent 86f7250d1c
commit f7288c16a6
2 changed files with 38 additions and 2 deletions

View File

@ -252,8 +252,12 @@ public class PersistedSecuritySetting implements EncodingSupport {
browseRoles = buffer.readNullableSimpleString();
createAddressRoles = buffer.readNullableSimpleString();
deleteAddressRoles = buffer.readNullableSimpleString();
viewRoles = buffer.readNullableSimpleString();
editRoles = buffer.readNullableSimpleString();
if (buffer.readableBytes() > 0) {
viewRoles = buffer.readNullableSimpleString();
}
if (buffer.readableBytes() > 0) {
editRoles = buffer.readNullableSimpleString();
}
}
/* (non-Javadoc)

View File

@ -19,9 +19,14 @@ package org.apache.activemq.artemis.tests.integration.security;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.core.persistence.config.PersistedSecuritySetting;
import org.apache.activemq.artemis.tests.util.RandomUtil;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class PersistedSecuritySettingTest {
@Test
@ -43,4 +48,31 @@ public class PersistedSecuritySettingTest {
persistedSecuritySetting.getViewRoles();
persistedSecuritySetting.getEditRoles();
}
@Test
public void testUpgradeAfterARTEMIS_4582() {
// this buffer simulates a PersistedSecuritySetting journal entry from *before* ARTEMIS-4582
SimpleString match = RandomUtil.randomSimpleString();
ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer((SimpleString.sizeofNullableString(match)) + 10);
buffer.writeSimpleString(match);
for (int i = 0; i < 10; i++) {
buffer.writeNullableSimpleString(null);
}
PersistedSecuritySetting persistedSecuritySetting = new PersistedSecuritySetting();
persistedSecuritySetting.decode(buffer);
assertEquals(match, persistedSecuritySetting.getAddressMatch());
assertNull(persistedSecuritySetting.getBrowseRoles());
assertNull(persistedSecuritySetting.getConsumeRoles());
assertNull(persistedSecuritySetting.getCreateAddressRoles());
assertNull(persistedSecuritySetting.getCreateDurableQueueRoles());
assertNull(persistedSecuritySetting.getCreateNonDurableQueueRoles());
assertNull(persistedSecuritySetting.getDeleteAddressRoles());
assertNull(persistedSecuritySetting.getDeleteDurableQueueRoles());
assertNull(persistedSecuritySetting.getDeleteNonDurableQueueRoles());
assertNull(persistedSecuritySetting.getManageRoles());
assertNull(persistedSecuritySetting.getSendRoles());
assertNull(persistedSecuritySetting.getViewRoles());
assertNull(persistedSecuritySetting.getEditRoles());
}
}