Add a configuration option for ignoring expirations.
This commit is contained in:
Родитель
8a473b6d00
Коммит
f5d650894b
|
@ -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") }
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче