Skip to content

Commit

Permalink
return only boolean on valid? method
Browse files Browse the repository at this point in the history
Signed-off-by: rishichawda <[email protected]>
  • Loading branch information
rishichawda committed Sep 16, 2021
1 parent c52c0fd commit 0049fca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/win32/certstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ def search(search_token)
# @param request[thumbprint<string>] of certificate
# @return [true, false] only true or false
def valid?(certificate_thumbprint, store_location: "", store_name: "")
cert_validate(certificate_thumbprint, store_location: store_location, store_name: store_name)
cert_validate(certificate_thumbprint, store_location: store_location, store_name: store_name).yield_self do |x|
if x.is_a?(TrueClass) || x.is_a?(FalseClass)
x
else
false
end
end
end

# To close and destroy pointer of open certificate store handler
Expand Down
2 changes: 2 additions & 0 deletions lib/win32/certstore/store_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def cert_validate(certificate_thumbprint, store_location:, store_name:)
thumbprint = update_thumbprint(certificate_thumbprint)
cert_pem = get_cert_pem(thumbprint, store_name: store_name, store_location: store_location)
cert_pem = format_pem(cert_pem)
return "Certificate not found" if cert_pem.empty?

verify_certificate(cert_pem)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/win32/unit/certstore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
before(:each) do
allow_any_instance_of(certbase).to receive(:get_cert_pem).and_return("")
end
it "returns Certificate not found" do
it "returns false" do
store = certstore.open(store_name)
expect(store.valid?(thumbprint)).to eql(false)
end
Expand Down

0 comments on commit 0049fca

Please sign in to comment.