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

cask/audit: allow the homepage https audit to have exceptions #12185

Merged
merged 5 commits into from Oct 22, 2021

Conversation

Rylan12
Copy link
Member

@Rylan12 Rylan12 commented Oct 4, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

This PR adds a cert_error_allowlist audit exception for the audit that checks HTTPS availability for cask homepages.

This list is designed to be used to allow audits to pass for the formulae affected by the Cloudflare issue we've been having.

CC: @bevanjkay and @GregBrimble

Corresponding homebrew/cask PR: Homebrew/homebrew-cask#112093 (can be merged in either order)

@BrewTestBot
Copy link
Member

Review period will end on 2021-10-05 at 23:30:17 UTC.

@Rylan12
Copy link
Member Author

Rylan12 commented Oct 5, 2021

The latest commit also refactors the tap_audit_exception methods that existed as (essentially) duplicates in formula_auditor.rb, utils/shared_audits.rb, and cask/audit.rb into a single method Tap#audit_exception. This required some other minor refactoring. I've tested almost all the lists and believe everything is still working as expected.

Library/Homebrew/cask/audit.rb Outdated Show resolved Hide resolved
@MikeMcQuaid
Copy link
Member

This PR adds a cert_error_allowlist audit exception for the audit that checks HTTPS availability for cask homepages.

This list is designed to be used to allow audits to pass for the formulae affected by the Cloudflare issue we've been having.

Code looks good to me! Might just want to name it something like homepage_audit_skiplist or something to make clearer what the code is doing (rather than the intent).

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Oct 6, 2021
@BrewTestBot
Copy link
Member

Review period ended.

@Rylan12
Copy link
Member Author

Rylan12 commented Oct 7, 2021

Thanks, good feedback. I haven't had free time to implement this yet and might not until the weekend, so apologies for the delay.

@Rylan12
Copy link
Member Author

Rylan12 commented Oct 18, 2021

Okay, I looked at this again but wasn't able to get the tests to work. The problem is that I've moved the logic that handles the exceptions to a Tap instance method to avoid needing to duplicate the method in Formula and Cask (and a third place that I'm blanking on). This makes the exception handling unreachable when {formula,cask}.tap is nil which makes sense. However, when the tests are run (primarily the dev-cmd/audit_spec.rb tests for FormulaAuditor) the generated formulae do not have a tap associated with them, so the exception list is never reached.

I tried a handful of things to trick the tests into thinking it has a tap so as not to mass-change a ton of tests but I think the solution is to change the logic to ensure that even these formulae have a tap associated (maybe test/tap or something like that to avoid weirdness with a CoreTap). I only briefly looked into this so I'll hopefully spend more time later fixing that up.

I'm on break this week (after Tuesday) so hopefully, I'll have some more time. I've found that I consistently have a lot less free time during the week than I expect so progress here has been a bit slow.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine without adding tests FWIW

@Rylan12
Copy link
Member Author

Rylan12 commented Oct 18, 2021

I think this is fine without adding tests FWIW

The problem is that it breaks existing tests (but because the tests no longer set the formula being tested up correctly rather than because this PR breaks functionality)

@MikeMcQuaid
Copy link
Member

Ah gotcha 😭

@Rylan12 Rylan12 force-pushed the cask-homepage-audit-exceptions branch from 78923d8 to 9ca0f68 Compare October 22, 2021 01:13
Comment on lines -67 to +76
described_class.new(Formulary.factory(path), options)
formula = Formulary.factory(path)

if options.key? :tap_audit_exceptions
tap = Tap.fetch("test/tap")
allow(tap).to receive(:audit_exceptions).and_return(options[:tap_audit_exceptions])
allow(formula).to receive(:tap).and_return(tap)
options.delete :tap_audit_exceptions
end

described_class.new(formula, options)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got the tests working!

For all of the formula_auditor tests, I've stubbed Formula#tap to return a test tap (test/tap) that contains the necessary exceptions.

@Rylan12 Rylan12 merged commit 55285e2 into Homebrew:master Oct 22, 2021
@Rylan12 Rylan12 deleted the cask-homepage-audit-exceptions branch October 22, 2021 14:55
@github-actions github-actions bot added the outdated PR was locked due to age label Nov 22, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants