diff --git a/debian/rules b/debian/rules index 65917257..b83d15c3 100755 --- a/debian/rules +++ b/debian/rules @@ -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 @@ -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: diff --git a/nss/integration-tests/helper_test.go b/nss/integration-tests/helper_test.go index 5e36fd31..461b42dc 100644 --- a/nss/integration-tests/helper_test.go +++ b/nss/integration-tests/helper_test.go @@ -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. @@ -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 } diff --git a/nss/integration-tests/integration_test.go b/nss/integration-tests/integration_test.go index 5f28a20c..263bff7d 100644 --- a/nss/integration-tests/integration_test.go +++ b/nss/integration-tests/integration_test.go @@ -153,11 +153,6 @@ 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 { @@ -165,7 +160,7 @@ func TestMain(m *testing.M) { } 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()