Skip to content

Commit

Permalink
chore(test): Fix expectations for condition strings in Cerbos 0.18 (#31)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Haines <[email protected]>
  • Loading branch information
haines authored Jun 16, 2022
1 parent 5dcbd6e commit f5393c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ AllCops:
RSpec/ExampleLength:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

RSpec/NestedGroups:
Enabled: false

Expand Down
14 changes: 12 additions & 2 deletions spec/cerbos/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:target) { "#{host}:#{port}" }
let(:host) { "localhost" }
let(:on_validation_error) { :return }
let(:cerbos_version) { ENV.fetch("CERBOS_VERSION") }

shared_examples "client" do
describe "#allow?" do
Expand Down Expand Up @@ -332,7 +333,12 @@
]
),
metadata: Cerbos::Output::PlanResources::Metadata.new(
condition_string: '(request.resource.attr.owner == "[email protected]")',
condition_string:
if cerbos_version_at_least?("0.18.0")
'(eq request.resource.attr.owner "[email protected]")'
else
'(request.resource.attr.owner == "[email protected]")'
end,
matched_scope: "test"
)
))
Expand All @@ -346,7 +352,7 @@
expect(response).to be_a(Cerbos::Output::ServerInfo).and(have_attributes(
built_at: an_instance_of(Time),
commit: a_string_matching(/\A[0-9a-f]{40}\z/),
version: ENV.fetch("CERBOS_VERSION")
version: cerbos_version
))
end
end
Expand Down Expand Up @@ -475,6 +481,10 @@
end
end

def cerbos_version_at_least?(version)
Gem::Version.new(cerbos_version) >= Gem::Version.new(version)
end

def read_pem(name)
File.read(File.expand_path("../../tmp/certificates/#{name}", __dir__))
end
Expand Down

0 comments on commit f5393c8

Please sign in to comment.