Search in sources :

Example 6 with ResidentGroup

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()));
}
Also used : ResidentGroup(com.quorum.tessera.config.ResidentGroup) Config(com.quorum.tessera.config.Config) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) Test(org.junit.Test)

Example 7 with ResidentGroup

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();
}
Also used : ResidentGroup(com.quorum.tessera.config.ResidentGroup) Config(com.quorum.tessera.config.Config) PrivacyViolationException(com.quorum.tessera.transaction.exception.PrivacyViolationException) Test(org.junit.Test)

Example 8 with ResidentGroup

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();
}
Also used : ResidentGroup(com.quorum.tessera.config.ResidentGroup) Config(com.quorum.tessera.config.Config) PrivacyViolationException(com.quorum.tessera.transaction.exception.PrivacyViolationException) Test(org.junit.Test)

Aggregations

Config (com.quorum.tessera.config.Config)8 ResidentGroup (com.quorum.tessera.config.ResidentGroup)8 Test (org.junit.Test)8 PrivacyViolationException (com.quorum.tessera.transaction.exception.PrivacyViolationException)5 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)4