Search in sources :

Example 1 with ResidentGroup

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

Example 2 with ResidentGroup

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

Example 3 with ResidentGroup

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

Example 4 with ResidentGroup

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

Example 5 with ResidentGroup

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