Skip to content

Commit

Permalink
#646 return-after-login feature
Browse files Browse the repository at this point in the history
  • Loading branch information
iinozemtsev committed May 27, 2015
1 parent 7578e8c commit e337efa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions netbout-web/src/main/java/com/netbout/rest/RsReturn.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public RsReturn(final Response res, final String loc, final String cookie)
res,
cookie,
URLEncoder.encode(loc, Charset.defaultCharset().name()),
"Path=/",
String.format(
Locale.ENGLISH,
"Expires=%1$ta, %1$td %1$tb %1$tY %1$tT GMT",
Expand Down
9 changes: 8 additions & 1 deletion netbout-web/src/main/java/com/netbout/rest/TkReturn.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
package com.netbout.rest;

import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.Iterator;
import lombok.EqualsAndHashCode;
import org.takes.Request;
Expand Down Expand Up @@ -83,7 +85,12 @@ public Response act(final Request request) throws IOException {
final Response response;
if (values.hasNext()) {
response = new RsWithCookie(
new RsRedirect(values.next()),
new RsRedirect(
URLDecoder.decode(
values.next(),
Charset.defaultCharset().name()
)
),
this.cookie,
""
);
Expand Down
10 changes: 8 additions & 2 deletions netbout-web/src/test/java/com/netbout/rest/TkAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.jcabi.urn.URN;
import com.netbout.mock.MkBase;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.regex.Pattern;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -126,7 +128,7 @@ public void redirectsToLoginAndSetsCookie() throws Exception {
// @checkstyle MultipleStringLiteralsCheck (1 line)
"Incorrect Set-Cookie header",
Pattern.compile(
"^Set-Cookie: RsReturn=.*%2Fwhatever;Expires=.*$",
"^Set-Cookie: RsReturn=.*%2Fwhatever;Path=/;Expires=.*$",
Pattern.MULTILINE
).matcher(head).find()
);
Expand All @@ -139,11 +141,15 @@ public void redirectsToLoginAndSetsCookie() throws Exception {
*/
@Test
public void redirectsToReturnCookie() throws Exception {
final String loc = "http://example.com/whatever";
final String head = new RsPrint(
new TkApp(new MkBase()).act(
new RqWithHeader(
new RqWithTester(new URN("urn:test:1")),
"Cookie: RsReturn=http://example.com/whatever"
String.format(
"Cookie: RsReturn=%s",
URLEncoder.encode(loc, Charset.defaultCharset().name())
)
)
)
).printHead();
Expand Down

0 comments on commit e337efa

Please sign in to comment.