use of com.quorum.tessera.config.ResidentGroup in project tessera by ConsenSys.
the class ResidentGroupHandlerImplTest method keyGetsAddedToAnExistingGroup.
@Test
public void keyGetsAddedToAnExistingGroup() {
ResidentGroup rg1 = new ResidentGroup();
rg1.setMembers(List.of(PublicKey.from("m1".getBytes()).encodeToBase64(), PublicKey.from("m2".getBytes()).encodeToBase64()));
rg1.setName("rg1");
Config config = mock(Config.class);
when(config.getResidentGroups()).thenReturn(List.of(rg1));
when(privacyGroupManager.getManagedKeys()).thenReturn(Set.of(PublicKey.from("m1".getBytes()), PublicKey.from("m2".getBytes())));
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));
residentGroupHandler.onCreate(config);
verify(privacyGroupManager).findPrivacyGroupByType(eq(PrivacyGroup.Type.RESIDENT));
verify(privacyGroupManager).getManagedKeys();
verify(privacyGroupManager).saveResidentGroup(eq("rg1"), any(), memberCaptor.capture());
assertThat(memberCaptor.getValue()).containsExactlyInAnyOrder(PublicKey.from("m1".getBytes()), PublicKey.from("m2".getBytes()));
}
use of com.quorum.tessera.config.ResidentGroup in project tessera by ConsenSys.
the class ResidentGroupHandlerImplTest method homelessKeysNotAllowed.
@Test
public void homelessKeysNotAllowed() {
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()), PublicKey.from("m3".getBytes())));
Config config = mock(Config.class);
when(config.getResidentGroups()).thenReturn(List.of(rg1, rg2));
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 residentGroupCanNotHaveRemoteKey.
@Test
public void residentGroupCanNotHaveRemoteKey() {
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");
Config config = mock(Config.class);
when(config.getResidentGroups()).thenReturn(List.of(rg1));
when(privacyGroupManager.getManagedKeys()).thenReturn(Set.of(PublicKey.from("m2".getBytes())));
assertThatThrownBy(() -> residentGroupHandler.onCreate(config)).isInstanceOf(PrivacyViolationException.class).hasMessageContaining("Key PublicKey[bTE=] configured in resident groups must be locally managed");
verify(privacyGroupManager).getManagedKeys();
}
Aggregations