Skip to content
Open
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
13 changes: 4 additions & 9 deletions lib/ldclient-openfeature/impl/context_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/impl/context_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading