mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 17:46:57 +02:00
fix(aes-encryption): labels.Serialize cover case when GenerateNonce errors
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
This commit is contained in:
parent
ca517446cc
commit
41cea23fff
@ -18,6 +18,7 @@ package endpoint
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -107,6 +108,34 @@ func (suite *LabelsSuite) TestEncryptionFailed() {
|
|||||||
suite.Contains(b.String(), "Failed to encrypt the text")
|
suite.Contains(b.String(), "Failed to encrypt the text")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *LabelsSuite) TestEncryptionFailedFaultyReader() {
|
||||||
|
foo, err := NewLabelsFromString(suite.fooAsTextEncrypted, suite.aesKey)
|
||||||
|
suite.NoError(err, "should succeed for valid label text")
|
||||||
|
|
||||||
|
// remove encryption nonce just for simplicity, so that we could regenerate nonce
|
||||||
|
delete(foo, txtEncryptionNonce)
|
||||||
|
|
||||||
|
originalRandReader := rand.Reader
|
||||||
|
defer func() {
|
||||||
|
log.StandardLogger().ExitFunc = nil
|
||||||
|
rand.Reader = originalRandReader
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Replace rand.Reader with a faulty reader
|
||||||
|
rand.Reader = &faultyReader{}
|
||||||
|
|
||||||
|
b := new(bytes.Buffer)
|
||||||
|
|
||||||
|
var fatalCrash bool
|
||||||
|
log.StandardLogger().ExitFunc = func(int) { fatalCrash = true }
|
||||||
|
log.StandardLogger().SetOutput(b)
|
||||||
|
|
||||||
|
_ = foo.Serialize(false, true, suite.aesKey)
|
||||||
|
|
||||||
|
suite.True(fatalCrash)
|
||||||
|
suite.Contains(b.String(), "Failed to generate cryptographic nonce")
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *LabelsSuite) TestDeserialize() {
|
func (suite *LabelsSuite) TestDeserialize() {
|
||||||
foo, err := NewLabelsFromStringPlain(suite.fooAsText)
|
foo, err := NewLabelsFromStringPlain(suite.fooAsText)
|
||||||
suite.NoError(err, "should succeed for valid label text")
|
suite.NoError(err, "should succeed for valid label text")
|
||||||
|
Loading…
Reference in New Issue
Block a user