Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #596 from ripienaar/595
Browse files Browse the repository at this point in the history
(#595) switch to using json format by default
  • Loading branch information
ripienaar authored Aug 30, 2019
2 parents 2582ccd + 913b54d commit 4e6220c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/mcollective/security/choria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def deserialize(string, format=:json)
#
# @return [Symbol]
def default_serializer
@config.pluginconf.fetch("choria.security.serializer", "yaml").downcase.intern
@config.pluginconf.fetch("choria.security.serializer", "json").downcase.intern
end

# The path where a server caches client certificates
Expand Down
15 changes: 11 additions & 4 deletions spec/unit/mcollective/security/choria_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ module MCollective

describe "#default_serializer" do
it "should default to yaml" do
expect(security.default_serializer).to be(:yaml)
expect(security.default_serializer).to be(:json)
end

it "should support JSON" do
it "should support YAML" do
Config.instance.expects(:pluginconf).returns(
"choria.security.serializer" => "JSON"
"choria.security.serializer" => "YAML"
)

expect(security.default_serializer).to be(:json)
expect(security.default_serializer).to be(:yaml)
end
end

Expand Down Expand Up @@ -92,6 +92,7 @@ module MCollective

describe "#encoderequest" do
it "should produce a valid choria:secure:request:1" do
security.stubs(:default_serializer).returns(:yaml)
security.initiated_by = :client
choria.stubs(:client_private_key).returns(File.expand_path("spec/fixtures/rip.mcollective.key"))
choria.stubs(:client_public_cert).returns(File.expand_path("spec/fixtures/rip.mcollective.pem"))
Expand Down Expand Up @@ -125,6 +126,7 @@ module MCollective

describe "#encodereply" do
it "should produce a valid choria:secure:reply:1" do
security.stubs(:default_serializer).returns(:yaml)
encoded = security.encodereply("rspec_agent", "rspec message", "123")

reply = JSON.parse(encoded)
Expand Down Expand Up @@ -191,6 +193,7 @@ module MCollective
end

it "should fail for invalid protocol messages" do
security.stubs(:default_serializer).returns(:yaml)
security.expects(:valid_protocol?).with({}, "choria:request:1", security.empty_request).returns(false)
security.expects(:valid_protocol?).with({}, "mcollective:request:3", security.empty_request).returns(false)

Expand All @@ -200,6 +203,7 @@ module MCollective
end

it "should return a valid legacy message" do
security.stubs(:default_serializer).returns(:yaml)
message = stub
secure = {
"message" => security.serialize(request, :yaml),
Expand Down Expand Up @@ -240,6 +244,7 @@ module MCollective
end

it "should support unserialized messages" do
security.stubs(:default_serializer).returns(:yaml)
request["message"] = {"rspec" => "message"}

message = stub
Expand All @@ -264,6 +269,7 @@ module MCollective
let(:reply) { security.empty_reply }

it "should return a valid legacy message" do
security.stubs(:default_serializer).returns(:yaml)
serialized_reply = security.serialize(reply, :yaml)

message = {
Expand All @@ -277,6 +283,7 @@ module MCollective
end

it "should fail for invalid protocol messages" do
security.stubs(:default_serializer).returns(:yaml)
security.expects(:valid_protocol?).with({}, "mcollective:reply:3", security.empty_reply).returns(false)
security.expects(:valid_protocol?).with({}, "choria:reply:1", security.empty_reply).returns(false)

Expand Down

0 comments on commit 4e6220c

Please sign in to comment.