Search in sources :

Example 6 with FossologyHostFingerPrint

use of org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint in project sw360portal by sw360.

the class FossologyHostKeyRepositoryTest method testCheckAValidNewKeyIsSavedAsUntrusted.

@Test
public void testCheckAValidNewKeyIsSavedAsUntrusted() throws Exception {
    when(connector.getAll()).thenReturn(Collections.<FossologyHostFingerPrint>emptyList());
    String host = "host";
    byte[] key = GOOD_KEY.getBytes();
    final String expectedFingerPrint = new HostKey(host, key).getFingerPrint(jSch);
    assertThat(expectedFingerPrint, not(isEmptyOrNullString()));
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            FossologyHostFingerPrint fingerPrint = (FossologyHostFingerPrint) invocation.getArguments()[0];
            assertThat(fingerPrint.getFingerPrint(), is(expectedFingerPrint));
            assertFalse(fingerPrint.isTrusted());
            return null;
        }
    }).when(connector).add(any(FossologyHostFingerPrint.class));
    assertThat(repo.check(host, key), is(HostKeyRepository.NOT_INCLUDED));
    verify(connector).getAll();
    verify(connector).add(any(FossologyHostFingerPrint.class));
}
Also used : Answer(org.mockito.stubbing.Answer) HostKey(com.jcraft.jsch.HostKey) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) FossologyHostFingerPrint(org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint) Test(org.junit.Test)

Example 7 with FossologyHostFingerPrint

use of org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint in project sw360portal by sw360.

the class FossologyHostKeyRepositoryTest method testCheckAValidKnownUntrustedKeyIsNotTrusted.

@Test
public void testCheckAValidKnownUntrustedKeyIsNotTrusted() throws Exception {
    String host = "host";
    byte[] key = GOOD_KEY.getBytes();
    final String expectedFingerPrint = new HostKey(host, key).getFingerPrint(jSch);
    assertThat(expectedFingerPrint, not(isEmptyOrNullString()));
    when(connector.getAll()).thenReturn(ImmutableList.of(new FossologyHostFingerPrint().setFingerPrint(expectedFingerPrint).setTrusted(false)));
    assertThat(repo.check(host, key), is(HostKeyRepository.NOT_INCLUDED));
    verify(connector).getAll();
    verify(connector, never()).add(any(FossologyHostFingerPrint.class));
}
Also used : HostKey(com.jcraft.jsch.HostKey) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) FossologyHostFingerPrint(org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint) Test(org.junit.Test)

Aggregations

FossologyHostFingerPrint (org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint)7 HostKey (com.jcraft.jsch.HostKey)4 Test (org.junit.Test)4 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 TException (org.apache.thrift.TException)1 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)1 FossologyService (org.eclipse.sw360.datahandler.thrift.fossology.FossologyService)1 FossologyFingerPrintRepository (org.eclipse.sw360.fossology.db.FossologyFingerPrintRepository)1 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)1 Answer (org.mockito.stubbing.Answer)1