Skip to content
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

Test umlaut passwords #60

Merged
merged 2 commits into from Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions keyring_darwin.go
Expand Up @@ -61,11 +61,10 @@ func (k macOSXKeychain) Get(service, username string) (string, error) {

// Set stores a secret in the keyring given a service name and a user.
func (k macOSXKeychain) Set(service, username, password string) error {
// if the added secret has multiple lines, osx will hex encode it
// identify this with a well-known prefix.
if strings.ContainsRune(password, '\n') {
password = encodingPrefix + hex.EncodeToString([]byte(password))
}
// if the added secret has multiple lines or some non ascii,
// osx will hex encode it on return. To avoid getting garbage, we
// encode all passwords
password = encodingPrefix + hex.EncodeToString([]byte(password))

return exec.Command(
execPathKeychain,
Expand Down
18 changes: 18 additions & 0 deletions keyring_test.go
Expand Up @@ -38,6 +38,24 @@ like osx`
}
}

// TestGetMultiline tests getting a multi-line password from the keyring
func TestGetUmlaut(t *testing.T) {
umlautPassword := "at least on OSX üöäÜÖÄß will be encoded"
err := Set(service, user, umlautPassword)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

pw, err := Get(service, user)
if err != nil {
t.Errorf("Should not fail, got: %s", err)
}

if umlautPassword != pw {
t.Errorf("Expected password %s, got %s", umlautPassword, pw)
}
}

// TestGetSingleLineHex tests getting a single line hex string password from the keyring.
func TestGetSingleLineHex(t *testing.T) {
hexPassword := "abcdef123abcdef123"
Expand Down