-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from ProtonMail/feat/improve-errors-key-selec…
…tion v2 API: Improve error messages for encryption key selection This PR enhances error messages by providing detailed explanations when key selection for encryption fails in the v2 API.
- Loading branch information
Showing
4 changed files
with
108 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -2075,3 +2075,37 @@ func TestAllowAllKeyFlagsWhenMissing(t *testing.T) { | |
t.Error("isValidCertificationKey must be true when InsecureAllowAllKeyFlagsWhenMissing is true") | ||
} | ||
} | ||
|
||
func TestEncryptionKeyError(t *testing.T) { | ||
// Make a master key. | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, err = entity.EncryptionKeyWithError(time.Unix(1405544146, 0), nil) | ||
if err == nil { | ||
t.Fatal("should fail") | ||
} | ||
if !strings.Contains(err.Error(), "no valid self signature found") { | ||
t.Fatal("wrong error") | ||
} | ||
|
||
entity.Subkeys[0].PublicKey.Version = 20 | ||
_, err = entity.EncryptionKeyWithError(time.Now(), nil) | ||
if err == nil { | ||
t.Fatal("should fail") | ||
} | ||
if !strings.Contains(err.Error(), "no valid binding signature found for subkey") { | ||
t.Fatal("wrong error") | ||
} | ||
|
||
entity.Subkeys = nil | ||
_, err = entity.EncryptionKeyWithError(time.Now(), nil) | ||
if err == nil { | ||
t.Fatal("should fail") | ||
} | ||
if !strings.Contains(err.Error(), "no encryption-capable key found (no key flags or invalid algorithm)") { | ||
t.Fatal("wrong error") | ||
} | ||
} |
This file contains 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