Add Better Error Handling for SSLSessionTicketKey
Adds more error handling when writing an SSLSessionTicketKey to the config map. Also adds tests and makes the function for modular. Fixes #2756
This commit is contained in:
parent
6615e98186
commit
52ecdf0b46
4 changed files with 72 additions and 13 deletions
|
|
@ -33,6 +33,9 @@ import (
|
|||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
|
||||
"encoding/base64"
|
||||
"io/ioutil"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
|
|
@ -828,3 +831,39 @@ func TestListIngresses(t *testing.T) {
|
|||
t.Errorf("Expected 3 Ingresses but got %v", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteSSLSessionTicketKey(t *testing.T) {
|
||||
tests := []string{
|
||||
"9DyULjtYWz520d1rnTLbc4BOmN2nLAVfd3MES/P3IxWuwXkz9Fby0lnOZZUdNEMV",
|
||||
"9SvN1C9AB5DvNde5fMKoJwAwICpqdjiMyxR+cv6NpAWv22rFd3gKt4wMyGxCm7l9Wh6BQPG0+csyBZSHHr2NOWj52Wx8xCegXf4NsSMBUqA=",
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
s := newStore(t)
|
||||
|
||||
cmap := &v1.ConfigMap{
|
||||
Data: map[string]string{
|
||||
"ssl-session-ticket-key": test,
|
||||
},
|
||||
}
|
||||
|
||||
f, err := ioutil.TempFile("", "ssl-session-ticket-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s.writeSSLSessionTicketKey(cmap, f.Name())
|
||||
|
||||
content, err := ioutil.ReadFile(f.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
encodedContent := base64.StdEncoding.EncodeToString(content)
|
||||
|
||||
f.Close()
|
||||
|
||||
if test != encodedContent {
|
||||
t.Fatalf("expected %v but returned %s", test, encodedContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue