Skip to content

Commit 5a6ef47

Browse files
committed
Fixed tests
1 parent 8c9fe35 commit 5a6ef47

File tree

4 files changed

+6
-31
lines changed

4 files changed

+6
-31
lines changed

server/src/main/java/access/manipulation/AttributeScriptContext.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
package access.manipulation;
22

33

4-
import lombok.Getter;
5-
64
import java.util.*;
75
import java.util.stream.Collectors;
86

9-
@Getter
10-
public class AttributeScriptContext {
11-
12-
private final Map<String, List<String>> attributes;
13-
private final String subjectId;
14-
15-
public AttributeScriptContext(Map<String, List<String>> attributes, String subjectId) {
16-
this.attributes = attributes;
17-
this.subjectId = subjectId;
18-
}
7+
public record AttributeScriptContext(Map<String, List<String>> attributes, String subjectId) {
198

209
public List<String> get(String name) {
2110
return attributes.getOrDefault(name, List.of());

server/src/main/java/access/manipulation/SpelAttributeManipulationService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ public void apply(AttributeManipulation policy,
2020
if (expression == null) {
2121
return;
2222
}
23-
if (!(attributes instanceof HashMap<String, List<String>>)) {
24-
attributes = new HashMap<>(attributes);
25-
}
2623
AttributeScriptContext ctx = new AttributeScriptContext(attributes, subjectId);
2724

25+
2826
StandardEvaluationContext context = new StandardEvaluationContext(ctx);
2927

3028
context.setTypeLocator(typeName -> {

server/src/test/java/access/manipulation/AttributePolicyManipulationTest.java renamed to server/src/test/java/access/manipulation/AttributeManipulationCompilerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import static org.junit.jupiter.api.Assertions.*;
1111

12-
class AttributePolicyManipulationTest {
12+
class AttributeManipulationCompilerTest {
1313

1414
private final AttributeManipulationCompiler compiler = new AttributeManipulationCompiler();
1515

@@ -81,7 +81,7 @@ void shouldFailOnJvmTypeAccess() {
8181
@Test
8282
void shouldAllowSubjectIdUsage() {
8383
String script = """
84-
set('subject', {getSubjectId()})
84+
set('subject', {subjectId()})
8585
""";
8686

8787
compiler.compile(script);

server/src/test/java/access/manipulation/SpelAttributeManipulationServiceTest.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void shouldExposeSubjectId() {
6767
Map<String, List<String>> attributes = new HashMap<>();
6868

6969
String script = """
70-
set('subject', {getSubjectId()})
70+
set('subject', {subjectId()})
7171
""";
7272

7373
service.apply(compilePolicy(script), attributes, "the-user");
@@ -128,19 +128,7 @@ void shouldRemoveAttribute() {
128128
void shouldSetAttribute() {
129129
Map<String, List<String>> attributes = new HashMap<>();
130130

131-
String script = "set('uid', {getSubjectId()})";
132-
133-
service.apply(compilePolicy(script), attributes, "user");
134-
135-
assertEquals(1, attributes.size());
136-
assertEquals(List.of("user"), attributes.get("uid"));
137-
}
138-
139-
@Test
140-
void worksForImmutableMaps() {
141-
Map<String, List<String>> attributes = Map.of();
142-
143-
String script = "set('uid', {getSubjectId()})";
131+
String script = "set('uid', {subjectId()})";
144132

145133
service.apply(compilePolicy(script), attributes, "user");
146134

0 commit comments

Comments
 (0)