-
Notifications
You must be signed in to change notification settings - Fork 46
Added testbed for opam, ocaml's package manager #189
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
Open
mzfr
wants to merge
2
commits into
google:main
Choose a base branch
from
mzfr:opam-testbed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| FROM ubuntu:22.04 | ||
|
|
||
| # Install bash explicitly (Ubuntu images usually have it, but to be safe) | ||
| RUN apt-get update && apt-get install -y bash && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Create opam default switch install path | ||
| RUN mkdir -p /home/test/.opam/default/.opam-switch | ||
|
|
||
| # App for putting scalibr binary inside the container | ||
| RUN mkdir -p /app | ||
|
|
||
| # Copy opam test data into the container | ||
| COPY testdata/ / | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Default command: start bash so the container stays alive interactively | ||
| CMD ["/bin/bash"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # OSV-Scalibr: opam (OCaml) Extractor | ||
|
|
||
| This directory contains the test Docker setup for testing OSV-Scalibr's opam extractor plugin. opam is the package manager for OCaml and stores installed package entries in a default switch install file. | ||
|
|
||
| ## Overview | ||
|
|
||
| The opam extractor enumerates installed OCaml packages by reading the default switch install file at: | ||
|
|
||
| ``` | ||
| ~/.opam/default/.opam-switch/install | ||
| ``` | ||
|
|
||
| Each entry is in the format `package-name.version` (one per line). | ||
|
|
||
| ## Test Data Contents | ||
|
|
||
| The testbed includes a sample install file with the following packages: | ||
|
|
||
| - `dune` v3.7.2 | ||
| - `ocamlfind` v1.9.6 | ||
| - `core_kernel` v0.15.1 | ||
| - `cohttp-lwt` v6.0.0 | ||
| - `ppx_deriving` v5.2.1 | ||
|
|
||
| ## Setup Instructions | ||
|
|
||
| ### Build the Docker Image | ||
|
|
||
| ```bash | ||
| cd security-testbeds/opam | ||
| docker build -t opam-test . | ||
| ``` | ||
|
|
||
| ### Run the Container | ||
|
|
||
| ```bash | ||
| docker run -it --rm -v $(pwd):/app opam-test | ||
| ``` | ||
|
|
||
| This will: | ||
| - Start an interactive bash session | ||
| - Mount the current directory as `/app` inside the container | ||
| - Allow you to place the `scalibr` binary in `/app` and run tests | ||
|
|
||
| ### Running OSV-Scalibr (inside container) | ||
|
|
||
| 1) Build or copy the `scalibr` binary to the current directory | ||
| 2) Inside the container, run: | ||
|
|
||
| ```bash | ||
| ./scalibr --extractors=ocaml/opam --result=opam_output.textproto --root=/ home/test/.opam/default/.opam-switch/install | ||
| ``` | ||
|
|
||
| ### Extracting Test Data to Host | ||
|
|
||
| If you want to run the extractor outside the container: | ||
|
|
||
| ```bash | ||
| docker run --rm -v $(pwd)/extracted_testdata:/output opam-test cp -r /home/test/.opam /output/ | ||
| ``` | ||
|
|
||
| Then on your host: | ||
|
|
||
| ```bash | ||
| ./scalibr --extractors=ocaml/opam --result=opam_output.textproto --root=$(pwd)/extracted_testdata .opam/default/.opam-switch/install | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # opam switch install list | ||
| dune.3.7.2 | ||
| ocamlfind.1.9.6 | ||
|
|
||
| core_kernel.0.15.1 # comment after entry | ||
| cohttp-lwt.6.0.0 | ||
| ppx_deriving.5.2.1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create this (or a similar) testdata file with actual ocaml package manager installation commands instead of hardcoding? That would be a better e2e test that SCALIBR is looking at the right lockfile format.