This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-jspf.git
The following commit(s) were added to refs/heads/master by this push: new e188ef5 [FIX] AsynchronousSPFExecutor should chain correctly DNSLookupContinuation e188ef5 is described below commit e188ef5db6a76dc687faa0d464eabc06c4896339 Author: Benoit TELLIER <btell...@linagora.com> AuthorDate: Fri May 17 11:08:15 2024 +0200 [FIX] AsynchronousSPFExecutor should chain correctly DNSLookupContinuation --- .../jspf/executor/AsynchronousSPFExecutor.java | 72 ++++++++++++---------- .../AsynchronousSPFExecutorIntegrationTest.java | 42 +++++++++++++ 2 files changed, 82 insertions(+), 32 deletions(-) diff --git a/resolver/src/main/java/org/apache/james/jspf/executor/AsynchronousSPFExecutor.java b/resolver/src/main/java/org/apache/james/jspf/executor/AsynchronousSPFExecutor.java index 2ec4e9d..0b950b3 100644 --- a/resolver/src/main/java/org/apache/james/jspf/executor/AsynchronousSPFExecutor.java +++ b/resolver/src/main/java/org/apache/james/jspf/executor/AsynchronousSPFExecutor.java @@ -50,39 +50,47 @@ public class AsynchronousSPFExecutor implements SPFExecutor { * @see SPFExecutor#execute(SPFSession, FutureSPFResult) */ public void execute(SPFSession session, FutureSPFResult result) { - SPFChecker checker; - while ((checker = session.popChecker()) != null) { - // only execute checkers we added (better recursivity) - LOGGER.debug("Executing checker: {}", checker); - SPFChecker finalChecker = checker; - try { - DNSLookupContinuation cont = checker.checkSPF(session); - if (cont == null) { - continue; - } - // if the checker returns a continuation we return it - dnsProbe.getRecordsAsync(cont.getRequest()) - .thenAccept(results -> { - try { - cont.getListener().onDNSResponse(new DNSResponse(results), session); - } catch (PermErrorException | NoneException | TempErrorException | NeutralException e) { - handleError(session, finalChecker, e); - } - }) - .exceptionally(e -> { - if (e instanceof TimeoutException) { - handleTimeout(session, finalChecker, cont, (TimeoutException) e); - } - if (e.getCause() instanceof TimeoutException) { - handleTimeout(session, finalChecker, cont, (TimeoutException) e.getCause()); - } - return null; - }); - } catch (Exception e) { - handleError(session, checker, e); - } + SPFChecker checker = session.popChecker(); + if (checker == null) { + result.setSPFResult(session); + return; + } + // only execute checkers we added (better recursivity) + LOGGER.debug("Executing checker: {}", checker); + try { + DNSLookupContinuation cont = checker.checkSPF(session); + handleCont(session, result, cont, checker); + } catch (Exception e) { + handleError(session, checker, e); + result.setSPFResult(session); + } + } + + private void handleCont(SPFSession session, FutureSPFResult result, DNSLookupContinuation cont, SPFChecker checker) { + if (cont != null) { + // if the checker returns a continuation we return it + dnsProbe.getRecordsAsync(cont.getRequest()) + .thenAccept(results -> { + try { + DNSLookupContinuation dnsLookupContinuation = cont.getListener().onDNSResponse(new DNSResponse(results), session); + handleCont(session, result, dnsLookupContinuation, checker); + } catch (PermErrorException | NoneException | TempErrorException | NeutralException e) { + handleError(session, checker, e); + } + }) + .exceptionally(e -> { + if (e instanceof TimeoutException) { + handleTimeout(session, checker, cont, (TimeoutException) e); + } + if (e.getCause() instanceof TimeoutException) { + handleTimeout(session, checker, cont, (TimeoutException) e.getCause()); + } + result.setSPFResult(session); + return null; + }); + } else { + execute(session, result); } - result.setSPFResult(session); } private void handleTimeout(SPFSession session, SPFChecker finalChecker, DNSLookupContinuation cont, TimeoutException e) { diff --git a/resolver/src/test/java/org/apache/james/jspf/AsynchronousSPFExecutorIntegrationTest.java b/resolver/src/test/java/org/apache/james/jspf/AsynchronousSPFExecutorIntegrationTest.java new file mode 100644 index 0000000..56b8e51 --- /dev/null +++ b/resolver/src/test/java/org/apache/james/jspf/AsynchronousSPFExecutorIntegrationTest.java @@ -0,0 +1,42 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.jspf; + +import static org.junit.Assert.assertEquals; + +import org.apache.james.jspf.executor.SPFResult; +import org.apache.james.jspf.impl.DefaultSPF; +import org.apache.james.jspf.impl.SPF; +import org.junit.Test; + +public class AsynchronousSPFExecutorIntegrationTest { + + @Test + public void test() { + SPF spf = new DefaultSPF(); + SPFResult result = spf.checkSPF("192.99.55.226", "n...@bytle.net", "beau.bytle.net"); + System.out.println(result.getResult()); + System.out.println(result.getExplanation()); + System.out.println(result.getHeader()); + assertEquals("pass", result.getResult()); + assertEquals("Received-SPF: pass (spfCheck: domain of bytle.net designates 192.99.55.226 as permitted sender) client-ip=192.99.55.226; envelope-from=n...@bytle.net; helo=beau.bytle.net;", + result.getHeader()); + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org