-
Notifications
You must be signed in to change notification settings - Fork 107
Add hostname and IP address validation for env #2207
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
Merged
portante
merged 1 commit into
distributed-system-analysis:main
from
portante:validate-hostname
Apr 10, 2021
Merged
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,11 @@ | ||
| +++ Running test-22 pbench-move-results --controller=bad_host_name.example.com | ||
| [error][1900-01-01T00:00:00.000000] Invalid controller: 'bad_host_name.example.com' | ||
| --- Finished test-22 pbench-move-results (status=1) | ||
| +++ pbench tree state | ||
| /var/tmp/pbench-test-utils/pbench | ||
| /var/tmp/pbench-test-utils/pbench/pbench.log | ||
| /var/tmp/pbench-test-utils/pbench/tmp | ||
| --- pbench tree state | ||
| +++ pbench.log file contents | ||
| [error][1900-01-01T00:00:00.000000] Invalid controller: 'bad_host_name.example.com' | ||
| --- pbench.log file contents |
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,13 @@ | ||
| +++ Running test-01 pbench-register-tool --name=mpstat --group=default --remote=invalid_remote.example.com,good.example.com,bad_remote.example.com | ||
| [error][1900-01-01T00:00:00.000000] Invalid remote specified: 'invalid_remote.example.com' | ||
| [error][1900-01-01T00:00:00.000000] Invalid remote specified: 'bad_remote.example.com' | ||
| --- Finished test-01 pbench-register-tool (status=1) | ||
| +++ pbench tree state | ||
| /var/tmp/pbench-test-utils/pbench | ||
| /var/tmp/pbench-test-utils/pbench/pbench.log | ||
| /var/tmp/pbench-test-utils/pbench/tmp | ||
| --- pbench tree state | ||
| +++ pbench.log file contents | ||
| [error][1900-01-01T00:00:00.000000] Invalid remote specified: 'invalid_remote.example.com' | ||
| [error][1900-01-01T00:00:00.000000] Invalid remote specified: 'bad_remote.example.com' | ||
| --- pbench.log file contents |
520 changes: 260 additions & 260 deletions
520
agent/util-scripts/gold/test-client-tool-meister/test-56.txt
Large diffs are not rendered by default.
Oops, something went wrong.
454 changes: 227 additions & 227 deletions
454
agent/util-scripts/gold/test-client-tool-meister/test-57.txt
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,20 @@ | ||
| #!/usr/bin/env python3 | ||
| """validate-hostname - validate the given hostname uses the proper syntax. | ||
|
|
||
| Exits with 0 on success, with 1 on failure, only emitting a message on stderr | ||
| if the argument is missing. | ||
| """ | ||
|
|
||
| import sys | ||
|
|
||
| from pbench.agent.utils import validate_hostname | ||
|
|
||
|
|
||
| try: | ||
| host_name = sys.argv[1] | ||
| except IndexError: | ||
| print("Missing host name argument", file=sys.stderr) | ||
| exit_val = 1 | ||
| else: | ||
| exit_val = validate_hostname(host_name) | ||
| sys.exit(exit_val) |
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,23 @@ | ||
| #!/usr/bin/env python3 | ||
| """validate-ipaddress - check the first argument to see if it is a valid IP | ||
| address (IPv4 or IPv6). Returns 0 on success, 1 if the IP address is not | ||
| valid, 2 if the IP address argument is missing, and 3 if an unexpected error | ||
| is encountered. No error message is emitted if the IP address is invalid. | ||
| """ | ||
|
|
||
| import ipaddress | ||
| import sys | ||
|
|
||
| try: | ||
| ipaddress.ip_address(sys.argv[1]) | ||
| except ValueError: | ||
| exit_val = 1 | ||
| except IndexError: | ||
| print("Missing IP address argument", file=sys.stderr) | ||
| exit_val = 2 | ||
| except Exception as exc: | ||
| print(f"Error processing IP address {sys.argv[1]}: {exc}", file=sys.stderr) | ||
| exit_val = 3 | ||
| else: | ||
| exit_val = 0 | ||
| sys.exit(exit_val) |
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,15 @@ | ||
| """Tests for validate_hostname | ||
| """ | ||
|
|
||
| from pbench.agent.utils import validate_hostname | ||
|
|
||
|
|
||
| def test_validate_hostname(): | ||
| assert validate_hostname("test") == 0 | ||
| assert validate_hostname("test.example.com") == 0 | ||
| assert validate_hostname("tes_t.example.com") == 1 | ||
portante marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert validate_hostname("test-.example.com") == 1 | ||
| assert validate_hostname("--run-label__") == 1 | ||
| assert validate_hostname("127.0.0.1") == 0 | ||
| assert validate_hostname("1270.0.0.1") == 0 | ||
| assert validate_hostname("2001:0db8:85a3:0000:0000:8a2e:0370:7334") == 0 | ||
portante marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.