Skip to content

Commit

Permalink
error if collection path is different than expected
Browse files Browse the repository at this point in the history
  • Loading branch information
nickatsegment committed Mar 31, 2021
1 parent 47a1d18 commit 1d6ce07
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libsecret.go
Expand Up @@ -56,6 +56,10 @@ func (e *secretsError) Error() string {

var errCollectionNotFound = errors.New("The collection does not exist. Please add a key first")

func (k *secretsKeyring) genCollectionPath() string {
return libsecret.DBusPath + "/collection/" + k.name
}

func (k *secretsKeyring) openSecrets() error {
session, err := k.service.Open()
if err != nil {
Expand All @@ -69,7 +73,7 @@ func (k *secretsKeyring) openSecrets() error {
return err
}

path := libsecret.DBusPath + "/collection/" + k.name
path := k.genCollectionPath()

for _, collection := range collections {
if string(collection.Path()) == path {
Expand Down Expand Up @@ -168,6 +172,10 @@ func (k *secretsKeyring) Set(item Item) error {
return err
}

if string(collection.Path()) != k.genCollectionPath() {
return fmt.Errorf("tried to create collection at path %s, but got %s", k.genCollectionPath(), string(collection.Path()))
}

k.collection = collection
}

Expand Down

0 comments on commit 1d6ce07

Please sign in to comment.