JmsDestinationLinker implements EntityLinker<JmsDestination> { @Override public void link(JmsDestination entity, Bundle bundle, Bundle targetBundle) { linkJndiStoredPassword(entity, bundle); linkDestinationStoredPassword(entity, bundle); linkInboundAssociatedService(entity, bundle); verifyPrivateKeys(entity, bundle); }  @Override Class<JmsDestination> getEntityClass(); @Override void link(JmsDestination entity, Bundle bundle, Bundle targetBundle);  }
@Test void testLinkStorePassword() { Bundle bundle = new Bundle(); bundle.addEntity(createStoredPassword(JNDI_STORED_PASSWORD_NAME)); bundle.addEntity(createStoredPassword(DESTINATION_STORED_PASSWORD_NAME)); final JmsDestination jmsDestination = createJmsDestination( String.format(PASSWORD_REF_FORMAT, JNDI_STORED_PASSWORD_NAME), String.format(PASSWORD_REF_FORMAT, DESTINATION_STORED_PASSWORD_NAME)); linker.link(jmsDestination, bundle, bundle); assertEquals(JNDI_STORED_PASSWORD_NAME, jmsDestination.getJndiPasswordRef()); assertNull(jmsDestination.getJndiPassword()); assertEquals(DESTINATION_STORED_PASSWORD_NAME, jmsDestination.getDestinationPasswordRef()); assertNull(jmsDestination.getDestinationPassword()); }
@Test void testLinkPasswordPlainText() { final String jndiPassword = "jndi-plaintextpassword"; final String destinationPassword = "destination-plaintextpassword"; final JmsDestination jmsDestination = createJmsDestination(jndiPassword, destinationPassword); linker.link(jmsDestination, new Bundle(), new Bundle()); assertEquals(jndiPassword, jmsDestination.getJndiPassword()); assertNull(jmsDestination.getJndiPasswordRef()); assertEquals(destinationPassword, jmsDestination.getDestinationPassword()); assertNull(jmsDestination.getDestinationPasswordRef()); }
@Test void testLinkPasswordL7C2VariableFormat() { final String jndiPassword = "$L7C2$1,3ok3RLhLqpD3Z3QdyTpoa2iHU2dRYdAF3TgSchF2ttI=$2EqC+niJG4yw7LOJ52Rur0VcGccT/r1WpHE+4Aiqj5GcNNYXub9h7pO5CrGT7eFGhyub2ilKx5M+ULQtbU5ZTcGxgj4K+H0+y9Yq5LNbKggoHYa+3T8r9pIcUamcCx7q\""; final String destinationPassword = "$L7C2$1,3ok3RLhLqpD3Z3QdyTpoa2iHU2dRYdAF3TgSchF2ttI=$2EqC+niJG4yw7LOJ52Rur0VcGccT/r1WpHE+4Aiqj5GcNNYXub9h7pO5CrGT7eFGhyub2ilKx5M+ULQtbU5ZTcGxgj4K+H0+y9Yq5LNbKggoHYa+3T8r9pIcUamcCx7q\""; final JmsDestination jmsDestination = createJmsDestination(jndiPassword, destinationPassword); linker.link(jmsDestination, new Bundle(), new Bundle()); assertNull(jmsDestination.getJndiPasswordRef()); assertNull(jmsDestination.getJndiPassword()); assertNull(jmsDestination.getDestinationPasswordRef()); assertNull(jmsDestination.getDestinationPassword()); }
@Test void testLinkMissingJndiStoredPassword() { Bundle bundle = new Bundle(); bundle.addEntity(createStoredPassword(DESTINATION_STORED_PASSWORD_NAME)); final JmsDestination jmsDestination = createJmsDestination( String.format(PASSWORD_REF_FORMAT, JNDI_STORED_PASSWORD_NAME), String.format(PASSWORD_REF_FORMAT, DESTINATION_STORED_PASSWORD_NAME)); assertThrows(LinkerException.class, () -> linker.link(jmsDestination, new Bundle(), new Bundle())); }
@Test void testLinkMissingDestinationStoredPassword() { Bundle bundle = new Bundle(); bundle.addEntity(createStoredPassword(JNDI_STORED_PASSWORD_NAME)); final JmsDestination jmsDestination = createJmsDestination( String.format(PASSWORD_REF_FORMAT, JNDI_STORED_PASSWORD_NAME), String.format(PASSWORD_REF_FORMAT, DESTINATION_STORED_PASSWORD_NAME)); assertThrows(LinkerException.class, () -> linker.link(jmsDestination, new Bundle(), new Bundle())); }
@Test void testLinkNoJndiStoredPassword() { Bundle bundle = new Bundle(); bundle.addEntity(createStoredPassword(DESTINATION_STORED_PASSWORD_NAME)); final JmsDestination jmsDestination = createJmsDestination( null, String.format(PASSWORD_REF_FORMAT, DESTINATION_STORED_PASSWORD_NAME) ); linker.link(jmsDestination, bundle, bundle); assertNull(jmsDestination.getJndiPasswordRef()); assertNull(jmsDestination.getJndiPassword()); assertEquals(DESTINATION_STORED_PASSWORD_NAME, jmsDestination.getDestinationPasswordRef()); assertNull(jmsDestination.getDestinationPassword()); }
@Test void testLinkNoDestinationStoredPassword() { Bundle bundle = new Bundle(); bundle.addEntity(createStoredPassword(JNDI_STORED_PASSWORD_NAME)); final JmsDestination jmsDestination = createJmsDestination( String.format(PASSWORD_REF_FORMAT, JNDI_STORED_PASSWORD_NAME), null); linker.link(jmsDestination, bundle, bundle); assertEquals(JNDI_STORED_PASSWORD_NAME, jmsDestination.getJndiPasswordRef()); assertNull(jmsDestination.getJndiPassword()); assertNull(jmsDestination.getDestinationPasswordRef()); assertNull(jmsDestination.getDestinationPassword()); }
@Test void testLinkNoDestinationAndJndiStoredPasswords() { Bundle bundle = new Bundle(); final JmsDestination jmsDestination = createJmsDestination( null, null); linker.link(jmsDestination, bundle, bundle); assertNull(jmsDestination.getJndiPasswordRef()); assertNull(jmsDestination.getJndiPassword()); assertNull(jmsDestination.getDestinationPasswordRef()); assertNull(jmsDestination.getDestinationPassword()); }
@Test void testLinkMissingInboundAssociatedService() { Bundle bundle = new Bundle(); final ServiceResolutionSettings serviceResolutionSettings = new ServiceResolutionSettings(); serviceResolutionSettings.setServiceRef("associated-service-id"); final InboundJmsDestinationDetail inboundDetail = new InboundJmsDestinationDetail(); inboundDetail.setAcknowledgeType(ON_TAKE); inboundDetail.setReplyType(NO_REPLY); inboundDetail.setUseRequestCorrelationId(false); inboundDetail.setServiceResolutionSettings(serviceResolutionSettings); final JmsDestination jmsDestination = createJmsDestinationBuilder(null,null) .inboundDetail(inboundDetail) .build(); assertThrows(LinkerException.class, () -> linker.link(jmsDestination, bundle, bundle)); }
@Test void testLinkNoInboundAssociatedService() { Bundle bundle = new Bundle(); final ServiceResolutionSettings serviceResolutionSettings = new ServiceResolutionSettings(); final InboundJmsDestinationDetail inboundDetail = new InboundJmsDestinationDetail(); inboundDetail.setAcknowledgeType(ON_TAKE); inboundDetail.setReplyType(NO_REPLY); inboundDetail.setUseRequestCorrelationId(false); inboundDetail.setServiceResolutionSettings(serviceResolutionSettings); final JmsDestination jmsDestination = createJmsDestinationBuilder(null,null) .inboundDetail(inboundDetail) .build(); linker.link(jmsDestination, bundle, bundle); assertNotNull(jmsDestination.getInboundDetail()); assertNotNull(jmsDestination.getInboundDetail().getServiceResolutionSettings()); assertNull(jmsDestination.getInboundDetail().getServiceResolutionSettings().getServiceRef()); }
@Test void testLinkJndiClientAuthPrivateKey() { Bundle bundle = new Bundle(); bundle.addEntity(createPrivateKey("key1")); final JmsDestination jmsDestination = createJmsDestinationBuilder(null, null) .additionalProperties(new HashMap<String, Object>() {{ put(JNDI_CLIENT_AUT_KEYSTORE_ALIAS, "key1"); }}) .build(); linker.link(jmsDestination, bundle, bundle); assertEquals(ImmutableMap.of(JNDI_CLIENT_AUT_KEYSTORE_ALIAS, "key1"), jmsDestination.getAdditionalProperties()); }
@Test void testLinkMissingJndiClientAuthPrivateKey() { Bundle bundle = new Bundle(); final JmsDestination jmsDestination = createJmsDestinationBuilder(null, null) .additionalProperties(new HashMap<String, Object>() {{ put(JNDI_CLIENT_AUT_KEYSTORE_ALIAS, "missing-key1"); }}) .build(); assertThrows(LinkerException.class, () -> linker.link(jmsDestination, bundle, bundle)); }
@Test void testLinkDestinationClientAuthPrivateKey() { Bundle bundle = new Bundle(); bundle.addEntity(createPrivateKey("key2")); final JmsDestination jmsDestination = createJmsDestinationBuilder(null, null) .additionalProperties(new HashMap<String, Object>() {{ put(DESTINATION_CLIENT_AUTH_KEYSTORE_ALIAS, "key2"); }}) .build(); linker.link(jmsDestination, bundle, bundle); assertEquals(ImmutableMap.of(DESTINATION_CLIENT_AUTH_KEYSTORE_ALIAS, "key2"), jmsDestination.getAdditionalProperties()); }
@Test void testLinkMissingDestinationClientAuthPrivateKey() { Bundle bundle = new Bundle(); final JmsDestination jmsDestination = createJmsDestinationBuilder(null, null) .additionalProperties(new HashMap<String, Object>() {{ put(DESTINATION_CLIENT_AUTH_KEYSTORE_ALIAS, "missing-key2"); }}) .build(); assertThrows(LinkerException.class, () -> linker.link(jmsDestination, bundle, bundle)); }