CredentialsMessageFilter { public static boolean verify(final ResourceIdentifier linkTarget, final Message msg) { if (msg.getMessageId() == null && msg.getCorrelationId() == null) { LOG.trace("message has neither a message-id nor correlation-id"); return false; } else if (!CredentialsConstants.CredentialsAction.isValid(msg.getSubject())) { LOG.trace("message [{}] does not contain valid subject property", msg.getMessageId()); return false; } else if (msg.getReplyTo() == null) { LOG.trace("message [{}] has no reply-to address set", msg.getMessageId()); return false; } else if (!MessageHelper.hasDataBody(msg)) { LOG.trace("message [{}] contains no Data section payload", msg.getMessageId()); return false; } else { return true; } } private  CredentialsMessageFilter(); static boolean verify(final ResourceIdentifier linkTarget, final Message msg);  }
@Test public void testVerifyFailsForMissingBody() { final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.get); final boolean filterResult = CredentialsMessageFilter.verify(target, msg); assertFalse(filterResult); }
@Test public void testVerifyFailsForNonDataSectionBody() { final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.get); msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD.encode())); msg.setContentType("application/json"); final boolean filterResult = CredentialsMessageFilter.verify(target, msg); assertFalse(filterResult); }
@Test public void testVerifyFailsForMissingCorrelationId() { final Message msg = ProtonHelper.message(); msg.setReplyTo("reply"); msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD)); msg.setContentType("application/json"); final boolean filterResult = CredentialsMessageFilter.verify(target, msg); assertFalse(filterResult); }
@Test public void testVerifyFailsForUnknownAction() { final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.unknown); msg.setBody(new AmqpValue(BILLIE_HASHED_PASSWORD)); msg.setContentType("application/json"); final boolean filterResult = CredentialsMessageFilter.verify(target, msg); assertFalse(filterResult); }
@Test public void testVerifySucceedsForValidGetAction() { final Message msg = givenAValidMessageWithoutBody(CredentialsConstants.CredentialsAction.get); msg.setBody(new Data(new Binary(BILLIE_HASHED_PASSWORD.toBuffer().getBytes()))); msg.setContentType("application/json"); final boolean filterResult = CredentialsMessageFilter.verify(target, msg); assertTrue(filterResult); }