Search in sources :

Example 21 with PrivacyGroup

use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.

the class PrivacyGroupManagerImplTest method testLegacyPrivacyGroupExisted.

@Test
public void testLegacyPrivacyGroupExisted() {
    final List<PublicKey> members = List.of(localKey, mock(PublicKey.class), mock(PublicKey.class));
    when(privacyGroupUtil.generateId(anyList())).thenReturn("generatedId".getBytes());
    when(privacyGroupDAO.retrieve("generatedId".getBytes())).thenReturn(Optional.of(mock(PrivacyGroupEntity.class)));
    final PrivacyGroup privacyGroup = privacyGroupManager.createLegacyPrivacyGroup(localKey, members);
    assertThat(privacyGroup).isNotNull();
    verify(privacyGroupDAO).retrieveOrSave(any());
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) Test(org.junit.Test)

Example 22 with PrivacyGroup

use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.

the class PrivacyGroupManagerImplTest method testStorePrivacyGroup.

@Test
public void testStorePrivacyGroup() {
    final PrivacyGroup mockPrivacyGroup = mock(PrivacyGroup.class);
    when(mockPrivacyGroup.getId()).thenReturn(PrivacyGroup.Id.fromBytes("id".getBytes()));
    final byte[] encoded = "encoded".getBytes();
    when(privacyGroupUtil.decode(encoded)).thenReturn(mockPrivacyGroup);
    when(privacyGroupUtil.generateLookupId(anyList())).thenReturn("lookup".getBytes());
    when(privacyGroupDAO.retrieve("id".getBytes())).thenReturn(Optional.empty());
    privacyGroupManager.storePrivacyGroup(encoded);
    ArgumentCaptor<PrivacyGroupEntity> argCaptor = ArgumentCaptor.forClass(PrivacyGroupEntity.class);
    verify(privacyGroupDAO).save(argCaptor.capture());
    final PrivacyGroupEntity saved = argCaptor.getValue();
    assertThat(saved).isNotNull();
    assertThat(saved.getId()).isEqualTo("id".getBytes());
    assertThat(saved.getLookupId()).isEqualTo("lookup".getBytes());
    assertThat(saved.getData()).isEqualTo("encoded".getBytes());
}
Also used : PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) Test(org.junit.Test)

Example 23 with PrivacyGroup

use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.

the class PrivacyGroupManagerImplTest method findPrivacyGroupByType.

@Test
public void findPrivacyGroupByType() {
    final PrivacyGroupEntity mockResult1 = mock(PrivacyGroupEntity.class);
    final PrivacyGroup mockPrivacyGroup1 = mock(PrivacyGroup.class);
    when(mockPrivacyGroup1.getState()).thenReturn(PrivacyGroup.State.ACTIVE);
    when(mockPrivacyGroup1.getType()).thenReturn(PrivacyGroup.Type.RESIDENT);
    when(mockResult1.getData()).thenReturn("data1".getBytes());
    final PrivacyGroupEntity mockResult2 = mock(PrivacyGroupEntity.class);
    final PrivacyGroup mockPrivacyGroup2 = mock(PrivacyGroup.class);
    when(mockPrivacyGroup2.getState()).thenReturn(PrivacyGroup.State.DELETED);
    when(mockPrivacyGroup2.getType()).thenReturn(PrivacyGroup.Type.RESIDENT);
    when(mockResult2.getData()).thenReturn("data2".getBytes());
    final PrivacyGroupEntity mockResult3 = mock(PrivacyGroupEntity.class);
    final PrivacyGroup mockPrivacyGroup3 = mock(PrivacyGroup.class);
    when(mockPrivacyGroup3.getState()).thenReturn(PrivacyGroup.State.ACTIVE);
    when(mockPrivacyGroup3.getType()).thenReturn(PrivacyGroup.Type.PANTHEON);
    when(mockResult3.getData()).thenReturn("data3".getBytes());
    when(privacyGroupUtil.decode("data1".getBytes())).thenReturn(mockPrivacyGroup1);
    when(privacyGroupUtil.decode("data2".getBytes())).thenReturn(mockPrivacyGroup2);
    when(privacyGroupUtil.decode("data3".getBytes())).thenReturn(mockPrivacyGroup3);
    when(privacyGroupDAO.findAll()).thenReturn(List.of(mockResult1, mockResult2, mockResult3));
    final List<PrivacyGroup> result = privacyGroupManager.findPrivacyGroupByType(PrivacyGroup.Type.RESIDENT);
    assertThat(result).isNotNull();
    assertThat(result).containsExactly(mockPrivacyGroup1);
    verify(privacyGroupDAO).findAll();
}
Also used : PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) Test(org.junit.Test)

Example 24 with PrivacyGroup

use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.

the class PrivacyGroupManagerImplTest method testDeletePrivacyGroup.

@Test
public void testDeletePrivacyGroup() {
    PublicKey from = PublicKey.from("r1".getBytes());
    PrivacyGroupEntity retrievedEt = mock(PrivacyGroupEntity.class);
    when(retrievedEt.getData()).thenReturn("data".getBytes());
    PrivacyGroup mockPG = mock(PrivacyGroup.class);
    when(mockPG.getId()).thenReturn(PrivacyGroup.Id.fromBytes("id".getBytes()));
    when(mockPG.getMembers()).thenReturn(List.of(PublicKey.from("r1".getBytes()), PublicKey.from("r2".getBytes())));
    when(mockPG.getState()).thenReturn(PrivacyGroup.State.ACTIVE);
    when(mockPG.getType()).thenReturn(PrivacyGroup.Type.PANTHEON);
    when(privacyGroupDAO.retrieve("id".getBytes())).thenReturn(Optional.of(retrievedEt));
    when(privacyGroupUtil.decode("data".getBytes())).thenReturn(mockPG);
    when(privacyGroupUtil.encode(any())).thenReturn("deletedData".getBytes());
    when(privacyGroupUtil.generateLookupId(any())).thenReturn("lookup".getBytes());
    doAnswer(invocation -> {
        Callable callable = invocation.getArgument(1);
        callable.call();
        return mock(PrivacyGroupEntity.class);
    }).when(privacyGroupDAO).update(any(), any());
    PrivacyGroup result = privacyGroupManager.deletePrivacyGroup(from, PrivacyGroup.Id.fromBytes("id".getBytes()));
    assertThat(result.getState()).isEqualTo(PrivacyGroup.State.DELETED);
    verify(privacyGroupDAO).retrieve("id".getBytes());
    verify(privacyGroupDAO).update(any(), any());
    // Verify payload being distributed has the correct values
    ArgumentCaptor<byte[]> payloadCaptor = ArgumentCaptor.forClass(byte[].class);
    ArgumentCaptor<List<PublicKey>> recipientsCaptor = ArgumentCaptor.forClass(List.class);
    verify(publisher).publishPrivacyGroup(payloadCaptor.capture(), recipientsCaptor.capture());
    assertThat(payloadCaptor.getValue()).isEqualTo("deletedData".getBytes());
    assertThat(recipientsCaptor.getValue()).containsAll(List.of(PublicKey.from("r1".getBytes()), PublicKey.from("r2".getBytes())));
    ArgumentCaptor<PrivacyGroup> argCaptor = ArgumentCaptor.forClass(PrivacyGroup.class);
    verify(privacyGroupUtil).encode(argCaptor.capture());
    PrivacyGroup deletedPg = argCaptor.getValue();
    assertThat(deletedPg.getId()).isEqualTo(PrivacyGroup.Id.fromBytes("id".getBytes()));
    assertThat(deletedPg.getState()).isEqualTo(PrivacyGroup.State.DELETED);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity) List(java.util.List) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 25 with PrivacyGroup

use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.

the class PrivacyGroupManagerImplTest method testRetrievePrivacyGroup.

@Test
public void testRetrievePrivacyGroup() {
    final PrivacyGroup.Id id = PrivacyGroup.Id.fromBytes("id".getBytes());
    final PrivacyGroupEntity mockResult = mock(PrivacyGroupEntity.class);
    final PrivacyGroup mockPrivacyGroup = mock(PrivacyGroup.class);
    when(mockPrivacyGroup.getState()).thenReturn(PrivacyGroup.State.ACTIVE);
    when(mockResult.getData()).thenReturn("data".getBytes());
    when(privacyGroupUtil.decode("data".getBytes())).thenReturn(mockPrivacyGroup);
    when(privacyGroupDAO.retrieve("id".getBytes())).thenReturn(Optional.of(mockResult));
    final PrivacyGroup result = privacyGroupManager.retrievePrivacyGroup(id);
    assertThat(result).isNotNull();
    assertThat(result).isEqualTo(mockPrivacyGroup);
    verify(privacyGroupDAO).retrieve("id".getBytes());
}
Also used : PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) Test(org.junit.Test)

Aggregations

PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)36 Test (org.junit.Test)22 PublicKey (com.quorum.tessera.encryption.PublicKey)21 PrivacyGroupEntity (com.quorum.tessera.data.PrivacyGroupEntity)17 MessageHash (com.quorum.tessera.data.MessageHash)8 Response (jakarta.ws.rs.core.Response)8 PrivacyViolationException (com.quorum.tessera.transaction.exception.PrivacyViolationException)7 Operation (io.swagger.v3.oas.annotations.Operation)7 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)7 SendResponse (com.quorum.tessera.api.SendResponse)6 Config (com.quorum.tessera.config.Config)6 SendRequest (com.quorum.tessera.api.SendRequest)5 ResidentGroup (com.quorum.tessera.config.ResidentGroup)5 PrivacyGroupManager (com.quorum.tessera.privacygroup.PrivacyGroupManager)5 java.util (java.util)5 Collectors (java.util.stream.Collectors)5 Stream (java.util.stream.Stream)5 PrivacyValid (com.quorum.tessera.api.constraint.PrivacyValid)4 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)4 TransactionManager (com.quorum.tessera.transaction.TransactionManager)4