Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions opam/Dockerfile
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/ /
Copy link
Copy Markdown
Collaborator

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.


# Set working directory
WORKDIR /app

# Default command: start bash so the container stays alive interactively
CMD ["/bin/bash"]
66 changes: 66 additions & 0 deletions opam/README.md
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
```
7 changes: 7 additions & 0 deletions opam/testdata/home/test/.opam/default/.opam-switch/install
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