Add a configuration option for ignoring expirations.

This commit is contained in:
Chris Gavin 2022-09-02 14:10:49 +01:00
Родитель 8a473b6d00
Коммит f5d650894b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 07F950B80C27E4DA
4 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -213,6 +213,7 @@ module Entitlements
# Returns true if expired, false if not expired.
Contract C::Or[nil, String], String => C::Or[nil, C::Bool]
def expired?(expiration, context)
return false if Entitlements.config.fetch("ignore_expirations", false)
return false if expiration.nil? || expiration.strip.empty?
if expiration =~ /\A(\d{4})-(\d{2})-(\d{2})\z/
year, month, day = Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i

Просмотреть файл

@ -22,6 +22,7 @@ module Entitlements
# Return true if we made any changes, false otherwise.
Contract C::SetOf[Entitlements::Models::Person] => C::Bool
def modify(result)
return false if Entitlements.config.fetch("ignore_expirations", false)
# If group is already empty, we have nothing to consider modifying, regardless
# of expiration date. Just return false right away.
if result.empty?

Просмотреть файл

@ -31,6 +31,16 @@ describe Entitlements::Data::Groups::Calculated::Modifiers::Expiration do
obj = Entitlements::Data::Groups::Calculated.read("cn=expired-text,ou=Felines,ou=Groups,dc=example,dc=net")
expect(obj.members).to eq(Set.new)
end
it "returns members if expiration is disabled in the configuration" do
Entitlements.config["ignore_expirations"] = true
allow(Entitlements::Util::Util).to receive(:path_for_group).with(ou_key).and_return(fixture("ldap-config/#{ou_key}"))
Entitlements::Data::Groups::Calculated.read_all(ou_key, cfg_obj)
obj = Entitlements::Data::Groups::Calculated.read("cn=expired-text,ou=Felines,ou=Groups,dc=example,dc=net")
expected_result = %w[russianblue mainecoon]
answer_set = Set.new(expected_result.map { |name| people_obj.read[name] })
expect(obj.members).to eq(answer_set)
end
end
context "expired text file with no valid non-expired conditions" do

Просмотреть файл

@ -438,6 +438,23 @@ describe Entitlements::Data::Groups::Calculated::Text do
end
end
context "already expired but expirations are disabled" do
let(:filename) { fixture("ldap-config/text/expiration-already-expired.txt") }
it "constructs the correct rule set" do
Entitlements.config["ignore_expirations"] = true
answer = {
"or" => [
{ "username" => "blackmanx" },
{ "username" => "russianblue" },
{ "username" => "mainecoon" }
]
}
result = subject.send(:rules)
expect(result).to eq(answer)
end
end
context "mix of not expired and already expired" do
let(:filename) { fixture("ldap-config/text/expiration-mixed-expired.txt") }