Skip to content

Commit

Permalink
Merge pull request #442 from cedarcode/sr--fix-serializer
Browse files Browse the repository at this point in the history
Fix JSON Serializer generating json with attributes with a null value
  • Loading branch information
brauliomartinezlm authored Nov 14, 2024
2 parents ad5e5ff + 99e9e4f commit e76d35c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/webauthn/json_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def to_hash_with_camelized_keys
attributes.each_with_object({}) do |attribute_name, hash|
value = send(attribute_name)

if value.respond_to?(:as_json)
if value && value.respond_to?(:as_json)
hash[camelize(attribute_name)] = value.as_json
elsif value
hash[camelize(attribute_name)] = deep_camelize_keys(value)
Expand Down
8 changes: 4 additions & 4 deletions spec/webauthn/public_key_credential/creation_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@
[{ type: "public-key", alg: -7 }, { type: "public-key", alg: -37 }, { type: "public-key", alg: -257 }]
)
expect(hash[:timeout]).to eq(120_000)
expect(hash[:excludeCredentials]).to be_nil
expect(hash[:authenticatorSelection]).to be_nil
expect(hash[:attestation]).to be_nil
expect(hash[:extensions]).to eq({})
expect(hash[:challenge]).to be_truthy
expect(hash[:extensions]).to eq({})
expect(hash).not_to have_key(:excludeCredentials)
expect(hash).not_to have_key(:authenticatorSelection)
expect(hash).not_to have_key(:attestation)
end

it "accepts shorthand for exclude_credentials" do
Expand Down
4 changes: 2 additions & 2 deletions spec/webauthn/public_key_credential/request_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@

hash = options.as_json

expect(hash[:rpId]).to be_nil
expect(hash[:timeout]).to eq(120_000)
expect(hash[:allowCredentials]).to eq([])
expect(hash[:userVerification]).to be_nil
expect(hash[:extensions]).to eq({})
expect(hash[:challenge]).to be_truthy
expect(hash).not_to have_key(:userVerification)
expect(hash).not_to have_key(:rpId)
end

it "accepts shorthand for allow_credentials" do
Expand Down

0 comments on commit e76d35c

Please sign in to comment.