Skip to content

Auto install Cocoapods when Podfile.lock not exist#723

Open
attiasas wants to merge 18 commits into
jfrog:devfrom
attiasas:fix_cocoapods_auto_install
Open

Auto install Cocoapods when Podfile.lock not exist#723
attiasas wants to merge 18 commits into
jfrog:devfrom
attiasas:fix_cocoapods_auto_install

Conversation

@attiasas
Copy link
Copy Markdown
Collaborator

@attiasas attiasas commented Apr 12, 2026

  • The pull request is targeting the dev branch.
  • The code has been validated to compile successfully by running go vet ./....
  • The code has been formatted properly using go fmt ./....
  • All static analysis checks passed.
  • All tests have passed. If this feature is not already covered by the tests, new tests have been added.
  • Updated the Contributing page / ReadMe page / CI Workflow files if needed.
  • All changes are detailed at the description. if not already covered at JFrog Documentation, new documentation have been added.

Improvement(cocoapods): auto-install when Podfile.lock is missing

Summary
CocoaPods BOM / dependency-tree generation now detects a missing Podfile.lock and runs pod install (unless SkipAutoInstall is enabled), so audits can proceed without a pre-generated lockfile. CocoaPods test fixtures are reorganized under cocoapods-project, and a new cocoapods-no-lock-file sample project supports integration coverage. The hidden skip-auto-install flag documentation is generalized to reflect support beyond Yarn/NPM only.

Running 'pod install' command to install dependencies and may produce lock files in the scanned directory

Changes

  • sca/bom/buildinfo/technologies/cocoapods: After resolving the pod executable, if Podfile.lock is absent and auto-install is allowed, run pod install; if auto-install is skipped, return a clear error. Introduce descriptorFileName / lockFileName constants; split getPodExecPath from getPodVersionAndExecPath and improve version-check error wrapping (podcommand.go, cocoapods.go).
  • cli/docs/flags.go: Widen SkipAutoInstall help text to “some package managers.”
  • Tests / fixtures: Move existing Podfile / Podfile.lock under tests/testdata/.../cocoapods/cocoapods-project; add cocoapods-no-lock-file fixture (Podfile + minimal Xcode workspace files). Point unit tests at the new path (cocoapods_test.go). Add TestXrayAuditCocoapodsNoLockFile and parameterize testXrayAuditCocoapods by project name (audit_test.go).
  • git_test.go: Adjust expected violation applicability / scan counts in two JAS-related git audit tests.

Testing

  • TestXrayAuditCocoapods / TestXrayAuditCocoapodsNoLockFile (latter skipped on Windows in code), and full go test ./... / CI as usual.

Notes

  • Auto-install assumes a working pod on PATH and a suitable host toolchain (the new audit test skips on Windows for that reason). SkipAutoInstall preserves the previous strict behavior when no lockfile exists.
  • git_test.go expectation changes are included in this branch; confirm they match the intended Xray/JAS baseline for your environment if those tests are sensitive to server or graph versions.

@attiasas attiasas requested a review from a team April 12, 2026 07:01
@attiasas attiasas added the bug Something isn't working label Apr 12, 2026
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label Apr 12, 2026
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label Apr 13, 2026
Comment thread sca/bom/buildinfo/technologies/cocoapods/cocoapods.go Outdated
Comment thread sca/bom/buildinfo/technologies/cocoapods/cocoapods.go
Comment thread audit_test.go Outdated
Comment thread cli/docs/flags.go
@attiasas attiasas requested review from a team and orto17 May 11, 2026 08:36
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label May 11, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label May 11, 2026
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label May 19, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label May 19, 2026
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label May 27, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label May 27, 2026
@attiasas attiasas added the safe to test Approve running integration tests on a pull request label May 31, 2026
@github-actions github-actions Bot removed the safe to test Approve running integration tests on a pull request label May 31, 2026
@github-actions
Copy link
Copy Markdown

👍 Frogbot scanned this pull request and did not find any new security issues.


}
// Check if lock file exists, if not run 'pod install'
lockFilePath := filepath.Join(currentDir, lockFileName)
if _, err := os.Stat(lockFilePath); os.IsNotExist(err) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Error variable shadowing — permission errors silently swallowed
The os.Stat result uses := in an inner scope, so when Stat returns a non-IsNotExist error (e.g. permission denied), the else if err != nil branch reads the outer err (which is nil), silently dropping
the error. Fix by using a separate statErr variable.

packageName := filepath.Base(currentDir)
packageInfo := fmt.Sprintf("%s:%s", packageName, VersionForMainModule)
_, _, err = getPodVersionAndExecPath()
_, podExecPath, err := getPodVersionAndExecPath()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is used only inside the 'if' and if !SkipAutoInstall
we can call it inside the 'if' statement and spare the call if not required

// Check if lock file exists, if not run 'pod install'
lockFilePath := filepath.Join(currentDir, lockFileName)
if _, err := os.Stat(lockFilePath); os.IsNotExist(err) {
if params.SkipAutoInstall {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No unit tests for the new auto-install / SkipAutoInstall code paths. Yarn and NuGet both test SkipAutoInstall at the unit level; at minimum, add a test asserting ErrProjectNotInstalled is returned
when SkipAutoInstall: true and no lock file exists.


func GetDependenciesData(currentDir string) (string, error) {
_, err := os.Stat(filepath.Join(currentDir, "Podfile.lock"))
_, err := os.Stat(filepath.Join(currentDir, lockFileName))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this necessary? we called it and checked the existence of the lock file prior to the call to GetDependenciesData

Comment thread audit_test.go

func testXrayAuditCocoapods(t *testing.T, format format.OutputFormat) string {
_, cleanUp := securityTestUtils.CreateTestProjectEnvAndChdir(t, filepath.Join(filepath.FromSlash(securityTests.GetTestResourcesPath()), "projects", "package-managers", "cocoapods"))
func TestXrayAuditCocoapodsNoLockFile(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TestXrayAuditCocoapodsNoLockFile will fail noisily on Linux CI without CocoaPods — add a pod binary availability skip guard.

Copy link
Copy Markdown
Contributor

@eranturgeman eranturgeman left a comment

Choose a reason for hiding this comment

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

LGTM! see my comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Automatically generated release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants