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

Commit e24bbb6

Browse files
Updating NSS integration tests lib build logic
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.
1 parent f58ac45 commit e24bbb6

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

debian/rules

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ export DPKG_GENSYMBOLS_CHECK_LEVEL := 4
1212
# Copy in build directory all content to embed
1313
export DH_GOLANG_INSTALL_ALL := 1
1414

15-
# The NSS integration tests require building the Rust lib, which turns to crates.io by default.
16-
# Since specifying the --offline flag also does not work, we must skip the integration tests when
17-
# building the package.
18-
export AAD_SKIP_INTEGRATION_TESTS := 1
19-
2015
# The following definitions are necessary because of the manual steps
2116
# we need to do to work around some issues with either dh-cargo,
2217
# the wrapper, or cargo
@@ -68,6 +63,14 @@ override_dh_auto_build:
6863

6964
override_dh_auto_test:
7065
dh_auto_test --buildsystem=cargo -- test --all
66+
67+
# We need to specify these Rust related variables to the Go tests in order to build the NSS lib
68+
# with the cargo wrapper in the integration tests in order to force cargo to use vendored deps
69+
# instead of querying crates.io for them.
70+
DEB_HOST_GNU_TYPE=$(DEB_HOST_GNU_TYPE) \
71+
DEB_HOST_RUST_TYPE=$(DEB_HOST_RUST_TYPE) \
72+
CARGO_HOME=$(CURDIR)/debian/cargo_home \
73+
CARGO_PATH=$(CARGO) \
7174
dh_auto_test
7275

7376
override_dh_auto_install:

nss/integration-tests/helper_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"testing"
1212
)
1313

14-
var libPath string
14+
var targetDir, libPath string
1515

1616
// outNSSCommandForLib returns the specific part for the nss command, filtering originOut.
1717
// It uses the locally build aad nss module for the integration tests.
@@ -65,19 +65,23 @@ func buildRustNSSLib() error {
6565
return err
6666
}
6767
// Builds the nss library.
68-
args := []string{"build", "--features", "integration-tests"}
69-
cmd := exec.Command("cargo", args...)
68+
args := []string{"build", "--verbose", "--features", "integration-tests", "--target-dir", targetDir}
69+
70+
cargo := os.Getenv("CARGO_PATH")
71+
if cargo == "" {
72+
cargo = "cargo"
73+
}
74+
// #nosec:G204 - we control the command arguments in tests
75+
cmd := exec.Command(cargo, args...)
7076
cmd.Dir = aadPath
7177
if out, err := cmd.CombinedOutput(); err != nil {
7278
return fmt.Errorf("could not build rust nss library (%s): %w", out, err)
7379
}
80+
targetDir = filepath.Join(targetDir, os.Getenv("DEB_HOST_RUST_TYPE"))
7481

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

nss/integration-tests/integration_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,14 @@ func TestIntegration(t *testing.T) {
153153
}
154154

155155
func TestMain(m *testing.M) {
156-
if os.Getenv("AAD_SKIP_INTEGRATION_TESTS") != "" {
157-
fmt.Println("Integration tests skipped as requested")
158-
return
159-
}
160-
161156
// Build the NSS library and executable in a temporary directory and allow linking to it.
162157
tmpDir, cleanup, err := createTempDir()
163158
if err != nil {
164159
os.Exit(1)
165160
}
166161
defer cleanup()
167162

168-
libPath = filepath.Join(tmpDir, "libnss_aad.so.2")
163+
targetDir, libPath = tmpDir, filepath.Join(tmpDir, "libnss_aad.so.2")
169164
// Builds the NSS Library.
170165
if err = buildRustNSSLib(); err != nil {
171166
cleanup()

0 commit comments

Comments
 (0)