### Question:
DefaultVerifier implements Verifier { public boolean verify(Challenge challenge, RequestContent requestContent, Authorization authorization) { return verifyWithResult(challenge, requestContent, authorization) == VerifyResult.SUCCESS; } DefaultVerifier(Keychain keychain);   DefaultVerifier(Keychain keychain, boolean strictRequestTarget);  DefaultVerifier(Keychain keychain, KeyId keyId);  DefaultVerifier(Keychain keychain, KeyId keyId, long skew); private  DefaultVerifier(Keychain keychain, KeyId keyId, long skew, boolean strictRequestTarget); Keychain getKeychain(); long getSkew(); void setSkew(long skew); Key selectKey(Authorization authorization); boolean verify(Challenge challenge, RequestContent requestContent, Authorization authorization); VerifyResult verifyWithResult(Challenge challenge, RequestContent requestContent, Authorization authorization); static final long DEFAULT_SKEW; }### Answer:
@Test public void testVerify() { TestBody.test(new TestBody() { @Override protected void execute() throws Exception { String fingerprint = "fingerprint"; Keychain identities = new MockKeychain(fingerprint); DefaultVerifier v = new DefaultVerifier(identities); RequestContent requestContent = new RequestContent.Builder().addDateNow().build(); Challenge c = new Challenge(DefaultVerifierTest.class.getName(), Constants.DEFAULT_HEADERS, Arrays.asList( Algorithm.SSH_RSA )); byte[] content = requestContent.getContent(Constants.DEFAULT_HEADERS, Constants.CHARSET); Authorization a = new Authorization(fingerprint, MockKey.mockSignBase64(content), Constants.DEFAULT_HEADERS, Algorithm.SSH_RSA); assertTrue("default verifier should verify mock signature ", v.verify(c, requestContent, a)); } }); }
@Test public void testStrictVerify() { TestBody.test(new TestBody() { @Override protected void execute() throws Exception { String fingerprint = "fingerprint"; Keychain identities = new MockKeychain(fingerprint); DefaultVerifier v = new DefaultVerifier(identities); DefaultVerifier strictV = new DefaultVerifier(identities, true); RequestContent requestContent = new RequestContent.Builder().setRequestTarget("get", "index.html").addDateNow().build(); List<String> headers = Arrays.asList(Constants.HEADER_REQUEST_TARGET, Constants.HEADER_DATE); Challenge c = new Challenge(DefaultVerifierTest.class.getName(), headers, Arrays.asList( Algorithm.SSH_RSA )); byte[] content = requestContent.getContent(headers, Constants.CHARSET); byte[] strictContent = requestContent.getBytesToSign(headers, Constants.CHARSET); Authorization authz = new Authorization(fingerprint, MockKey.mockSignBase64(content), headers, Algorithm.SSH_RSA); Authorization strictAuthz = new Authorization(fingerprint, MockKey.mockSignBase64(strictContent), headers, Algorithm.SSH_RSA); assertTrue("default verifier should verify default mock signature ", v.verify(c, requestContent, authz)); assertTrue("default verifier should verify strict mock signature ", v.verify(c, requestContent, strictAuthz)); assertTrue("strict verifier should verify strict mock signature ", strictV.verify(c, requestContent, strictAuthz)); assertFalse("strict verifier should not verify default mock signature ", strictV.verify(c, requestContent, authz)); } }); }