[java-oidc-common] branch main updated: JOIDC-21 - Use token authentication for OIDC dynamic client registration
Scott Cantor
cantor.2 at osu.edu
Tue Mar 15 12:28:27 UTC 2022
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-oidc-common.
View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=3b3b90262ead07af18e7d2e6f501aa87f00fe500
The following commit(s) were added to refs/heads/main by this push:
new 3b3b902 JOIDC-21 - Use token authentication for OIDC dynamic client registration
3b3b902 is described below
commit 3b3b90262ead07af18e7d2e6f501aa87f00fe500
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Mar 15 08:27:52 2022 -0400
JOIDC-21 - Use token authentication for OIDC dynamic client registration
https://shibboleth.atlassian.net/browse/JOIDC-21
Adjust metadata policy enforcer into a BiFunction.
---
.../policy/impl/DefaultMetadataPolicyEnforcer.java | 8 +-
.../impl/DefaultMetadataPolicyEnforcerTest.java | 392 ++++++++++-----------
2 files changed, 199 insertions(+), 201 deletions(-)
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyEnforcer.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyEnforcer.java
index 3664215..4e8c1a0 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyEnforcer.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyEnforcer.java
@@ -20,7 +20,7 @@ package net.shibboleth.oidc.metadata.policy.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.function.Function;
+import java.util.function.BiFunction;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
@@ -55,15 +55,13 @@ import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
* been applied to, and a flag indicating if the object was compatible with the value checks of the metadata policy.
* </p>
*/
-public class DefaultMetadataPolicyEnforcer implements Function<Pair<Object, MetadataPolicy>, Pair<Object, Boolean>> {
+public class DefaultMetadataPolicyEnforcer implements BiFunction<Object,MetadataPolicy,Pair<Object,Boolean>> {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(DefaultMetadataPolicyEnforcer.class);
/** {@inheritDoc} */
- @Override @Nonnull public Pair<Object, Boolean> apply(@Nonnull final Pair<Object, MetadataPolicy> pair) {
- final Object candidate = pair.getFirst();
- final MetadataPolicy policy = pair.getSecond();
+ @Nonnull public Pair<Object, Boolean> apply(@Nullable final Object candidate, @Nullable final MetadataPolicy policy) {
if (policy == null) {
return new Pair<>(candidate, Boolean.TRUE);
}
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyEnforcerTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyEnforcerTest.java
index 638cf56..e99fb4b 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyEnforcerTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyEnforcerTest.java
@@ -42,19 +42,19 @@ public class DefaultMetadataPolicyEnforcerTest {
public void apply_whenValueSetToNull_resultIsValueWithTrue() {
final String stringValue = "mockValue";
assertResultEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withValue(stringValue).build())),
+ applier.apply(null, new MetadataPolicy.Builder().withValue(stringValue).build()),
stringValue);
final List<String> listValue = List.of("value1", "value2");
assertResultEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withValue(listValue).build())),
+ applier.apply(null, new MetadataPolicy.Builder().withValue(listValue).build()),
listValue);
final int intValue = 123;
assertResultEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withValue(intValue).build())),
+ applier.apply(null, new MetadataPolicy.Builder().withValue(intValue).build()),
intValue);
final boolean booleanValue = true;
assertResultEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withValue(booleanValue).build())),
+ applier.apply(null, new MetadataPolicy.Builder().withValue(booleanValue).build()),
booleanValue);
}
@@ -62,282 +62,282 @@ public class DefaultMetadataPolicyEnforcerTest {
public void apply_whenValueSetToSomething_resultIsValueWithTrue() {
final String stringValue = "mockValue";
assertResultEquals(
- applier.apply(new Pair<>(4321, new MetadataPolicy.Builder().withValue(stringValue).build())),
+ applier.apply(4321, new MetadataPolicy.Builder().withValue(stringValue).build()),
stringValue);
final List<String> listValue = List.of("value1", "value2");
assertResultEquals(
- applier.apply(new Pair<>("mock", new MetadataPolicy.Builder().withValue(listValue).build())),
+ applier.apply("mock", new MetadataPolicy.Builder().withValue(listValue).build()),
listValue);
final int intValue = 123;
assertResultEquals(
- applier.apply(new Pair<>(false, new MetadataPolicy.Builder().withValue(intValue).build())),
+ applier.apply(false, new MetadataPolicy.Builder().withValue(intValue).build()),
intValue);
final boolean booleanValue = true;
assertResultEquals(
- applier.apply(new Pair<>(List.of("1"), new MetadataPolicy.Builder().withValue(booleanValue).build())),
+ applier.apply(List.of("1"), new MetadataPolicy.Builder().withValue(booleanValue).build()),
booleanValue);
}
@Test
public void apply_whenAddToNullCandidate_resultIsSameAsWithValue() {
final String stringValue = "mockValue";
- System.out.println("" + applier.apply(new Pair<>(null, new MetadataPolicy.Builder()
- .withAdd(stringValue).build())));
+ System.out.println("" + applier.apply(null, new MetadataPolicy.Builder()
+ .withAdd(stringValue).build()));
Assert.assertEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withAdd(stringValue).build())),
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withValue(stringValue).build())));
+ applier.apply(null, new MetadataPolicy.Builder().withAdd(stringValue).build()),
+ applier.apply(null, new MetadataPolicy.Builder().withValue(stringValue).build()));
final List<String> listValue = List.of("value1", "value2");
Assert.assertEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withAdd(listValue).build())),
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withValue(listValue).build())));
+ applier.apply(null, new MetadataPolicy.Builder().withAdd(listValue).build()),
+ applier.apply(null, new MetadataPolicy.Builder().withValue(listValue).build()));
final int intValue = 123;
Assert.assertEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withAdd(intValue).build())),
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withValue(intValue).build())));
+ applier.apply(null, new MetadataPolicy.Builder().withAdd(intValue).build()),
+ applier.apply(null, new MetadataPolicy.Builder().withValue(intValue).build()));
final boolean booleanValue = true;
Assert.assertEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withAdd(booleanValue).build())),
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withValue(booleanValue).build())));
+ applier.apply(null, new MetadataPolicy.Builder().withAdd(booleanValue).build()),
+ applier.apply(null, new MetadataPolicy.Builder().withValue(booleanValue).build()));
}
@Test
public void apply_whenAddToSameExistingCandidate_resultIsSameWithTrue() {
assertResultEquals(
- applier.apply(new Pair<>("existing", new MetadataPolicy.Builder().withAdd("existing").build())),
+ applier.apply("existing", new MetadataPolicy.Builder().withAdd("existing").build()),
"existing");
assertResultEquals(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withAdd(123).build())),
+ applier.apply(123, new MetadataPolicy.Builder().withAdd(123).build()),
123);
assertResultEquals(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withAdd(true).build())),
+ applier.apply(true, new MetadataPolicy.Builder().withAdd(true).build()),
true);
}
@Test
public void apply_whenAddToDifferentSingleExistingCandidate_resultIsFalse() {
assertResultFalse(
- applier.apply(new Pair<>("existing", new MetadataPolicy.Builder().withAdd("another").build())));
+ applier.apply("existing", new MetadataPolicy.Builder().withAdd("another").build()));
assertResultFalse(
- applier.apply(new Pair<>("existing", new MetadataPolicy.Builder().withAdd(List.of("another"))
- .build())));
+ applier.apply("existing", new MetadataPolicy.Builder().withAdd(List.of("another"))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withAdd(321).build())));
+ applier.apply(123, new MetadataPolicy.Builder().withAdd(321).build()));
assertResultFalse(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withAdd(false).build())));
+ applier.apply(true, new MetadataPolicy.Builder().withAdd(false).build()));
}
@Test
public void apply_whenAddToListCandidate_resultIsMergedWithTrue() {
final List<String> listValue = List.of("value1", "value2");
assertResultEquals(
- applier.apply(new Pair<>(List.of("value0"),
- new MetadataPolicy.Builder().withAdd(listValue).build())),
+ applier.apply(List.of("value0"),
+ new MetadataPolicy.Builder().withAdd(listValue).build()),
List.of("value0", "value1", "value2"));
final List<Integer> intValues = List.of(123);
assertResultEquals(
- applier.apply(new Pair<>(List.of(321), new MetadataPolicy.Builder().withAdd(intValues).build())),
+ applier.apply(List.of(321), new MetadataPolicy.Builder().withAdd(intValues).build()),
List.of(321, 123));
final List<Boolean> booleanValues = List.of(true);
assertResultEquals(
- applier.apply(new Pair<>(List.of(false), new MetadataPolicy.Builder().withAdd(booleanValues).build())),
+ applier.apply(List.of(false), new MetadataPolicy.Builder().withAdd(booleanValues).build()),
List.of(false, true));
}
@Test
public void apply_whenNoCandidateAndDefaultSet_resultIsDefaultWithTrue() {
assertResultEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withDefaultValue("default").build())),
+ applier.apply(null, new MetadataPolicy.Builder().withDefaultValue("default").build()),
"default");
assertResultEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withDefaultValue(List.of("default"))
- .build())),
+ applier.apply(null, new MetadataPolicy.Builder().withDefaultValue(List.of("default"))
+ .build()),
List.of("default"));
assertResultEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withDefaultValue(123).build())),
+ applier.apply(null, new MetadataPolicy.Builder().withDefaultValue(123).build()),
123);
assertResultEquals(
- applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withDefaultValue(true).build())),
+ applier.apply(null, new MetadataPolicy.Builder().withDefaultValue(true).build()),
true);
}
@Test
public void apply_whenCandidateAndDefaultSet_resultIsCandidateWithTrue() {
assertResultEquals(
- applier.apply(new Pair<>("existing", new MetadataPolicy.Builder()
- .withDefaultValue("default").build())),
+ applier.apply("existing", new MetadataPolicy.Builder()
+ .withDefaultValue("default").build()),
"existing");
assertResultEquals(
- applier.apply(new Pair<>(List.of("existing"), new MetadataPolicy.Builder()
- .withDefaultValue(List.of("default")).build())),
+ applier.apply(List.of("existing"), new MetadataPolicy.Builder()
+ .withDefaultValue(List.of("default")).build()),
List.of("existing"));
assertResultEquals(
- applier.apply(new Pair<>(321, new MetadataPolicy.Builder().withDefaultValue(123).build())),
+ applier.apply(321, new MetadataPolicy.Builder().withDefaultValue(123).build()),
321);
assertResultEquals(
- applier.apply(new Pair<>(false, new MetadataPolicy.Builder().withDefaultValue(true).build())),
+ applier.apply(false, new MetadataPolicy.Builder().withDefaultValue(true).build()),
false);
}
@Test
public void apply_whenEssentialAndNoValue_resultIsFalse() {
- assertResultFalse(applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withEssential(true).build())));
+ assertResultFalse(applier.apply(null, new MetadataPolicy.Builder().withEssential(true).build()));
}
@Test
public void apply_whenNonEssentialAndNoValue_resultIsNullWithTrue() {
// default is that essential=false
- assertResultEquals(applier.apply(new Pair<>(null, new MetadataPolicy.Builder().build())),
+ assertResultEquals(applier.apply(null, new MetadataPolicy.Builder().build()),
null);
- assertResultEquals(applier.apply(new Pair<>(null, new MetadataPolicy.Builder().withEssential(false).build())),
+ assertResultEquals(applier.apply(null, new MetadataPolicy.Builder().withEssential(false).build()),
null);
}
@Test
public void apply_whenOneOfMeetsValue_resultIsCandidateWithTrue() {
assertResultEquals(
- applier.apply(new Pair<>("existing", new MetadataPolicy.Builder().withOneOfValues(List.of("existing"))
- .build())),
+ applier.apply("existing", new MetadataPolicy.Builder().withOneOfValues(List.of("existing"))
+ .build()),
"existing");
assertResultEquals(
- applier.apply(new Pair<>("existing", new MetadataPolicy.Builder().withOneOfValues(List.of("existing",
- "another")).build())),
+ applier.apply("existing", new MetadataPolicy.Builder().withOneOfValues(List.of("existing",
+ "another")).build()),
"existing");
assertResultEquals(
- applier.apply(new Pair<>(List.of("existing"), new MetadataPolicy.Builder().withOneOfValues(
- List.of("existing")).build())),
+ applier.apply(List.of("existing"), new MetadataPolicy.Builder().withOneOfValues(
+ List.of("existing")).build()),
List.of("existing"));
assertResultEquals(
- applier.apply(new Pair<>(List.of("existing"), new MetadataPolicy.Builder().withOneOfValues(
- List.of("existing", "another")).build())),
+ applier.apply(List.of("existing"), new MetadataPolicy.Builder().withOneOfValues(
+ List.of("existing", "another")).build()),
List.of("existing"));
assertResultEquals(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withOneOfValues(List.of(123))
- .build())),
+ applier.apply(123, new MetadataPolicy.Builder().withOneOfValues(List.of(123))
+ .build()),
123);
assertResultEquals(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withOneOfValues(List.of(123, 321))
- .build())),
+ applier.apply(123, new MetadataPolicy.Builder().withOneOfValues(List.of(123, 321))
+ .build()),
123);
assertResultEquals(
- applier.apply(new Pair<>(List.of(123), new MetadataPolicy.Builder().withOneOfValues(List.of(123))
- .build())),
+ applier.apply(List.of(123), new MetadataPolicy.Builder().withOneOfValues(List.of(123))
+ .build()),
List.of(123));
assertResultEquals(
- applier.apply(new Pair<>(List.of(123), new MetadataPolicy.Builder().withOneOfValues(List.of(123, 321))
- .build())),
+ applier.apply(List.of(123), new MetadataPolicy.Builder().withOneOfValues(List.of(123, 321))
+ .build()),
List.of(123));
assertResultEquals(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withOneOfValues(List.of(true))
- .build())),
+ applier.apply(true, new MetadataPolicy.Builder().withOneOfValues(List.of(true))
+ .build()),
true);
assertResultEquals(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withOneOfValues(List.of(true, false))
- .build())),
+ applier.apply(true, new MetadataPolicy.Builder().withOneOfValues(List.of(true, false))
+ .build()),
true);
assertResultEquals(
- applier.apply(new Pair<>(List.of(true), new MetadataPolicy.Builder().withOneOfValues(List.of(true))
- .build())),
+ applier.apply(List.of(true), new MetadataPolicy.Builder().withOneOfValues(List.of(true))
+ .build()),
List.of(true));
assertResultEquals(
- applier.apply(new Pair<>(List.of(true), new MetadataPolicy.Builder().withOneOfValues(List.of(true,
- false)).build())),
+ applier.apply(List.of(true), new MetadataPolicy.Builder().withOneOfValues(List.of(true,
+ false)).build()),
List.of(true));
}
@Test
public void apply_whenOneOfNotMeetingValue_resultIsFalse() {
assertResultFalse(
- applier.apply(new Pair<>(List.of("existing", "another"), new MetadataPolicy.Builder().withOneOfValues(
- List.of("existing", "another")).build())));
+ applier.apply(List.of("existing", "another"), new MetadataPolicy.Builder().withOneOfValues(
+ List.of("existing", "another")).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of("not"), new MetadataPolicy.Builder().withOneOfValues(
- List.of("existing", "another")).build())));
+ applier.apply(List.of("not"), new MetadataPolicy.Builder().withOneOfValues(
+ List.of("existing", "another")).build()));
assertResultFalse(
- applier.apply(new Pair<>("not", new MetadataPolicy.Builder().withOneOfValues(List.of("existing"))
- .build())));
+ applier.apply("not", new MetadataPolicy.Builder().withOneOfValues(List.of("existing"))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>("not", new MetadataPolicy.Builder().withOneOfValues(List.of("existing",
- "another")).build())));
+ applier.apply("not", new MetadataPolicy.Builder().withOneOfValues(List.of("existing",
+ "another")).build()));
assertResultFalse(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withOneOfValues(List.of(321))
- .build())));
+ applier.apply(123, new MetadataPolicy.Builder().withOneOfValues(List.of(321))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withOneOfValues(List.of(321, 322))
- .build())));
+ applier.apply(123, new MetadataPolicy.Builder().withOneOfValues(List.of(321, 322))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(123), new MetadataPolicy.Builder().withOneOfValues(List.of(321))
- .build())));
+ applier.apply(List.of(123), new MetadataPolicy.Builder().withOneOfValues(List.of(321))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(123), new MetadataPolicy.Builder().withOneOfValues(List.of(321, 322))
- .build())));
+ applier.apply(List.of(123), new MetadataPolicy.Builder().withOneOfValues(List.of(321, 322))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withOneOfValues(List.of(false))
- .build())));
+ applier.apply(true, new MetadataPolicy.Builder().withOneOfValues(List.of(false))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(false, new MetadataPolicy.Builder().withOneOfValues(List.of(true))
- .build())));
+ applier.apply(false, new MetadataPolicy.Builder().withOneOfValues(List.of(true))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(true), new MetadataPolicy.Builder().withOneOfValues(List.of(false))
- .build())));
+ applier.apply(List.of(true), new MetadataPolicy.Builder().withOneOfValues(List.of(false))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(false), new MetadataPolicy.Builder().withOneOfValues(List.of(true))
- .build())));
+ applier.apply(List.of(false), new MetadataPolicy.Builder().withOneOfValues(List.of(true))
+ .build()));
}
@Test
public void apply_whenSubsetOfMeetsValue_resultIsCandidateWithTrue() {
// single values
assertResultEquals(
- applier.apply(new Pair<>("existing", new MetadataPolicy.Builder().withSubsetOfValues(List.of(
- "existing")).build())),
+ applier.apply("existing", new MetadataPolicy.Builder().withSubsetOfValues(List.of(
+ "existing")).build()),
"existing");
assertResultEquals(
- applier.apply(new Pair<>("existing", new MetadataPolicy.Builder().withSubsetOfValues(List.of(
- "existing", "another")).build())),
+ applier.apply("existing", new MetadataPolicy.Builder().withSubsetOfValues(List.of(
+ "existing", "another")).build()),
"existing");
assertResultEquals(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withSubsetOfValues(List.of(123))
- .build())),
+ applier.apply(123, new MetadataPolicy.Builder().withSubsetOfValues(List.of(123))
+ .build()),
123);
assertResultEquals(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withSubsetOfValues(List.of(123, 321))
- .build())),
+ applier.apply(123, new MetadataPolicy.Builder().withSubsetOfValues(List.of(123, 321))
+ .build()),
123);
assertResultEquals(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withSubsetOfValues(List.of(true))
- .build())),
+ applier.apply(true, new MetadataPolicy.Builder().withSubsetOfValues(List.of(true))
+ .build()),
true);
assertResultEquals(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withSubsetOfValues(List.of(true, false))
- .build())),
+ applier.apply(true, new MetadataPolicy.Builder().withSubsetOfValues(List.of(true, false))
+ .build()),
true);
// list of values
assertResultEquals(
- applier.apply(new Pair<>(List.of("existing", "another"),
- new MetadataPolicy.Builder().withSubsetOfValues(List.of("existing", "another")).build())),
+ applier.apply(List.of("existing", "another"),
+ new MetadataPolicy.Builder().withSubsetOfValues(List.of("existing", "another")).build()),
List.of("existing", "another"));
assertResultEquals(
- applier.apply(new Pair<>(List.of("existing", "another"),
+ applier.apply(List.of("existing", "another"),
new MetadataPolicy.Builder().withSubsetOfValues(List.of(
- "existing", "another", "yet_another")).build())),
+ "existing", "another", "yet_another")).build()),
List.of("existing", "another"));
assertResultEquals(
- applier.apply(new Pair<>(List.of(123, 321), new MetadataPolicy.Builder()
- .withSubsetOfValues(List.of(123, 321)).build())),
+ applier.apply(List.of(123, 321), new MetadataPolicy.Builder()
+ .withSubsetOfValues(List.of(123, 321)).build()),
List.of(123, 321));
assertResultEquals(
- applier.apply(new Pair<>(List.of(123, 321), new MetadataPolicy.Builder()
- .withSubsetOfValues(List.of(123, 321, 213)).build())),
+ applier.apply(List.of(123, 321), new MetadataPolicy.Builder()
+ .withSubsetOfValues(List.of(123, 321, 213)).build()),
List.of(123, 321));
assertResultEquals(
- applier.apply(new Pair<>(List.of(true), new MetadataPolicy.Builder().withSubsetOfValues(List.of(true))
- .build())),
+ applier.apply(List.of(true), new MetadataPolicy.Builder().withSubsetOfValues(List.of(true))
+ .build()),
List.of(true));
assertResultEquals(
- applier.apply(new Pair<>(List.of(true, false), new MetadataPolicy.Builder()
- .withSubsetOfValues(List.of(true, false)).build())),
+ applier.apply(List.of(true, false), new MetadataPolicy.Builder()
+ .withSubsetOfValues(List.of(true, false)).build()),
List.of(true, false));
}
@@ -345,91 +345,91 @@ public class DefaultMetadataPolicyEnforcerTest {
public void apply_whenSubsetOfNotMeetingValue_resultIsFalse() {
// single values
assertResultFalse(
- applier.apply(new Pair<>("not", new MetadataPolicy.Builder().withSubsetOfValues(List.of(
- "existing")).build())));
+ applier.apply("not", new MetadataPolicy.Builder().withSubsetOfValues(List.of(
+ "existing")).build()));
assertResultFalse(
- applier.apply(new Pair<>("not", new MetadataPolicy.Builder().withSubsetOfValues(List.of(
- "existing", "another")).build())));
+ applier.apply("not", new MetadataPolicy.Builder().withSubsetOfValues(List.of(
+ "existing", "another")).build()));
assertResultFalse(
- applier.apply(new Pair<>(321, new MetadataPolicy.Builder().withSubsetOfValues(List.of(123))
- .build())));
+ applier.apply(321, new MetadataPolicy.Builder().withSubsetOfValues(List.of(123))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withSubsetOfValues(List.of(223, 321))
- .build())));
+ applier.apply(123, new MetadataPolicy.Builder().withSubsetOfValues(List.of(223, 321))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withSubsetOfValues(List.of(false))
- .build())));
+ applier.apply(true, new MetadataPolicy.Builder().withSubsetOfValues(List.of(false))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(false, new MetadataPolicy.Builder().withSubsetOfValues(List.of(true))
- .build())));
+ applier.apply(false, new MetadataPolicy.Builder().withSubsetOfValues(List.of(true))
+ .build()));
// list of values
assertResultFalse(
- applier.apply(new Pair<>(List.of("not"),
- new MetadataPolicy.Builder().withSubsetOfValues(List.of("existing", "another")).build())));
+ applier.apply(List.of("not"),
+ new MetadataPolicy.Builder().withSubsetOfValues(List.of("existing", "another")).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of("not", "neither"),
+ applier.apply(List.of("not", "neither"),
new MetadataPolicy.Builder().withSubsetOfValues(List.of(
- "existing", "another", "yet_another")).build())));
+ "existing", "another", "yet_another")).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(123), new MetadataPolicy.Builder()
- .withSubsetOfValues(List.of(321, 432)).build())));
+ applier.apply(List.of(123), new MetadataPolicy.Builder()
+ .withSubsetOfValues(List.of(321, 432)).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(123, 321), new MetadataPolicy.Builder()
- .withSubsetOfValues(List.of(123, 213)).build())));
+ applier.apply(List.of(123, 321), new MetadataPolicy.Builder()
+ .withSubsetOfValues(List.of(123, 213)).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(true), new MetadataPolicy.Builder()
- .withSubsetOfValues(List.of(false)).build())));
+ applier.apply(List.of(true), new MetadataPolicy.Builder()
+ .withSubsetOfValues(List.of(false)).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(false), new MetadataPolicy.Builder()
- .withSubsetOfValues(List.of(true)).build())));
+ applier.apply(List.of(false), new MetadataPolicy.Builder()
+ .withSubsetOfValues(List.of(true)).build()));
}
@Test
public void apply_whenSupersetOfMeetsValue_resultIsCandidateWithTrue() {
// single values
assertResultEquals(
- applier.apply(new Pair<>("existing", new MetadataPolicy.Builder().withSupersetOfValues(List.of(
- "existing")).build())),
+ applier.apply("existing", new MetadataPolicy.Builder().withSupersetOfValues(List.of(
+ "existing")).build()),
"existing");
assertResultEquals(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withSupersetOfValues(List.of(123))
- .build())),
+ applier.apply(123, new MetadataPolicy.Builder().withSupersetOfValues(List.of(123))
+ .build()),
123);
assertResultEquals(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withSupersetOfValues(List.of(true))
- .build())),
+ applier.apply(true, new MetadataPolicy.Builder().withSupersetOfValues(List.of(true))
+ .build()),
true);
assertResultEquals(
- applier.apply(new Pair<>(false, new MetadataPolicy.Builder().withSupersetOfValues(List.of(false))
- .build())),
+ applier.apply(false, new MetadataPolicy.Builder().withSupersetOfValues(List.of(false))
+ .build()),
false);
// list of values
assertResultEquals(
- applier.apply(new Pair<>(List.of("existing", "another"),
- new MetadataPolicy.Builder().withSupersetOfValues(List.of("existing", "another")).build())),
+ applier.apply(List.of("existing", "another"),
+ new MetadataPolicy.Builder().withSupersetOfValues(List.of("existing", "another")).build()),
List.of("existing", "another"));
assertResultEquals(
- applier.apply(new Pair<>(List.of("existing", "another"),
+ applier.apply(List.of("existing", "another"),
new MetadataPolicy.Builder().withSupersetOfValues(List.of(
- "existing")).build())),
+ "existing")).build()),
List.of("existing", "another"));
assertResultEquals(
- applier.apply(new Pair<>(List.of(123, 321), new MetadataPolicy.Builder()
- .withSupersetOfValues(List.of(123, 321)).build())),
+ applier.apply(List.of(123, 321), new MetadataPolicy.Builder()
+ .withSupersetOfValues(List.of(123, 321)).build()),
List.of(123, 321));
assertResultEquals(
- applier.apply(new Pair<>(List.of(123, 321, 213), new MetadataPolicy.Builder()
- .withSupersetOfValues(List.of(123)).build())),
+ applier.apply(List.of(123, 321, 213), new MetadataPolicy.Builder()
+ .withSupersetOfValues(List.of(123)).build()),
List.of(123, 321, 213));
assertResultEquals(
- applier.apply(new Pair<>(List.of(true), new MetadataPolicy.Builder()
- .withSupersetOfValues(List.of(true)).build())),
+ applier.apply(List.of(true), new MetadataPolicy.Builder()
+ .withSupersetOfValues(List.of(true)).build()),
List.of(true));
assertResultEquals(
- applier.apply(new Pair<>(List.of(true, false), new MetadataPolicy.Builder()
- .withSupersetOfValues(List.of(false)).build())),
+ applier.apply(List.of(true, false), new MetadataPolicy.Builder()
+ .withSupersetOfValues(List.of(false)).build()),
List.of(true, false));
}
@@ -437,69 +437,69 @@ public class DefaultMetadataPolicyEnforcerTest {
public void apply_whenSupersetOfNotMeetingValue_resultIsFalse() {
// single values
assertResultFalse(
- applier.apply(new Pair<>("not", new MetadataPolicy.Builder().withSupersetOfValues(List.of(
- "existing")).build())));
+ applier.apply("not", new MetadataPolicy.Builder().withSupersetOfValues(List.of(
+ "existing")).build()));
assertResultFalse(
- applier.apply(new Pair<>("not", new MetadataPolicy.Builder().withSupersetOfValues(List.of(
- "existing", "another")).build())));
+ applier.apply("not", new MetadataPolicy.Builder().withSupersetOfValues(List.of(
+ "existing", "another")).build()));
assertResultFalse(
- applier.apply(new Pair<>(321, new MetadataPolicy.Builder().withSupersetOfValues(List.of(123))
- .build())));
+ applier.apply(321, new MetadataPolicy.Builder().withSupersetOfValues(List.of(123))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(123, new MetadataPolicy.Builder().withSupersetOfValues(List.of(223, 321))
- .build())));
+ applier.apply(123, new MetadataPolicy.Builder().withSupersetOfValues(List.of(223, 321))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(true, new MetadataPolicy.Builder().withSupersetOfValues(List.of(false))
- .build())));
+ applier.apply(true, new MetadataPolicy.Builder().withSupersetOfValues(List.of(false))
+ .build()));
assertResultFalse(
- applier.apply(new Pair<>(false, new MetadataPolicy.Builder().withSupersetOfValues(List.of(true))
- .build())));
+ applier.apply(false, new MetadataPolicy.Builder().withSupersetOfValues(List.of(true))
+ .build()));
// list of values
assertResultFalse(
- applier.apply(new Pair<>(List.of("not"),
- new MetadataPolicy.Builder().withSupersetOfValues(List.of("not", "another")).build())));
+ applier.apply(List.of("not"),
+ new MetadataPolicy.Builder().withSupersetOfValues(List.of("not", "another")).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of("not", "neither"),
+ applier.apply(List.of("not", "neither"),
new MetadataPolicy.Builder().withSupersetOfValues(List.of(
- "not", "neither", "another")).build())));
+ "not", "neither", "another")).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(123), new MetadataPolicy.Builder()
- .withSupersetOfValues(List.of(123, 321)).build())));
+ applier.apply(List.of(123), new MetadataPolicy.Builder()
+ .withSupersetOfValues(List.of(123, 321)).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(123, 321), new MetadataPolicy.Builder()
- .withSupersetOfValues(List.of(123, 321, 213)).build())));
+ applier.apply(List.of(123, 321), new MetadataPolicy.Builder()
+ .withSupersetOfValues(List.of(123, 321, 213)).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(true), new MetadataPolicy.Builder()
- .withSupersetOfValues(List.of(false)).build())));
+ applier.apply(List.of(true), new MetadataPolicy.Builder()
+ .withSupersetOfValues(List.of(false)).build()));
assertResultFalse(
- applier.apply(new Pair<>(List.of(false), new MetadataPolicy.Builder()
- .withSupersetOfValues(List.of(true, false)).build())));
+ applier.apply(List.of(false), new MetadataPolicy.Builder()
+ .withSupersetOfValues(List.of(true, false)).build()));
}
@Test
public void apply_whenRegexMeetsValue_resultIsCandidateWithTrue() {
final String candidate = "https://sub.example.org/cb";
- assertResultEquals(applier.apply(new Pair<>(candidate,
- new MetadataPolicy.Builder().withRegexp(".*").build())), candidate);
- assertResultEquals(applier.apply(new Pair<>(candidate,
- new MetadataPolicy.Builder().withRegexp("^https:\\/\\/(?:([^.]+)\\.)?example\\.org\\/(.*)").build())),
+ assertResultEquals(applier.apply(candidate,
+ new MetadataPolicy.Builder().withRegexp(".*").build()), candidate);
+ assertResultEquals(applier.apply(candidate,
+ new MetadataPolicy.Builder().withRegexp("^https:\\/\\/(?:([^.]+)\\.)?example\\.org\\/(.*)").build()),
candidate);
final List<String> candidates = List.of(candidate + "1", candidate + "2");
- assertResultEquals(applier.apply(new Pair<>(candidates,
- new MetadataPolicy.Builder().withRegexp("^https:\\/\\/(?:([^.]+)\\.)?example\\.org\\/(.*)").build())),
+ assertResultEquals(applier.apply(candidates,
+ new MetadataPolicy.Builder().withRegexp("^https:\\/\\/(?:([^.]+)\\.)?example\\.org\\/(.*)").build()),
candidates);
}
@Test
public void apply_whenRegexNotMeetingValue_resultIsFalse() {
final String regex = "^https:\\/\\/(?:([^.]+)\\.)?example\\.org\\/(.*)";
- assertResultFalse(applier.apply(new Pair<>("http://example.org/cb",
- new MetadataPolicy.Builder().withRegexp(regex).build())));
- assertResultFalse(applier.apply(new Pair<>("https://example.com/cb",
- new MetadataPolicy.Builder().withRegexp(regex).build())));
- assertResultFalse(applier.apply(new Pair<>(List.of("https://sub.example.org/cb", "https://sub.example.com/cb"),
- new MetadataPolicy.Builder().withRegexp(regex).build())));
+ assertResultFalse(applier.apply("http://example.org/cb",
+ new MetadataPolicy.Builder().withRegexp(regex).build()));
+ assertResultFalse(applier.apply("https://example.com/cb",
+ new MetadataPolicy.Builder().withRegexp(regex).build()));
+ assertResultFalse(applier.apply(List.of("https://sub.example.org/cb", "https://sub.example.com/cb"),
+ new MetadataPolicy.Builder().withRegexp(regex).build()));
}
public static void assertResultEquals(final Pair<Object, Boolean> pair, final Object expected) {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list