Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in VariableAwareExpression that does not correctly parses expression #710

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public VariableAwareExpression(String value) {
int openingCurlyBracePos = value.indexOf("{", currentPos);
if (openingCurlyBracePos == -1) {
if (currentPos < value.length()) {
String authorizationPart = value.substring(currentPos, value.length() - currentPos);
String authorizationPart = value.substring(currentPos);
tmpParts.add(ctx -> authorizationPart);
}
break;
Expand Down
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;
}
}
}
Loading