diff --git a/lib/ldclient-openfeature/impl/context_converter.rb b/lib/ldclient-openfeature/impl/context_converter.rb index e6621b9..736f3b7 100644 --- a/lib/ldclient-openfeature/impl/context_converter.rb +++ b/lib/ldclient-openfeature/impl/context_converter.rb @@ -121,17 +121,12 @@ def to_ld_context(context) @logger.error("The attribute 'anonymous' must be a boolean") next elsif k == 'privateAttributes' && v.is_a?(Array) - private_attributes = [] - v.each do |private_attribute| - unless private_attribute.is_a?(String) - @logger.error("'privateAttributes' must be an array of only string values") - next - end - - private_attributes << private_attribute + unless v.all?(String) + @logger.error("'privateAttributes' must be an array of only string values") + next end - context[:_meta] = { privateAttributes: private_attributes } unless private_attributes.empty? + context[:_meta] = { privateAttributes: v } unless v.empty? elsif k == 'privateAttributes' @logger.error("The attribute 'privateAttributes' must be an array") else diff --git a/spec/impl/context_converter_spec.rb b/spec/impl/context_converter_spec.rb index dade1f1..c69ff58 100644 --- a/spec/impl/context_converter_spec.rb +++ b/spec/impl/context_converter_spec.rb @@ -141,6 +141,16 @@ expect(log_output.string).to include("'privateAttributes' must be an array of only string values") end + + it "rejects the entire private attribute list when any entry is not a string" do + context = OpenFeature::SDK::EvaluationContext.new(key: "user-key", privateAttributes: ["email", true]) + + ld_context = context_converter.to_ld_context(context) + + expect(ld_context.valid?).to be(true) + expect(ld_context.private_attributes).to be_empty + expect(log_output.string).to include("ERROR", "'privateAttributes' must be an array of only string values") + end end describe "multi kind context" do