Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
Updating NSS integration tests lib build logic
Browse files Browse the repository at this point in the history
Instead of ignoring the tests during packaging, we can now override the
binary responsible to build the library.
This allows us to use the cargo wrapper (offered by dh-cargo) to build
the library offline, without automatically querying crates.io for the
dependencies.
  • Loading branch information
denisonbarbosa committed Feb 14, 2023
1 parent f58ac45 commit e24bbb6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
13 changes: 8 additions & 5 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export DPKG_GENSYMBOLS_CHECK_LEVEL := 4
# Copy in build directory all content to embed
export DH_GOLANG_INSTALL_ALL := 1

# The NSS integration tests require building the Rust lib, which turns to crates.io by default.
# Since specifying the --offline flag also does not work, we must skip the integration tests when
# building the package.
export AAD_SKIP_INTEGRATION_TESTS := 1

# The following definitions are necessary because of the manual steps
# we need to do to work around some issues with either dh-cargo,
# the wrapper, or cargo
Expand Down Expand Up @@ -68,6 +63,14 @@ override_dh_auto_build:

override_dh_auto_test:
dh_auto_test --buildsystem=cargo -- test --all

# We need to specify these Rust related variables to the Go tests in order to build the NSS lib
# with the cargo wrapper in the integration tests in order to force cargo to use vendored deps
# instead of querying crates.io for them.
DEB_HOST_GNU_TYPE=$(DEB_HOST_GNU_TYPE) \
DEB_HOST_RUST_TYPE=$(DEB_HOST_RUST_TYPE) \
CARGO_HOME=$(CURDIR)/debian/cargo_home \
CARGO_PATH=$(CARGO) \
dh_auto_test

override_dh_auto_install:
Expand Down
22 changes: 13 additions & 9 deletions nss/integration-tests/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"
)

var libPath string
var targetDir, libPath string

// outNSSCommandForLib returns the specific part for the nss command, filtering originOut.
// It uses the locally build aad nss module for the integration tests.
Expand Down Expand Up @@ -65,19 +65,23 @@ func buildRustNSSLib() error {
return err
}
// Builds the nss library.
args := []string{"build", "--features", "integration-tests"}
cmd := exec.Command("cargo", args...)
args := []string{"build", "--verbose", "--features", "integration-tests", "--target-dir", targetDir}

cargo := os.Getenv("CARGO_PATH")
if cargo == "" {
cargo = "cargo"
}
// #nosec:G204 - we control the command arguments in tests
cmd := exec.Command(cargo, args...)
cmd.Dir = aadPath
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("could not build rust nss library (%s): %w", out, err)
}
targetDir = filepath.Join(targetDir, os.Getenv("DEB_HOST_RUST_TYPE"))

// Moves the compiled library to the expected path.
args = []string{filepath.Join(aadPath, "target", "debug", "libnss_aad.so"), libPath}
cmd = exec.Command("cp", args...)
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("could not copy the compiled rust nss library (%s): %w", out, err)
// Renames the compiled library to have the expected versioned name.
if err = os.Rename(filepath.Join(targetDir, "debug", "libnss_aad.so"), libPath); err != nil {
return fmt.Errorf("Setup: could not rename the Rust NSS library: %w", err)
}

return nil
}
7 changes: 1 addition & 6 deletions nss/integration-tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,14 @@ func TestIntegration(t *testing.T) {
}

func TestMain(m *testing.M) {
if os.Getenv("AAD_SKIP_INTEGRATION_TESTS") != "" {
fmt.Println("Integration tests skipped as requested")
return
}

// Build the NSS library and executable in a temporary directory and allow linking to it.
tmpDir, cleanup, err := createTempDir()
if err != nil {
os.Exit(1)
}
defer cleanup()

libPath = filepath.Join(tmpDir, "libnss_aad.so.2")
targetDir, libPath = tmpDir, filepath.Join(tmpDir, "libnss_aad.so.2")
// Builds the NSS Library.
if err = buildRustNSSLib(); err != nil {
cleanup()
Expand Down

0 comments on commit e24bbb6

Please sign in to comment.