|
| 1 | +package org.jooby.pac4j; |
| 2 | + |
| 3 | +import static org.easymock.EasyMock.expect; |
| 4 | +import static org.junit.Assert.assertEquals; |
| 5 | + |
| 6 | +import java.util.Map; |
| 7 | +import java.util.Optional; |
| 8 | + |
| 9 | +import org.jooby.Err; |
| 10 | +import org.jooby.Mutant; |
| 11 | +import org.jooby.Request; |
| 12 | +import org.jooby.Response; |
| 13 | +import org.jooby.Status; |
| 14 | +import org.jooby.internal.pac4j.AuthContext; |
| 15 | +import org.jooby.internal.pac4j.AuthSerializer; |
| 16 | +import org.jooby.test.MockUnit; |
| 17 | +import org.jooby.test.MockUnit.Block; |
| 18 | +import org.junit.Test; |
| 19 | +import org.junit.runner.RunWith; |
| 20 | +import org.powermock.core.classloader.annotations.PrepareForTest; |
| 21 | +import org.powermock.modules.junit4.PowerMockRunner; |
| 22 | + |
| 23 | +import com.google.common.collect.ImmutableList; |
| 24 | +import com.google.common.collect.ImmutableMap; |
| 25 | + |
| 26 | +@RunWith(PowerMockRunner.class) |
| 27 | +@PrepareForTest({AuthContext.class, AuthSerializer.class }) |
| 28 | +public class Issue599 { |
| 29 | + |
| 30 | + private Block params = unit -> { |
| 31 | + Mutant param = unit.get(Mutant.class); |
| 32 | + expect(param.toList()).andReturn(ImmutableList.of("v1")); |
| 33 | + expect(param.toList()).andThrow(new Err(Status.BAD_REQUEST)); |
| 34 | + |
| 35 | + Map<String, Mutant> map = ImmutableMap.of("p1", param, "p2", param); |
| 36 | + |
| 37 | + Mutant params = unit.mock(Mutant.class); |
| 38 | + expect(params.toMap()).andReturn(map); |
| 39 | + |
| 40 | + Request req = unit.get(Request.class); |
| 41 | + expect(req.params()).andReturn(params); |
| 42 | + }; |
| 43 | + |
| 44 | + @Test |
| 45 | + public void shouldKeepQueryString() throws Exception { |
| 46 | + new MockUnit(Request.class, Response.class, Mutant.class) |
| 47 | + .expect(params) |
| 48 | + .expect(unit -> { |
| 49 | + Request req = unit.get(Request.class); |
| 50 | + expect(req.secure()).andReturn(false); |
| 51 | + expect(req.hostname()).andReturn("localhost"); |
| 52 | + expect(req.port()).andReturn(8080); |
| 53 | + expect(req.path()).andReturn("/foo"); |
| 54 | + expect(req.queryString()).andReturn(Optional.of("bar=1")); |
| 55 | + }) |
| 56 | + .run(unit -> { |
| 57 | + AuthContext ctx = new AuthContext(unit.get(Request.class), unit.get(Response.class)); |
| 58 | + assertEquals("http://localhost:8080/foo?bar=1", ctx.getFullRequestURL()); |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments