diff --git a/lib/ldclient-rb/impl/context_filter.rb b/lib/ldclient-rb/impl/context_filter.rb index bec00400..3e8c9f6a 100644 --- a/lib/ldclient-rb/impl/context_filter.rb +++ b/lib/ldclient-rb/impl/context_filter.rb @@ -70,7 +70,7 @@ def filter_redact_anonymous(context) filtered[:anonymous] = true if anonymous redacted = [] - private_attributes = @private_attributes.concat(context.private_attributes) + private_attributes = @private_attributes + context.private_attributes name = context.get_value(:name) if !name.nil? && !check_whole_attribute_private(:name, private_attributes, redacted, anonymous && redact_anonymous) diff --git a/spec/impl/context_filter_spec.rb b/spec/impl/context_filter_spec.rb new file mode 100644 index 00000000..000849c9 --- /dev/null +++ b/spec/impl/context_filter_spec.rb @@ -0,0 +1,29 @@ +require "spec_helper" + +module LaunchDarkly + module Impl + describe ContextFilter do + it "does not apply per-context private attributes to later contexts" do + filter = ContextFilter.new(false, []) + private_context = LDContext.create({ kind: "user", key: "user-key", email: "email", _meta: { privateAttributes: ["email"] } }) + other_context = LDContext.create({ kind: "user", key: "other-key", email: "email" }) + + expect(filter.filter(private_context)[:_meta][:redactedAttributes]).to eq([:email]) + expect(filter.filter(other_context)).to eq({ key: "other-key", kind: "user", email: "email" }) + end + + it "does not apply private attributes of one kind to the other kinds of a multi-kind context" do + filter = ContextFilter.new(false, []) + context = LDContext.create_multi([ + LDContext.create({ kind: "user", key: "user-key", email: "email", _meta: { privateAttributes: ["email"] } }), + LDContext.create({ kind: "org", key: "org-key", email: "email" }), + ]) + + filtered = filter.filter(context) + + expect(filtered["user"][:_meta][:redactedAttributes]).to eq([:email]) + expect(filtered["org"]).to eq({ key: "org-key", email: "email" }) + end + end + end +end