-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug to read sub string correctly
Motivation: VariableAwareExpression uses substring to get remaining part of String. It has a bug, it is using the length of the string in second index, instead of using last position + 1 of required substring. Without this fix, expressions like {foo}bar can not be processed. Changes: This patch fixes it.
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ommon/src/test/java/io/vertx/ext/auth/authorization/impl/VariableAwareExpressionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.vertx.ext.auth.authorization.impl; | ||
|
||
import io.vertx.core.MultiMap; | ||
import io.vertx.ext.auth.User; | ||
import io.vertx.ext.auth.authorization.AuthorizationContext; | ||
import org.junit.Test; | ||
|
||
import java.util.function.Function; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class VariableAwareExpressionTest { | ||
|
||
@Test | ||
public void test2() { | ||
VariableAwareExpression expression = new VariableAwareExpression("{bar}end"); | ||
String resolved = expression.resolve(new MockAuthorizationContext(MultiMap.caseInsensitiveMultiMap().add("bar", "foo"))); | ||
Function<AuthorizationContext, String>[] parts = expression.parts(); | ||
assertEquals("fooend", resolved); | ||
} | ||
|
||
@Test | ||
public void test3() { | ||
VariableAwareExpression expression = new VariableAwareExpression("begin{bar}"); | ||
String resolved = expression.resolve(new MockAuthorizationContext(MultiMap.caseInsensitiveMultiMap().add("bar", "foo"))); | ||
assertEquals("beginfoo", resolved); | ||
} | ||
|
||
@Test | ||
public void test4() { | ||
VariableAwareExpression expression = new VariableAwareExpression("part1,part2{bar}"); | ||
String resolved = expression.resolve(new MockAuthorizationContext(MultiMap.caseInsensitiveMultiMap().add("bar", "foo"))); | ||
assertEquals("part1,part2foo", resolved); | ||
} | ||
|
||
@Test | ||
public void test5() { | ||
VariableAwareExpression expression = new VariableAwareExpression("part1{bar}part2,part3"); | ||
String resolved = expression.resolve(new MockAuthorizationContext(MultiMap.caseInsensitiveMultiMap().add("bar", "foo"))); | ||
assertEquals("part1foopart2,part3", resolved); | ||
} | ||
|
||
private static class MockAuthorizationContext implements AuthorizationContext { | ||
|
||
private final MultiMap variables; | ||
|
||
public MockAuthorizationContext(MultiMap variables) { | ||
this.variables = variables; | ||
} | ||
|
||
@Override | ||
public User user() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public MultiMap variables() { | ||
return variables; | ||
} | ||
} | ||
} |