-
Notifications
You must be signed in to change notification settings - Fork 3
storage: strip inline comments from .pub, .group and .keys files #20
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
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,74 @@ | ||
| open Passage | ||
|
|
||
| let test_config_lines content = | ||
| let tmpfile = Filename.temp_file "config_lines_test" ".txt" in | ||
| Fun.protect | ||
| (fun () -> | ||
| Out_channel.with_open_text tmpfile (fun oc -> output_string oc content); | ||
| let result = Storage.config_lines tmpfile in | ||
| List.iter (fun line -> Printf.printf "%S\n" line) result) | ||
| ~finally:(fun () -> Sys.remove tmpfile) | ||
|
|
||
| let%expect_test "empty lines are stripped" = | ||
| test_config_lines "alice\n\nbob\n\n\ncharlie\n"; | ||
| [%expect {| | ||
| "alice" | ||
| "bob" | ||
| "charlie" |}] | ||
|
|
||
| let%expect_test "full-line comments are stripped" = | ||
| test_config_lines "alice\n# this is a comment\nbob\n # indented comment\ncharlie\n"; | ||
| [%expect {| | ||
| "alice" | ||
| "bob" | ||
| "charlie" |}] | ||
|
|
||
| let%expect_test "inline comments are stripped" = | ||
| test_config_lines "alice # team lead\nbob#backup\ncharlie # ops\n"; | ||
| [%expect {| | ||
| "alice" | ||
| "bob" | ||
| "charlie" |}] | ||
|
|
||
| let%expect_test "leading and trailing whitespace is trimmed" = | ||
| test_config_lines " alice \n\tbob\t\n charlie \n"; | ||
| [%expect {| | ||
| "alice" | ||
| "bob" | ||
| "charlie" |}] | ||
|
|
||
| let%expect_test "whitespace + inline comments combined" = | ||
| test_config_lines " alice # lead \n bob # backup \n"; | ||
| [%expect {| | ||
| "alice" | ||
| "bob" |}] | ||
|
|
||
| let%expect_test "line that is only a comment after stripping" = | ||
| test_config_lines "# full comment\n # indented full comment\nalice\n"; | ||
| [%expect {| "alice" |}] | ||
|
|
||
| let%expect_test "nonexistent file returns empty list" = | ||
| let result = Storage.config_lines "/nonexistent/path/file.txt" in | ||
| List.iter (fun line -> Printf.printf "%S\n" line) result; | ||
| [%expect {| |}] | ||
|
|
||
| let%expect_test "empty file returns empty list" = | ||
| test_config_lines ""; | ||
| [%expect {| |}] | ||
|
|
||
| let%expect_test "file with only comments and whitespace" = | ||
| test_config_lines "# comment\n \n\n # another\n"; | ||
| [%expect {| |}] | ||
|
|
||
| let%expect_test "mixed: all features together" = | ||
| test_config_lines {|# header comment | ||
| alice # admin | ||
| bob | ||
| # separator | ||
|
|
||
| charlie # ops | ||
| |}; | ||
| [%expect {| | ||
| "alice" | ||
| "bob" | ||
| "charlie" |}] |
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,95 @@ | ||
| $ . ./setup_fixtures.sh | ||
|
|
||
| Test that config_lines correctly handles comments, empty lines, and whitespace | ||
| in .keys, .group, and .pub files. | ||
|
|
||
| === .keys files: empty lines, full-line comments, whitespace, and inline comments === | ||
|
|
||
| $ cat<<EOF > "$PASSAGE_DIR/secrets/00/.keys" | ||
| > # This is a full-line comment | ||
| > # Indented full-line comment | ||
| > | ||
| > bobby.bob # team lead | ||
| > robby.rob | ||
| > | ||
| > EOF | ||
| $ passage who 00 | ||
| bobby.bob | ||
| robby.rob | ||
|
|
||
| Create and decrypt a secret in the folder with the above .keys | ||
| $ passage get 00/secret1 | ||
| (00/secret1) secret: single line | ||
|
|
||
| === .group files: empty lines, full-line comments, whitespace, and inline comments === | ||
|
|
||
| $ cat<<EOF > "$PASSAGE_DIR/keys/commented.group" | ||
| > # group members | ||
| > | ||
| > robby.rob # admin | ||
| > tommy.tom # regular | ||
| > | ||
| > EOF | ||
| $ passage who @commented | ||
| robby.rob | ||
| tommy.tom | ||
|
|
||
| Use the commented group in a .keys file and verify it resolves correctly | ||
| $ cat<<EOF > "$PASSAGE_DIR/secrets/01/00/.keys" | ||
| > @commented | ||
| > EOF | ||
| $ passage who -f 01/00 | ||
| robby.rob | ||
| tommy.tom | ||
|
|
||
| === .pub files: inline comments should be stripped === | ||
|
|
||
| Create a .pub key file with an inline comment appended to the actual key | ||
| $ INLINE_PUB_USER="inline.pub.user" | ||
| $ INLINE_PUB_IDENTITY="$INLINE_PUB_USER.key" | ||
| $ age-keygen > "$INLINE_PUB_IDENTITY" 2> /dev/null | ||
| $ PUBKEY=$(age-keygen -y "$INLINE_PUB_IDENTITY") | ||
| $ echo "$PUBKEY # added 2025-01-01" > "$PASSAGE_DIR/keys/$INLINE_PUB_USER.pub" | ||
|
|
||
| The key should still work for encryption - inline comment must be stripped | ||
| $ cat<<EOF > "$PASSAGE_DIR/secrets/00/.keys" | ||
| > bobby.bob | ||
| > $INLINE_PUB_USER | ||
| > EOF | ||
| $ cat<<EOF | passage create 00/inline_pub_secret | ||
| > pub inline comment test | ||
| > EOF | ||
| $ PASSAGE_IDENTITY="$INLINE_PUB_IDENTITY" passage get 00/inline_pub_secret | ||
| pub inline comment test | ||
|
|
||
| === .pub files: leading/trailing whitespace should be trimmed === | ||
|
|
||
| $ WHITESPACE_USER="whitespace.pub.user" | ||
| $ WHITESPACE_IDENTITY="$WHITESPACE_USER.key" | ||
| $ age-keygen > "$WHITESPACE_IDENTITY" 2> /dev/null | ||
| $ WHITESPACE_PUBKEY=$(age-keygen -y "$WHITESPACE_IDENTITY") | ||
| $ echo " $WHITESPACE_PUBKEY " > "$PASSAGE_DIR/keys/$WHITESPACE_USER.pub" | ||
|
|
||
| $ cat<<EOF > "$PASSAGE_DIR/secrets/00/.keys" | ||
| > bobby.bob | ||
| > $WHITESPACE_USER | ||
| > EOF | ||
| $ cat<<EOF | passage create 00/whitespace_pub_secret | ||
| > whitespace pub test | ||
| > EOF | ||
| $ PASSAGE_IDENTITY="$WHITESPACE_IDENTITY" passage get 00/whitespace_pub_secret | ||
| whitespace pub test | ||
|
|
||
| === Mixed: all features together in a .keys file === | ||
|
|
||
| $ cat<<EOF > "$PASSAGE_DIR/secrets/00/.keys" | ||
| > # This is a full-line comment | ||
| > bobby.bob # primary | ||
| > | ||
| > # Another full-line comment | ||
| > robby.rob # secondary | ||
| > | ||
| > EOF | ||
| $ passage who 00 | ||
| bobby.bob | ||
| robby.rob |
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.
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.
no need for cram tests, unit tests are enough
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.
removed in latest version