Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter out unsupported policies #600

Merged
merged 3 commits into from
Nov 24, 2023
Merged
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
17 changes: 17 additions & 0 deletions spec/policies_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ describe LavinMQ::VHost do
definitions = {
"max-length" => JSON::Any.new(10_i64),
"alternate-exchange" => JSON::Any.new("dead-letters"),
"unsupported" => JSON::Any.new("unsupported"),
}
vhost = Server.vhosts.create("add_policy")

Expand Down Expand Up @@ -212,6 +213,22 @@ describe LavinMQ::VHost do
ch.queue_declare(q.name, passive: true)[:message_count].should eq 2
end
end

it "effective_policy_definition should not include unsupported policies" do
supported_policies = {"max-length", "max-length-bytes",
"message-ttl", "expires", "overflow",
"dead-letter-exchange", "dead-letter-routing-key",
"federation-upstream", "federation-upstream-set",
"delivery-limit", "max-age", "alternate-exchange",
"delayed-message"}
vhost.queues["test"] = LavinMQ::Queue.new(vhost, "test")
vhost.add_policy("test", "^.*$", "all", definitions, -10_i8)
sleep 0.01
vhost.queues["test"].details_tuple[:effective_policy_definition].as(Hash(String, JSON::Any)).each do |k, v|
supported_policies.includes?(k).should be_true
end
vhost.delete_policy("test")
end
end

describe "together with arguments" do
Expand Down
10 changes: 7 additions & 3 deletions src/lavinmq/policy.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module LavinMQ
end

class Policy
SUPPORTED_POLICIES = {"max-length", "max-length-bytes", "message-ttl", "expires", "overflow",
"dead-letter-exchange", "dead-letter-routing-key", "federation-upstream",
"federation-upstream-set", "delivery-limit", "max-age",
"alternate-exchange", "delayed-message"}
enum Target
All
Queues
Expand Down Expand Up @@ -67,15 +71,15 @@ module LavinMQ
merged[k] = v
end
end
merged
merged.select { |key, _| SUPPORTED_POLICIES.includes?(key) }
end

def self.merge_definitions(p1 : Nil, p2 : Policy) : Hash(String, JSON::Any)
p2.definition
p2.definition.select { |key, _| SUPPORTED_POLICIES.includes?(key) }
end

def self.merge_definitions(p1 : Policy, p2 : Nil) : Hash(String, JSON::Any)
p1.definition
p1.definition.select { |key, _| SUPPORTED_POLICIES.includes?(key) }
end

def self.merge_definitions(p1 : Nil, p2 : Nil) : Hash(String, JSON::Any)
Expand Down
Loading