fix base64 decode
This commit is contained in:
1 parent
7e93ab5040
commit
37626c6159
1 file changed
+60
-4
@@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import pojos.Email;
|
||||
import pojos.Emails;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -54,6 +56,38 @@ public class TempMailAPISteps extends Steps {
|
||||
ColorFormatter.GREEN.toConsole(token));
|
||||
}
|
||||
|
||||
// @And("TempMailAPI: Confirm Home Eset registration")
|
||||
// public void tempmailapiAgreeRegistrationInHomeEset() {
|
||||
//
|
||||
// String emailSubject = "Potwierdzenie utworzenia konta";
|
||||
//
|
||||
// getEmailsUntilFindEmailWithSubject(emailSubject);
|
||||
// String responeJsonString = response.getBody().asString();
|
||||
//
|
||||
// try {
|
||||
// Emails emails = objectMapper.readValue(responeJsonString, Emails.class);
|
||||
//
|
||||
// for (Email email : emails.getEmails()) {
|
||||
// if (email.getSubject().equals(emailSubject)) {
|
||||
// log.info("Email body: {}", email.getHtml());
|
||||
//
|
||||
// Pattern pattern = Pattern.compile(ESET_URL_LINK);
|
||||
// Matcher matcher = pattern.matcher(email.getHtml());
|
||||
//
|
||||
// if (matcher.find()) {
|
||||
// String href = matcher.group();
|
||||
// log.info("Activation link found: {}", href);
|
||||
// open(href);
|
||||
// } else {
|
||||
// throw new RuntimeException("Activation link not found");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
@And("TempMailAPI: Confirm Home Eset registration")
|
||||
public void tempmailapiAgreeRegistrationInHomeEset() {
|
||||
|
||||
@@ -66,21 +100,43 @@ public class TempMailAPISteps extends Steps {
|
||||
Emails emails = objectMapper.readValue(responeJsonString, Emails.class);
|
||||
|
||||
for (Email email : emails.getEmails()) {
|
||||
if (email.getSubject().equals(emailSubject)) {
|
||||
if (emailSubject.equals(email.getSubject())) {
|
||||
|
||||
String htmlBody = email.getHtml();
|
||||
|
||||
if (htmlBody == null || htmlBody.isBlank()) {
|
||||
log.warn("Email HTML is null, attempting Base64 decode of body field");
|
||||
String rawBody = email.getBody();
|
||||
if (rawBody == null || rawBody.isBlank()) {
|
||||
throw new RuntimeException("Both html and body fields are null or empty");
|
||||
}
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(rawBody.replaceAll("\\s", ""));
|
||||
htmlBody = new String(decodedBytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
log.info("Email body (decoded): {}", htmlBody);
|
||||
|
||||
Pattern pattern = Pattern.compile(ESET_URL_LINK);
|
||||
Matcher matcher = pattern.matcher(email.getHtml());
|
||||
Matcher matcher = pattern.matcher(htmlBody);
|
||||
|
||||
if (matcher.find()) {
|
||||
String href = matcher.group();
|
||||
log.info("Activation link found: {}", href);
|
||||
open(href);
|
||||
} else {
|
||||
throw new RuntimeException("Activation link not found");
|
||||
throw new RuntimeException("Activation link not found in email body");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Email with subject '" + emailSubject + "' not found in response");
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Failed to process email confirmation", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user