spec/event_serializer_spec.rb in ldclient-rb-2.3.2 vs spec/event_serializer_spec.rb in ldclient-rb-2.4.0
- old
+ new
@@ -17,10 +17,18 @@
u = user.clone
u[:privateAttributeNames] = [ 'dizzle', 'unused' ]
u
}
+ let(:user_with_unknown_top_level_attrs) {
+ { key: 'abc', firstName: 'Sue', species: 'human', hatSize: 6, custom: { bizzle: 'def', dizzle: 'ghi' }}
+ }
+
+ let(:anon_user) {
+ { key: 'abc', anonymous: 'true', custom: { bizzle: 'def', dizzle: 'ghi' }}
+ }
+
# expected results from serializing user
let(:user_with_all_attrs_hidden) {
{ key: 'abc', custom: { }, privateAttrs: [ 'bizzle', 'dizzle', 'firstName' ]}
}
@@ -31,11 +39,15 @@
let(:user_with_own_specified_attr_hidden) {
{ key: 'abc', firstName: 'Sue', custom: { bizzle: 'def' }, privateAttrs: [ 'dizzle' ]}
}
+ let(:anon_user_with_all_attrs_hidden) {
+ { key: 'abc', anonymous: 'true', custom: { }, privateAttrs: [ 'bizzle', 'dizzle' ]}
+ }
+
def make_event(user)
{
creationDate: 1000000,
key: 'xyz',
kind: 'thing',
@@ -79,8 +91,22 @@
it "looks at both per-user privateAttrs and global config" do
es = LaunchDarkly::EventSerializer.new(config_with_some_attrs_private)
event = make_event(user_specifying_own_private_attr)
j = es.serialize_events([event])
expect(parse_results(j)).to eq [make_event(user_with_all_attrs_hidden)]
+ end
+
+ it "strips out any unknown top-level attributes" do
+ es = LaunchDarkly::EventSerializer.new(base_config)
+ event = make_event(user_with_unknown_top_level_attrs)
+ j = es.serialize_events([event])
+ expect(parse_results(j)).to eq [make_event(user)]
+ end
+
+ it "leaves the anonymous attribute as is" do
+ es = LaunchDarkly::EventSerializer.new(config_with_all_attrs_private)
+ event = make_event(anon_user)
+ j = es.serialize_events([event])
+ expect(parse_results(j)).to eq [make_event(anon_user_with_all_attrs_hidden)]
end
end
end