use of com.quorum.tessera.config.ResidentGroup in project tessera by ConsenSys.
the class ResidentGroupHandlerImplTest method keyExistedInADifferentGroupInDb.
@Test
public void keyExistedInADifferentGroupInDb() {
ResidentGroup rg1 = new ResidentGroup();
rg1.setMembers(List.of(PublicKey.from("m1".getBytes()).encodeToBase64()));
rg1.setName("rg1");
ResidentGroup rg2 = new ResidentGroup();
rg2.setMembers(List.of(PublicKey.from("m2".getBytes()).encodeToBase64()));
rg2.setName("rg2");
when(privacyGroupManager.getManagedKeys()).thenReturn(Set.of(PublicKey.from("m1".getBytes()), PublicKey.from("m2".getBytes())));
Config config = mock(Config.class);
when(config.getResidentGroups()).thenReturn(List.of(rg1, rg2));
final PrivacyGroup existedGroup = mock(PrivacyGroup.class);
when(existedGroup.getMembers()).thenReturn(List.of(PublicKey.from("m2".getBytes())));
when(existedGroup.getId()).thenReturn(PrivacyGroup.Id.fromBytes("otherGroup".getBytes()));
when(privacyGroupManager.findPrivacyGroupByType(eq(PrivacyGroup.Type.RESIDENT))).thenReturn(List.of(existedGroup));
assertThatThrownBy(() -> residentGroupHandler.onCreate(config)).isInstanceOf(PrivacyViolationException.class).hasMessageContaining("Key cannot belong to more than one resident group");
verify(privacyGroupManager).findPrivacyGroupByType(eq(PrivacyGroup.Type.RESIDENT));
verify(privacyGroupManager).getManagedKeys();
}
use of com.quorum.tessera.config.ResidentGroup in project tessera by ConsenSys.
the class ResidentGroupHandlerImplTest method keysCanNotBeMovedOutOfAGroup.
@Test
public void keysCanNotBeMovedOutOfAGroup() {
final PrivacyGroup existedGroup = mock(PrivacyGroup.class);
when(existedGroup.getMembers()).thenReturn(List.of(PublicKey.from("m1".getBytes())));
when(existedGroup.getId()).thenReturn(PrivacyGroup.Id.fromBytes("rg1".getBytes()));
when(privacyGroupManager.findPrivacyGroupByType(eq(PrivacyGroup.Type.RESIDENT))).thenReturn(List.of(existedGroup));
ResidentGroup rg2 = new ResidentGroup();
rg2.setMembers(List.of(PublicKey.from("m1".getBytes()).encodeToBase64(), PublicKey.from("m2".getBytes()).encodeToBase64()));
rg2.setName("rg2");
Config config = mock(Config.class);
when(config.getResidentGroups()).thenReturn(List.of(rg2));
when(privacyGroupManager.getManagedKeys()).thenReturn(Set.of(PublicKey.from("m1".getBytes()), PublicKey.from("m2".getBytes())));
assertThatThrownBy(() -> residentGroupHandler.onCreate(config)).isInstanceOf(PrivacyViolationException.class).hasMessageContaining("Key cannot belong to more than one resident group");
verify(privacyGroupManager).findPrivacyGroupByType(eq(PrivacyGroup.Type.RESIDENT));
verify(privacyGroupManager).getManagedKeys();
}
use of com.quorum.tessera.config.ResidentGroup in project tessera by ConsenSys.
the class ResidentGroupHandlerImplTest method homelessKeysNotAllowedConsideringBothConfigAndDb.
@Test
public void homelessKeysNotAllowedConsideringBothConfigAndDb() {
ResidentGroup rg1 = new ResidentGroup();
rg1.setMembers(List.of(PublicKey.from("m1".getBytes()).encodeToBase64()));
rg1.setName("rg1");
when(privacyGroupManager.getManagedKeys()).thenReturn(Set.of(PublicKey.from("m1".getBytes()), PublicKey.from("m2".getBytes()), PublicKey.from("m3".getBytes())));
Config config = mock(Config.class);
when(config.getResidentGroups()).thenReturn(List.of(rg1));
final PrivacyGroup pg = PrivacyGroup.Builder.buildResidentGroup("private", "", List.of(PublicKey.from("m2".getBytes())));
when(privacyGroupManager.findPrivacyGroupByType(eq(PrivacyGroup.Type.RESIDENT))).thenReturn(List.of(pg));
assertThatThrownBy(() -> residentGroupHandler.onCreate(config)).isInstanceOf(PrivacyViolationException.class).hasMessageContaining("PublicKey[bTM=] must belong to a resident group");
verify(privacyGroupManager).findPrivacyGroupByType(eq(PrivacyGroup.Type.RESIDENT));
verify(privacyGroupManager).getManagedKeys();
}
use of com.quorum.tessera.config.ResidentGroup in project tessera by ConsenSys.
the class ResidentGroupHandlerImplTest method createNewGroups.
@Test
public void createNewGroups() {
ResidentGroup rg1 = new ResidentGroup();
rg1.setMembers(List.of(PublicKey.from("m1".getBytes()).encodeToBase64()));
rg1.setName("rg1");
ResidentGroup rg2 = new ResidentGroup();
rg2.setMembers(List.of(PublicKey.from("m2".getBytes()).encodeToBase64()));
rg2.setName("rg2");
ResidentGroup rg3 = new ResidentGroup();
rg3.setMembers(List.of(PublicKey.from("m3".getBytes()).encodeToBase64()));
rg3.setName("rg3");
when(privacyGroupManager.getManagedKeys()).thenReturn(Set.of(PublicKey.from("m1".getBytes()), PublicKey.from("m2".getBytes()), PublicKey.from("m3".getBytes())));
Config config = mock(Config.class);
when(config.getResidentGroups()).thenReturn(List.of(rg1, rg2, rg3));
residentGroupHandler.onCreate(config);
verify(privacyGroupManager).findPrivacyGroupByType(eq(PrivacyGroup.Type.RESIDENT));
verify(privacyGroupManager).getManagedKeys();
verify(privacyGroupManager, times(3)).saveResidentGroup(anyString(), any(), any());
}
use of com.quorum.tessera.config.ResidentGroup in project tessera by ConsenSys.
the class ResidentGroupHandlerImplTest method keysCanNotExistInTwoDifferentGroups.
@Test
public void keysCanNotExistInTwoDifferentGroups() {
ResidentGroup rg1 = new ResidentGroup();
rg1.setMembers(List.of(PublicKey.from("m1".getBytes()).encodeToBase64()));
rg1.setName("rg1");
ResidentGroup rg2 = new ResidentGroup();
rg2.setMembers(List.of(PublicKey.from("m1".getBytes()).encodeToBase64()));
rg2.setName("rg2");
when(privacyGroupManager.getManagedKeys()).thenReturn(Set.of(PublicKey.from("m1".getBytes()), PublicKey.from("m2".getBytes())));
Config config = mock(Config.class);
when(config.getResidentGroups()).thenReturn(List.of(rg1, rg2));
assertThatThrownBy(() -> residentGroupHandler.onCreate(config)).isInstanceOf(PrivacyViolationException.class).hasMessageContaining("Key cannot belong to more than one resident group").hasMessageContaining("PublicKey[bTE=]");
verify(privacyGroupManager).findPrivacyGroupByType(eq(PrivacyGroup.Type.RESIDENT));
verify(privacyGroupManager).getManagedKeys();
}
Aggregations