FossologyHostKeyRepository implements HostKeyRepository { @Override public int check(String host, byte[] key) { String fingerPrint; try { fingerPrint = new HostKey(host, key).getFingerPrint(J_SHC); for (FossologyHostFingerPrint savedFingerPrint : hostKeyDb.getAll()) { if (fingerPrint.equals(savedFingerPrint.getFingerPrint())) { if (savedFingerPrint.isTrusted()) { return OK; } else { log.error("attempting connection to untrusted Host"); return NOT_INCLUDED; } } } } catch (Exception e) { log.error(format("exception while verifying host '%s'", host), e); return NOT_INCLUDED; } log.error(format("cannot verify host '%s', fingerprint = '%s'", host, fingerPrint)); final FossologyHostFingerPrint newFossologyHostFingerPrint = new FossologyHostFingerPrint().setFingerPrint(fingerPrint).setTrusted(false); hostKeyDb.add(newFossologyHostFingerPrint); return NOT_INCLUDED; } @Autowired  FossologyHostKeyRepository(FossologyFingerPrintRepository fossologyFingerPrintRepository); @Override int check(String host, byte[] key); @Override void add(HostKey hostkey, UserInfo ui); @Override void remove(String host, String type); @Override void remove(String host, String type, byte[] key); @Override String getKnownHostsRepositoryID(); @Override HostKey[] getHostKey(); @Override HostKey[] getHostKey(String host, String type);  }
@Test public void testCheckNullIsNotAValidKey() throws Exception { assertThat(repo.check("host", null), is(HostKeyRepository.NOT_INCLUDED)); }
@Test public void testCheckAnEmptyKeyIsInvalid() throws Exception { byte[] key = "".getBytes(); assertThat(repo.check("host", key), is(HostKeyRepository.NOT_INCLUDED)); }
@Test public void testCheckAnInvalidKey() throws Exception { byte[] key = "cfsdcvdf".getBytes(); assertThat(repo.check("host", key), is(HostKeyRepository.NOT_INCLUDED)); }