Skip to content
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 @@ -143,8 +143,9 @@ private LDContext BuildSingleContext(Map<String, Value> attributes, String kind,
ContextBuilder builder = LDContext.builder(ContextKind.of(kind), key);

attributes.forEach((attrKey, attrValue) -> {
// Key has been processed, so we can skip it.
if (Objects.equals(attrKey, "key") || Objects.equals(attrKey, "targetingKey")) return;
// Key and kind have been processed, so we can skip them.
if (Objects.equals(attrKey, "key") || Objects.equals(attrKey, "targetingKey")
|| Objects.equals(attrKey, "kind")) return;

if (Objects.equals(attrKey, "privateAttributes")) {
List<Value> valueList = attrValue.asList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,38 @@ public void itCanCreateAContextFromAKeyAndKind() {
assertFalse(logs().containsAnyLogs());
}

@Test
public void itIgnoresNestedKindInMultiKindContexts() {
for (Value nestedKind : new Value[]{new Value("user"), new Value("multi"), new Value(42)}) {
HashMap<String, Value> orgAttributes = new HashMap<>();
orgAttributes.put("key", new Value("org-key"));
orgAttributes.put("kind", nestedKind);
HashMap<String, Value> userAttributes = new HashMap<>();
userAttributes.put("key", new Value("user-key"));
HashMap<String, Value> attributes = new HashMap<>();
attributes.put("kind", new Value("multi"));
attributes.put("org", new Value(new ImmutableStructure(orgAttributes)));
attributes.put("user", new Value(new ImmutableStructure(userAttributes)));

LDContext converted = evaluationContextConverter.toLdContext(new ImmutableContext(attributes));

assertTrue(converted.isValid());
assertEquals(2, converted.getIndividualContextCount());
LDContext org = converted.getIndividualContext(ContextKind.of("org"));
assertNotNull(org);
assertEquals(ContextKind.of("org"), org.getKind());
assertEquals("org-key", org.getKey());
for (String attribute : org.getCustomAttributeNames()) {
assertNotEquals("kind", attribute);
}
assertEquals(LDContext.create("user-key"), converted.getIndividualContext(ContextKind.of("user")));
assertEquals(LDContext.createMulti(
LDContext.builder(ContextKind.of("org"), "org-key").build(),
LDContext.create("user-key")), converted);
assertFalse(logs().containsAnyLogs());
}
}

@Test
public void itLogsAnErrorWhenThereIsNoTargetingKey() {
evaluationContextConverter.toLdContext(new ImmutableContext());
Expand Down
Loading