-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check that contextValue starts with (#240)
* fix: check that contextValue starts with There had been an inversion of variable usage for one of our cases in the matcher. This PR makes sure to compare contextValue to see if it starts with the requested value in the constraint, instead of the other way around. fixes #238
- Loading branch information
Showing
2 changed files
with
58 additions
and
5 deletions.
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
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 |
---|---|---|
|
@@ -211,4 +211,56 @@ public void shouldSupportInvertingStringContains() { | |
.build(); | ||
assertThat(strategy.isEnabled(parameters, ctx, constraintList)).isFalse(); | ||
} | ||
|
||
@Test | ||
public void startsWithShouldMatchCorrectlyWhenCaseSensitive() { | ||
Strategy strategy = new DefaultStrategy(); | ||
List<Constraint> constraintList = | ||
Collections.singletonList( | ||
new Constraint( | ||
"email", | ||
Operator.STR_STARTS_WITH, | ||
Collections.singletonList("testuser"), | ||
false, | ||
false)); | ||
Map<String, String> parameters = new HashMap<>(); | ||
UnleashContext ctx = | ||
UnleashContext.builder() | ||
.environment("dev") | ||
.addProperty("email", "[email protected]") | ||
.build(); | ||
assertThat(strategy.isEnabled(parameters, ctx, constraintList)).isFalse(); | ||
UnleashContext ctx2 = | ||
UnleashContext.builder() | ||
.environment("dev") | ||
.addProperty("email", "[email protected]") | ||
.build(); | ||
assertThat(strategy.isEnabled(parameters, ctx2, constraintList)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void startsWithShouldMatchCorrectlyWhenCaseInsensitive() { | ||
Strategy strategy = new DefaultStrategy(); | ||
List<Constraint> constraintList = | ||
Collections.singletonList( | ||
new Constraint( | ||
"email", | ||
Operator.STR_STARTS_WITH, | ||
Collections.singletonList("testuser"), | ||
false, | ||
true)); | ||
Map<String, String> parameters = new HashMap<>(); | ||
UnleashContext ctx = | ||
UnleashContext.builder() | ||
.environment("dev") | ||
.addProperty("email", "[email protected]") | ||
.build(); | ||
assertThat(strategy.isEnabled(parameters, ctx, constraintList)).isTrue(); | ||
UnleashContext ctx2 = | ||
UnleashContext.builder() | ||
.environment("dev") | ||
.addProperty("email", "[email protected]") | ||
.build(); | ||
assertThat(strategy.isEnabled(parameters, ctx2, constraintList)).isTrue(); | ||
} | ||
} |