6232 Commits

Author SHA1 Message Date
William Woodruff
09c12d817e
Revert "attestation: specialize error when gh is old" 2024-08-12 15:53:17 -04:00
William Woodruff
aafa81b3d9
Merge pull request #17926 from Homebrew/ww/gh-too-old 2024-08-12 15:28:36 -04:00
William Woodruff
be8ee6ea22
fixup attestation_spec
Signed-off-by: William Woodruff <william@yossarian.net>
2024-08-12 15:10:18 -04:00
Douglas Eichelberger
52b25d71f5 Make Cask::Artifact::Installer typesafe 2024-08-11 16:56:20 -07:00
apainintheneck
1fe16a5e35 Address feedback
- Move HOMEBREW_TAP_DIRECTORY to startup/config.rb because this file
holds more of the directory constants
- Rename `Commands.cmd_directories` to `Commands.tap_cmd_directories`
to better express that the commands come from taps

This file has the directory constants while the other one has regexes.
Just better organization.
2024-08-10 17:52:26 -07:00
apainintheneck
a3e917afe1 Refactor method to remove extra tap requires
We were selectively requiring the tap.rb file in a few places for
performance reasons. The main method we were referencing was the
`Tap.cmd_directories` method which uses `Pathname` and the `TAP_DIRECTORY`
constant internally. `Tap.cmd_directories` is mostly used in the `Commands`
module and that is loaded very early on in the program so it made sense
to move that command to that module. To facilitate that I moved the
`TAP_DIRECTORY` constant to the top-level and renamed it to
`HOMEBREW_TAP_DIRECTORY`. It now lies in the tap_constants.rb file.

A nice bonus of this refactor is that it speeds up loading external
commands since the tap.rb file is no longer required by default in
those cases.
2024-08-10 13:49:10 -07:00
Douglas Eichelberger
cefae82307 Fix tests 2024-08-10 11:20:53 -07:00
Markus Reiter
8e08a698d1
Merge pull request #17562 from reitermarkus/token-auditor
Share code between cask token and formula name audits.
2024-08-10 19:46:32 +02:00
Mike McQuaid
42a6b59de5
sbom: fix errors, improve reproducibility, tests.
- Remove/change data from bottle SBOM to avoid harming reproduciblity
- Add `schema_validation_errors` method to provide nicer test failures
- Add tests more tests for SBOM when bottling
- Cleanup SBOM tests to use more typical RSpec form and be DRYer
2024-08-08 09:34:32 +01:00
Bo Anderson
6b186f9874
Fix SBOM schema validation 2024-08-08 02:30:42 +01:00
Bo Anderson
040372fafa
Vendor SBOM schema 2024-08-07 18:00:53 +01:00
Patrick Linnane
5b8568defa
system_command_spec: specify exception
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2024-08-05 09:17:23 -07:00
Mike McQuaid
87fec6ca69
Merge pull request #17940 from HaraldNordgren/cask_deps 2024-08-05 13:53:04 +01:00
Mike McQuaid
1e560120a6
Merge pull request #17867 from branchvincent/std_npm_args 2024-08-05 08:52:07 +01:00
Issy Long
cb8769c2a0
rubocops/text: Allow bin interpolation inside word arrays
- We discovered that the following syntax in the formula `sqlsmith`
  should actually be OK because the `\n` is like whitespace.

```ruby
cmd = %W[
  #{bin}/sqlsmith
  --threads=4
  --timeout=10
]
shell_output(cmd)
```
2024-08-04 23:45:34 +01:00
Branch Vincent
1771bf1bbb
rubocops/lines: audit std_npm_args usage 2024-08-03 20:28:38 -07:00
Harald Nordgren
7cf5c2cdd9 Show dependencies for casks 2024-08-03 20:25:13 +02:00
Issy Long
7bf7030db8
Add autocorrection for the interpolated bin audit
- I got bored doing them manually.
- Also now more people can help with letters of the alphabet using `brew style --only=FormulaAuditStrict/Text --fix homebrew/core`.
2024-08-01 22:41:04 +01:00
Issy Long
0872966c27
Avoid double parentheses for eg. (path/here/).rmtree corrections 2024-08-01 18:28:01 +01:00
Issy Long
7404735654
rubocops/no_fileutils_rmrf: Fix rmtree on a method returning Pathname
- Tidy up the node matchers. Either `FileUtils.rm_rf` or `rm_rf` on a
  `Pathname` instance or `self`.
2024-08-01 18:28:01 +01:00
Issy Long
83e21fba11
rubocop/no_fileutils_rmrf: Handle rmtree as an instance method 2024-08-01 18:28:00 +01:00
Issy Long
0889df837a
Casks use FileUtils.rm_rf & Pathname.rmtree still 2024-08-01 18:28:00 +01:00
Issy Long
99c5cc99b5
rubocop/no_fileutils_rmrf: Scope to just formulae and casks 2024-08-01 18:28:00 +01:00
Issy Long
14dd3592dc
rubocop/no_fileutils_rmrf: Discourage Pathname#rmtree too
- This [seems to be](https://ruby-doc.org/3.3.4/exts/pathname/Pathname.html#method-i-rmtree)
  equivalent to `FileUtils#rm_r`, so replace it with that.
2024-08-01 18:28:00 +01:00
Issy Long
cc7784605d
rubocop/no_fileutils_rmrf: Reorganize tests 2024-08-01 18:28:00 +01:00
Issy Long
ebd9d183dc
rubocop/no_fileutils_rmrf: Extend to cover FileUtils#rmtree too 2024-08-01 18:28:00 +01:00
Issy Long
f4e4808553
rubocop/no_fileutils_rmrf: Extend to cover FileUtils#rm_f too 2024-08-01 18:28:00 +01:00
Issy Long
e6976ae3d1
rubocop: Discourage the use of FileUtils.rm_rf
- This cop checks for the use of `FileUtils.rm_rf` and suggests using
  `FileUtils.rm_r` because we should know if we couldn't delete a
  thing for some reason, not just force it.
2024-08-01 18:27:59 +01:00
William Woodruff
9d313b23eb
sandbox: disallow backslashes in path filter names
This should really be an allowlist rather than a denylist,
but for the time being this at least prevents someone from
causing an obtuse sandbox error by naming a file something like
"foo\".

Signed-off-by: William Woodruff <william@yossarian.net>
2024-07-31 12:10:51 -04:00
Markus Reiter
3b4e1cb573
Share code between cask token and formula name audits. 2024-07-30 21:41:15 +02:00
Mike McQuaid
e3a1a9dccf
Improve locking UX
My experience recently playing around with our locking behaviour is
that, while mostly seamless and not seen by users, it's leaks
implementation details a bit too heavily.

As a result, the following improvements are in this commit:
- Ensure that, whenever possible, we tell the user the actual command
  that is holding a given lock instead of the lock name (an internal
  implementation detail)
- Make the locking error output a little more consistent and user
  friendly
- Add a `DownloadLock` class to simplify locking downloads
- Add a `HOMEBREW_LOCK_CONTEXT` variable to allow adding additional
  context for logging error messages
- Lock paths and leave deciding how this translates to lock names up
  to the locking code itself
- Lock the Cellar/Caskroom paths explicitly rather than implicitly

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
2024-07-30 17:51:02 +01:00
William Woodruff
5e0e0d56af
attestation: remove gh version detection
I'm declaring bankruptcy on this entire approach:

1. We can attempt to match on versions, but this will fail
   when the version of `gh` installed is built from `HEAD`
   or similar.
2. We can match on dates instead (since `gh --version` also includes
   the date), but this is even more brittle + implies a support
   contract we don't actually have (we don't actually want
   to say we support random dated builds between public releases
   of `gh`).

This moves us back to a simpler approach: if `gh` is present,
we use it. If `gh` is not present, we attempt to install it
with `ensure_executable!`. If the user's `gh` is present but too old,
it'll fail during attestation verification with a reasonable error,
which IMO is fine for now since this is all still in beta.

Signed-off-by: William Woodruff <william@yossarian.net>
2024-07-29 13:13:55 -04:00
Issy Long
f0084e611a
rubocops/text: Allow all "#{bin}/foo" interpolated strings with spaces
- This was complaining about `shell_output("#{bin}/abricate-get_db --help 2>&1")` which it shouldn't have.
2024-07-28 17:18:35 +01:00
Mike McQuaid
7abc6f4349
cask/installer: improve *_FORBIDDEN_* env handling.
- Improve the error message when a cask or formula is forbidden by an
  environment variable (fixes #17880)
- Move the `forbidden_tap_check` and `forbidden_cask_and_formula_check`
  methods to the top of the `install` method, so that they are checked
  before the main cask is downloaded.
2024-07-27 16:13:51 +01:00
Branch Vincent
5304b70c92
rubocops/lines: remove existing npm audit 2024-07-26 05:41:57 -07:00
Issy Long
38bb463aad
Interpolated shell_output("#{bin}/foo -v"), for example, is fine
- This would be weird to change because it's a string not a pathname passed to `shell_output`.
- I had misunderstood https://github.com/Homebrew/brew/pull/17826#discussion_r1690806375.
2024-07-25 13:28:00 +01:00
Mike McQuaid
b31cfe8a85
Merge pull request #17840 from Homebrew/forbid-path-installs 2024-07-25 11:48:30 +01:00
Issy Long
ac973535ee
Merge pull request #17826 from Homebrew/no-interpolated-bin
rubocops/text: Enforce `bin/"formula"` instead of `"#{bin}/formula"`
2024-07-25 11:39:20 +01:00
Bo Anderson
10cbf191dc
Add env to disable finding packages from paths 2024-07-25 11:37:44 +01:00
Issy Long
a6596c969f
Test the shell_output single string edge case 2024-07-25 10:41:13 +01:00
Bo Anderson
a4b65647ae
Merge pull request #17844 from samford/version-loosen-debian-regex
version: loosen Debian orig tarball regex
2024-07-25 04:47:32 +01:00
Bo Anderson
38987be01f
cmd/--repository: fix homebrew- prefix handling 2024-07-25 01:42:53 +01:00
Issy Long
3713939e0d
rubocops/text: Include dashed binaries in bin/ interpolation check
- Previously this only included the formula name.
- But, for example in tests, we have "#{bin}/ansible-test",
  not just "#{bin}/ansible". So handle that too.
- I decided to make the error message better by extracting the
  binary name from the interpolation, but I'm not sure it was worth it.

```
$ brew audit --strict ansible
ansible
  * line 580, col 29: Use `bin/"ansible-test"` instead of `"#{bin}/ansible-test"`
Error: 1 problem in 1 formula detected.
```
2024-07-24 22:19:38 +01:00
Sam Ford
2cd95d482d
version: loosen Debian orig tarball regex
The regex to match Debian `orig` tarballs uses the standard regex for
versions like `1.2.3` but it won't match versions without a dot. The
`lcrack` formula uses a date-based version in the filename
(`lcrack_20040914.orig.tar.gz`) and `mkcue` uses a single number
(`mkcue_1.orig.tar.gz`), so we have to use a manual `version` in
these formulae.

This updates the regex to use the looser `NUMERIC_WITH_OPTIONAL_DOTS`
pattern, which will also match the aforementioned versions. I tested
this by checking versions of formulae before/after this change and
confirming that they remain the same after removing the `version`
calls from related formulae.
2024-07-24 11:39:09 -04:00
Bo Anderson
131b930d89
attestation: only fallback to backfill on 404 2024-07-23 16:59:52 +01:00
Issy Long
96400e01e1
rubocops/text: Enforce bin/"formula" instead of "#{bin}/formula" 2024-07-23 12:43:15 +01:00
Nanda H Krishna
45f853ef61
Merge pull request #17793 from Homebrew/fix-frozen-array-modification-errors
Avoid frozen array errors in `brew upgrade`
2024-07-19 09:58:57 -04:00
apainintheneck
5a37a77a7b Add tests for new sort_formulae_for_install method
These are integration tests but they should complete relatively
quickly anyway since we're not installing anything.
2024-07-18 21:38:43 -07:00
Bo Anderson
16d547b030
attestation: handle bad configurations better 2024-07-18 16:11:25 +01:00
Kevin
4aae003a1a
Merge pull request #17766 from Homebrew/fix-formula-uri-loader
FormulaURILoader: use regex to validate refs before attempting to cast
2024-07-17 20:07:17 -07:00