JdbcConnectionLinker implements EntityLinker<JdbcConnection> { @Override public void link(JdbcConnection entity, Bundle bundle, Bundle targetBundle) { if (entity.getPassword() != null) { if (entity.getPassword().startsWith(ENCRYPTED_PASSWORD_PREFIX)) { entity.setPassword(null); } else { String storedPasswordReference = extractVariableName(entity.getPassword()); if (!isEmpty(storedPasswordReference)) { Matcher matcher = STORED_PASSWORD_PATTERN.matcher(storedPasswordReference); if (matcher.matches()) { String storedPasswordName = matcher.group(1); setPasswordRef(entity, bundle, storedPasswordName); } } } } }  @Override void link(JdbcConnection entity, Bundle bundle, Bundle targetBundle); @Override Class<JdbcConnection> getEntityClass();  }
@Test void link() { link(GATEWAY); }
@Test void linkUsingPasswordWithDots() { link(GATEWAY_WITH_DOTS); }
@Test void linkMissingPassword() { final JdbcConnection jdbcConnection = createJdbcConnection(String.format(STORED_PASSWORD_REF_FORMAT, GATEWAY)); assertThrows(LinkerException.class, () -> linker.link(jdbcConnection, new Bundle(), new Bundle())); }
@Test void linkNullPassword() { final JdbcConnection jdbcConnection = createJdbcConnection(null); linker.link(jdbcConnection, new Bundle(), new Bundle()); assertNull(jdbcConnection.getPasswordRef()); assertNull(jdbcConnection.getPassword()); }
@Test void linkWrongPassword() { Bundle bundle = new Bundle(); bundle.addEntity(createStoredPassword(GATEWAY + GATEWAY)); final JdbcConnection jdbcConnection = createJdbcConnection(String.format(STORED_PASSWORD_REF_FORMAT, GATEWAY)); assertThrows(LinkerException.class, () -> linker.link(jdbcConnection, bundle, bundle)); }
@Test void linkNotPasswordVariable() { final JdbcConnection jdbcConnection = createJdbcConnection("${" + GATEWAY + "}"); linker.link(jdbcConnection, new Bundle(), new Bundle()); assertNull(jdbcConnection.getPasswordRef()); assertEquals("${" + GATEWAY + "}", jdbcConnection.getPassword()); assertNotNull(jdbcConnection.getPassword()); }
@Test void linkNotVariableFormat() { final JdbcConnection jdbcConnection = createJdbcConnection(GATEWAY); linker.link(jdbcConnection, new Bundle(), new Bundle()); assertNull(jdbcConnection.getPasswordRef()); assertEquals(GATEWAY, jdbcConnection.getPassword()); assertNotNull(jdbcConnection.getPassword()); }
@Test void linkL7C2VariableFormat() { final JdbcConnection jdbcConnection = createJdbcConnection("$L7C2$1,3ok3RLhLqpD3Z3QdyTpoa2iHU2dRYdAF3TgSchF2ttI=$2EqC+niJG4yw7LOJ52Rur0VcGccT/r1WpHE+4Aiqj5GcNNYXub9h7pO5CrGT7eFGhyub2ilKx5M+ULQtbU5ZTcGxgj4K+H0+y9Yq5LNbKggoHYa+3T8r9pIcUamcCx7q"); linker.link(jdbcConnection, new Bundle(), new Bundle()); assertNull(jdbcConnection.getPasswordRef()); assertNull(jdbcConnection.getPassword()); }