Skip to content

Commit d8e34f8

Browse files
committed
osxkeychain: tests: uncleaned paths are preserved
Signed-off-by: Albin Kerouanton <[email protected]>
1 parent b1d5bf0 commit d8e34f8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

osxkeychain/osxkeychain_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,39 @@ func TestOSXKeychainHelperRetrieveAliases(t *testing.T) {
141141
}
142142
}
143143

144+
func TestOSXKeychainHelperStoreWithUncleanPath(t *testing.T) {
145+
helper := Osxkeychain{}
146+
creds := &credentials.Credentials{
147+
ServerURL: "https://::1:8080//////location/../../hello",
148+
Username: "testuser",
149+
Secret: "testsecret",
150+
}
151+
152+
// Clean store before and after the test.
153+
defer helper.Delete(creds.ServerURL)
154+
if err := helper.Delete(creds.ServerURL); err != nil && !credentials.IsErrCredentialsNotFound(err) {
155+
t.Errorf("prepare: failed to delete '%s': %v", creds.ServerURL, err)
156+
}
157+
158+
// Store the credentials
159+
if err := helper.Add(creds); err != nil {
160+
t.Fatalf("Error: failed to store credentials with unclean path %q: %s", creds.ServerURL, err)
161+
}
162+
163+
// Retrieve and verify credentials
164+
username, secret, err := helper.Get(creds.ServerURL)
165+
if err != nil {
166+
t.Fatalf("Error: failed to retrieve credentials with unclean path %q: %s", creds.ServerURL, err)
167+
}
168+
169+
if username != creds.Username {
170+
t.Errorf("Error: expected username %s, got %s", creds.Username, username)
171+
}
172+
if secret != creds.Secret {
173+
t.Errorf("Error: expected secret %s, got %s", creds.Secret, secret)
174+
}
175+
}
176+
144177
// TestOSXKeychainHelperRetrieveStrict verifies that only matching secrets are
145178
// returned.
146179
func TestOSXKeychainHelperRetrieveStrict(t *testing.T) {

0 commit comments

Comments
 (0)