Skip to content

Commit

Permalink
Merge pull request #60 from allcloud-jonathan/feature/umlaut-password…
Browse files Browse the repository at this point in the history
…-test

Test umlaut passwords
  • Loading branch information
szuecs committed Jul 28, 2021
2 parents 9725ced + 2379dd9 commit 46cefa2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
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

0 comments on commit 46cefa2

Please sign in to comment.