Add uid_mappings test - #3161
Conversation
|
Please check the failed CIs |
There was a problem hiding this comment.
Pull Request Overview
This PR adds tests to validate uid and gid mappings as part of issue #361, ensuring that the runtime specification correctly reflects the system's uid/gid mapping state. Key changes include:
- Adding a helper function to validate id mappings (uid/gid) in tests.
- Updating the test runner to include the "uid_mappings" test.
- Adding a new test suite for uid_mappings.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/contest/runtimetest/src/tests.rs | Added validate_id_mappings and validate_uid_mappings functions to check uid/gid mapping files. |
| tests/contest/runtimetest/src/main.rs | Included the uid_mappings test in the test selection logic. |
| tests/contest/contest/src/tests/uid_mappings/uid_mappings_test.rs | Added a new test suite for uid_mappings with spec creation and test execution. |
| tests/contest/contest/src/tests/uid_mappings/mod.rs | Exposes the uid_mappings test for integration with the overall test framework. |
| tests/contest/contest/src/tests/mod.rs | Registered the uid_mappings module as part of the tests. |
| tests/contest/contest/src/main.rs | Updated the test manager to include the uid_mappings test group. |
|
To correct the second embarrassing mistake, I re-committed and did a force push. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds tests for uid_mappings validation as described in issue #361. It introduces a new helper function (validate_id_mappings) in the runtime tests, updates the test executor to handle "uid_mappings", and creates an integration test for uid_mappings under the contest tests.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/contest/runtimetest/src/tests.rs | Adds validate_id_mappings and validate_uid_mappings to verify id mapping files |
| tests/contest/runtimetest/src/main.rs | Updates the test runner to include "uid_mappings" |
| tests/contest/contest/src/tests/uid_mappings/uid_mappings_test.rs | Provides a new test that creates a spec with uid and gid mappings |
| tests/contest/contest/src/tests/uid_mappings/mod.rs | Exposes the uid_mappings test group |
| tests/contest/contest/src/tests/mod.rs | Registers the uid_mappings test module |
| tests/contest/contest/src/main.rs | Includes uid_mappings in the execution of test groups |
1cc7c98 to
8fc4387
Compare
Signed-off-by: moz-sec <m0253c@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: moz-sec <m0253c@gmail.com>
Signed-off-by: moz-sec <m0253c@gmail.com>
8fc4387 to
049a251
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds tests for UID/GID mappings validation. The changes introduce a new function, validate_id_mappings, and integrate UID/GID mapping tests into both the runtime tests and contest test suites.
- Adds functions to validate UID/GID mappings in tests/contest/runtimetest/src/tests.rs.
- Updates main test dispatchers in tests/contest/runtimetest/src/main.rs and tests/contest/contest/src/main.rs.
- Adds a new uid_mappings test in tests/contest/contest/src/tests/uid_mappings/uid_mappings_test.rs and corresponding mod updates.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/contest/runtimetest/src/tests.rs | Introduces validate_id_mappings and validate_uid_mappings for UID/GID testing; potential issues with error messaging and index assumptions noted. |
| tests/contest/runtimetest/src/main.rs | Registers the new "uid_mappings" test. |
| tests/contest/contest/src/tests/uid_mappings/uid_mappings_test.rs | Adds a new test case for uid and gid mappings. |
| tests/contest/contest/src/tests/uid_mappings/mod.rs | Exposes the uid_mappings test group. |
| tests/contest/contest/src/main.rs | Updates test groups to include uid_mappings. |
Comments suppressed due to low confidence (1)
tests/contest/runtimetest/src/tests.rs:1014
- The loop iterating over the lines assumes that the number of lines exactly matches the count of expected_id_mappings, which may lead to an index out-of-bounds error. Consider checking that the lengths match before iterating or using a zip-based iteration to safely compare corresponding entries.
if !(actual_host_id == expected_id_mappings[i].host_id() && actual_container_id == expected_id_mappings[i].container_id() && actual_map_size == expected_id_mappings[i].size())
Signed-off-by: moz-sec <m0253c@gmail.com>
Signed-off-by: moz-sec <m0253c@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds tests for uid_mappings validation as described in #361 by implementing new validation functions and integrating them into both the runtime test suite and the contest test framework.
- Introduces validate_id_mappings and validate_uid_mappings functions in tests/contest/runtimetest/src/tests.rs.
- Updates main and contest test runners to register and execute the uid_mappings tests.
- Adds a new uid_mappings test module in tests/contest/contest/src/tests/uid_mappings.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/contest/runtimetest/src/tests.rs | Adds uid_mappings validation functions and necessary import updates. |
| tests/contest/runtimetest/src/main.rs | Registers uid_mappings test in the main test runner. |
| tests/contest/contest/src/tests/uid_mappings/uid_mappings_test.rs | Introduces a new uid_mappings test using LinuxIdMappingBuilder. |
| tests/contest/contest/src/tests/uid_mappings/mod.rs | Declares uid_mappings_test module and re-exports the test getter. |
| tests/contest/contest/src/tests/mod.rs | Registers uid_mappings test group in the contest tests module. |
| tests/contest/contest/src/main.rs | Integrates uid_mappings test group into the contest main runner. |
Comments suppressed due to low confidence (1)
tests/contest/contest/src/tests/uid_mappings/uid_mappings_test.rs:48
- [nitpick] Consider renaming the variable 'gid_mapping' to 'gid_mappings' to better reflect that it is a collection of mappings and to maintain consistency with 'uid_mappings'.
let gid_mapping = vec![LinuxIdMappingBuilder::default()
|
@utam0k |
| .typ(LinuxNamespaceType::User) | ||
| .build() | ||
| .unwrap(); | ||
| default_namespaces.push(userns); |
There was a problem hiding this comment.
This is obviously no longer default_namespaces.
There was a problem hiding this comment.
Are you saying that the variable name default_namespaces is not appropriate?
For example, does it mean that I should name the variable namespaces and push user namespaces?
There was a problem hiding this comment.
default_namespaces clearly has a different variable name and role at the time it is pushed.
Signed-off-by: moz-sec <m0253c@gmail.com>
Signed-off-by: moz-sec <m0253c@gmail.com>
|
Sorry, but this PR is in conflict. Could you check it? |
Signed-off-by: moz-sec <m0253c@gmail.com>
YJDoc2
left a comment
There was a problem hiding this comment.
couple of minor comments, but overall ok. Also when you're responding to these, can you rebase / merge main?
Signed-off-by: moz-sec <m0253c@gmail.com>
Signed-off-by: moz-sec <m0253c@gmail.com>
* add_uid_mappings test Signed-off-by: moz-sec <m0253c@gmail.com> * feat: handle multiple mappings Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: moz-sec <m0253c@gmail.com> * resolve borrowing issue with variable Signed-off-by: moz-sec <m0253c@gmail.com> * change the error message to match the process Signed-off-by: moz-sec <m0253c@gmail.com> * use zip to pair and compare expected_id_mappings and lines Signed-off-by: moz-sec <m0253c@gmail.com> * make all variable names common in uid/gid_mappings Signed-off-by: moz-sec <m0253c@gmail.com> * rename the variable Signed-off-by: moz-sec <m0253c@gmail.com> * delete unwanted comments Signed-off-by: moz-sec <m0253c@gmail.com> * fix: unwrap directly without using a match Signed-off-by: moz-sec <m0253c@gmail.com> * feat: randomize the numbers to be mapped Signed-off-by: moz-sec <m0253c@gmail.com> --------- Signed-off-by: moz-sec <m0253c@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description
This implements the uid_mappings validation in #361 .
I wrote it based on linux_uid_mappings.go from opencontainers/runtime-tools.
Type of Change
Testing
Related Issues
#361
Additional Context