-
Notifications
You must be signed in to change notification settings - Fork 6
tests: replace hardcoded test pool names with unique checksummed names #995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tasleson
wants to merge
1
commit into
snapshotmanager:main
Choose a base branch
from
tasleson:test_asset_names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/bin/bash | ||
| # snapm-test-name - generate and validate snapm test resource names | ||
| # | ||
| # Format: snapm_<subsystem>_<context>_<8 hex random>_<4 hex checksum> | ||
| # | ||
| # Usage: | ||
| # snapm-test-name generate <subsystem> <context> | ||
| # snapm-test-name validate <name> | ||
| # | ||
| # Subsystem: lm (LVM), st (Stratis) | ||
| # Context: vg, pool, lv, vol | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| _generate() { | ||
| local subsystem="$1" | ||
| local context="$2" | ||
| local random_hex | ||
| random_hex=$(od -An -tx1 -N4 /dev/urandom | tr -d ' \n') | ||
| local prefix="snapm_${subsystem}_${context}_${random_hex}" | ||
| local checksum | ||
| checksum=$(printf '%s' "$prefix" | sha256sum | cut -c1-4) | ||
| printf '%s_%s\n' "$prefix" "$checksum" | ||
| } | ||
|
|
||
| _validate() { | ||
| local name="$1" | ||
| if [ ${#name} -lt 6 ]; then | ||
| echo "INVALID: name too short" | ||
| return 1 | ||
| fi | ||
| local sep="${name: -5:1}" | ||
| if [ "$sep" != "_" ]; then | ||
| echo "INVALID: missing checksum separator" | ||
| return 1 | ||
| fi | ||
| local prefix="${name:0:${#name}-5}" | ||
| local embedded="${name: -4}" | ||
| local computed | ||
| computed=$(printf '%s' "$prefix" | sha256sum | cut -c1-4) | ||
| if [ "$embedded" = "$computed" ]; then | ||
| echo "VALID: $name" | ||
| return 0 | ||
| else | ||
| echo "INVALID: checksum mismatch (expected $computed, got $embedded)" | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| if [ $# -lt 2 ]; then | ||
| echo "Usage: $0 generate <subsystem> <context>" >&2 | ||
| echo " $0 validate <name>" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| case "$1" in | ||
| generate) | ||
| if [ $# -ne 3 ]; then | ||
| echo "Usage: $0 generate <subsystem> <context>" >&2 | ||
| exit 2 | ||
| fi | ||
| _generate "$2" "$3" | ||
| ;; | ||
| validate) | ||
| _validate "$2" | ||
| ;; | ||
| *) | ||
| echo "Unknown command: $1" >&2 | ||
| echo "Usage: $0 generate <subsystem> <context>" >&2 | ||
| echo " $0 validate <name>" >&2 | ||
| exit 2 | ||
| ;; | ||
| esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the ownership check match the advertised name format.
_validate_snapm_name()only verifies the trailing separator and checksum. Anysnapm_lm_*/snapm_st_*name with a matching 4-character suffix is therefore treated as test-owned, even if it does not followsnapm_<subsystem>_<context>_<8hex>_<4hex>. That is too loose for the destructivevgremove/stratis ... destroycalls below.Suggested tightening
_validate_snapm_name() { local name="$1" - if [ ${`#name`} -lt 6 ]; then - return 1 - fi - local sep="${name: -5:1}" - if [ "$sep" != "_" ]; then - return 1 - fi + [[ "$name" =~ ^snapm_[a-z0-9]+_[a-z0-9]+_[0-9a-f]{8}_[0-9a-f]{4}$ ]] || return 1 local prefix="${name:0:${`#name`}-5}" local embedded="${name: -4}" local computed computed=$(printf '%s' "$prefix" | sha256sum | cut -c1-4) [ "$embedded" = "$computed" ] }Please keep the equivalent validators in
tests/_util.pyandtests/bin/snapm-test-namealigned with this.🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we're trying to avoid is destroying something that the test didn't create. A human would have to create a name, then take the shasum of the same, grab the last 4 characters of the shasum and append it onto the end. I don't think any human would normally go through such a thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tasleson, that's a fair point — the checksum is already a strong enough ownership signal. The probability of a coincidentally matching 4-character SHA-256 suffix on a non-test name is ~1 in 65 536, and as you note, deliberately constructing such a name would require intentionally runningsha256sumon the prefix and appending the result — not something that happens by accident. The existing validation is sufficient for its purpose of guarding against accidental destruction of non-test resources. I'll withdraw my suggestion.( ˶ˆ꒳ˆ˵ )🐇
🧠 Learnings used