Commit 0a8e7d85 authored by Simon Urli's avatar Simon Urli
Browse files

XWIKI-18526: Bad URL serialization to Forgot username/password

  * Fix serialization link when sending validation email

(cherry picked from commit d01cd34a)
parent 4b321972
......@@ -23,6 +23,7 @@
import java.net.URL;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.mail.internet.InternetAddress;
......@@ -42,6 +43,7 @@
import org.xwiki.security.authentication.ResetPasswordManager;
import org.xwiki.security.authentication.ResetPasswordRequestResponse;
import org.xwiki.url.ExtendedURL;
import org.xwiki.url.URLNormalizer;
import org.xwiki.user.UserManager;
import org.xwiki.user.UserProperties;
import org.xwiki.user.UserPropertiesResolver;
......@@ -98,6 +100,10 @@
@Inject
private ResourceReferenceSerializer<ResourceReference, ExtendedURL> resourceReferenceSerializer;
@Inject
@Named("contextpath")
private URLNormalizer<ExtendedURL> urlNormalizer;
@Inject
private UserReferenceSerializer<String> referenceSerializer;
......@@ -195,6 +201,7 @@ public void sendResetPasswordEmailRequest(ResetPasswordRequestResponse requestRe
ExtendedURL extendedURL = null;
try {
extendedURL = this.resourceReferenceSerializer.serialize(resourceReference);
extendedURL = this.urlNormalizer.normalize(extendedURL);
URL serverURL = context.getURLFactory().getServerURL(context);
URL externalVerificationURL = new URL(serverURL, extendedURL.serialize());
......
......@@ -22,6 +22,7 @@
import java.net.URL;
import java.util.Arrays;
import javax.inject.Named;
import javax.inject.Provider;
import javax.mail.internet.InternetAddress;
......@@ -40,6 +41,7 @@
import org.xwiki.test.junit5.mockito.InjectMockComponents;
import org.xwiki.test.junit5.mockito.MockComponent;
import org.xwiki.url.ExtendedURL;
import org.xwiki.url.URLNormalizer;
import org.xwiki.user.UserManager;
import org.xwiki.user.UserProperties;
import org.xwiki.user.UserPropertiesResolver;
......@@ -88,6 +90,10 @@
@MockComponent
private ResourceReferenceSerializer<ResourceReference, ExtendedURL> resourceReferenceSerializer;
@MockComponent
@Named("contextpath")
private URLNormalizer<ExtendedURL> urlNormalizer;
@MockComponent
private UserReferenceSerializer<String> referenceSerializer;
......@@ -214,8 +220,12 @@ void sendResetPasswordEmailRequest() throws Exception
String verificationCode = "foobar4242";
resourceReference.addParameter("u", "user:Foobar");
resourceReference.addParameter("v", verificationCode);
when(this.resourceReferenceSerializer.serialize(resourceReference)).thenReturn(
new ExtendedURL(Arrays.asList("authenticate", "reset"), resourceReference.getParameters()));
ExtendedURL firstExtendedURL =
new ExtendedURL(Arrays.asList("authenticate", "reset"), resourceReference.getParameters());
when(this.resourceReferenceSerializer.serialize(resourceReference)).thenReturn(firstExtendedURL);
when(this.urlNormalizer.normalize(firstExtendedURL)).thenReturn(
new ExtendedURL(Arrays.asList("xwiki", "authenticate", "reset"), resourceReference.getParameters())
);
XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
when(this.context.getURLFactory()).thenReturn(urlFactory);
when(urlFactory.getServerURL(this.context)).thenReturn(new URL("http://xwiki.org"));
......@@ -226,7 +236,7 @@ void sendResetPasswordEmailRequest() throws Exception
verificationCode);
this.resetPasswordManager.sendResetPasswordEmailRequest(requestResponse);
verify(this.resetPasswordMailSender).sendResetPasswordEmail("Foo Bar", email,
new URL("http://xwiki.org/authenticate/reset?u=user%3AFoobar&v=foobar4242"));
new URL("http://xwiki.org/xwiki/authenticate/reset?u=user%3AFoobar&v=foobar4242"));
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment