src/jetstream/plugins/kubernetes/auth/cert_tests.go
package auth
import (
"encoding/json"
"net/http/httptest"
"strings"
"testing"
"github.com/labstack/echo/v4"
)
func TestFetchCertAuth(t *testing.T) {
kubeSpec := &CertKubeAuth{}
mockConnectRequet := "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURBRENDQWVpZ0F3SUJBZ0lCQWpBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwdGFXNXAKYTNWaVpVTkJNQjRYRFRFNE1UQXhNakUyTlRnMU1Wb1hEVEU1TVRBeE16RTJOVGcxTVZvd01URVhNQlVHQTFVRQpDaE1PYzNsemRHVnRPbTFoYzNSbGNuTXhGakFVQmdOVkJBTVREVzFwYm1scmRXSmxMWFZ6WlhJd2dnRWlNQTBHCkNTcUdTSWIzRFFFQkFRVUFBNElCRHdBd2dnRUtBb0lCQVFEeFNtT2dORmV5VjkyRE5Sa0RmNVNSZlk5WHhGRVkKbFF2Z3lEcmFnVVpCcXFTaFBaZGdFdnBFWlVObkVoa1ZaYnc5WGUxelFMdVFuZnJEaERzOHlqTk8xWTV4ZUt2cwpIQlVBZEsxa2FQMlBXMVhSN3hxREh2SFdhQ3dRWVdHK1Bsa0NXMzg1YzBsNktXRUc5SVlFWFdkT1VDbEZuT3ZoCnJBN2RTNWR5eFViU3FCd0RSSDljMlhDVjQ4c1dLZnJhdmQvMTg5bWJENStQRk9ZditnRFFycHBTYnUzQytjTmYKbC93NDl0L0NQWlQ4bHFWU2FBUHhzOXFKbStKSFVFWHk3a1p2bGRZbG83NjJ3V1B6c0JoaXNkNU5ua2hmbGhrUApKSWNrWjN5eWF5bkdkOWJlKzdva2hwVEt1STNReGh5MTBrMWsxc1dyYmJTWVJDbmQ1akdVN3N2REFnTUJBQUdqClB6QTlNQTRHQTFVZER3RUIvd1FFQXdJRm9EQWRCZ05WSFNVRUZqQVVCZ2dyQmdFRkJRY0RBUVlJS3dZQkJRVUgKQXdJd0RBWURW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UnFmRmRFWXdQQ3p2V09vVkpSZGJsUXk0RHZkOEp4TWkrVFBCclFvanhvbQpzR0F3ZC9vanVObTVtWXFCcUltcnBHVUljL3FzcW5ZMU5jbVBqNkdobTJMMTdtanh3eTh0c2VEeDcxbkhvdWJ0CmcveitsS2ZzUUlZYUN0VzJnNUhvWUNpcEFvR0JBTTNtcHAvQTNYakNScXJLbFc3YTRNNHZZWk0rNTl4eUlQTmkKQnZ3d3Z0YjMrUFU3djUweWNjQ09CRFhKMVFrbWZoRHh5Z1ppdW54WWM5NEhncXgzVkE1cjh1ZzlNRmVxaTVkUApZL0Y1T0hySCtydnFUTnhIUnFBVTZ1UmEyTHNILzEwNzNnVGFMUmtwZzU4eElLR0tNUGhWZ05ZRTltRlVpWEpaCmM2UE52UjhCQW9HQU0zNTlZSUNUalNNYlYvSjJUbUx1Zjh2ejh0WVJDeXlla0h6Z2tTcmpqWUZWNmoxUTllWGQKa1ZFWitaYW1xYkZvUmxqK1lHS21XQ0w0OXJTWkYxNmVYL1V3OW5haEErcmtYL21aaERkOXIrVE90enpycUVYSQpUQVlld3R5ZGEzUzkyaytOWU8zZE5kbWZLQVdYV2JzdjZUKzBBTXR6VTFkMlNaaDlsTU5aVkUwPQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo="
e := echo.New()
req := httptest.NewRequest(echo.POST, "/pp/v1/auth/login/cnsi?cert=&certKey=&cnsi_guid=testGuid&connect_type=kube-cert-auth&system_shared=false", strings.NewReader(mockConnectRequet))
engineReq := req
rec := httptest.NewRecorder()
res := echo.NewResponse(rec, e)
c := e.NewContext(engineReq, res)
kubeCertAuth, err := kubeSpec.extractCerts(c)
if err != nil {
t.Fail()
}
if kubeCertAuth.Certificate == "" {
t.Fail()
}
if kubeCertAuth.CertificateKey == "" {
t.Fail()
}
jsonString, err := kubeCertAuth.GetJSON()
if err != nil {
t.Fail()
}
testKubeCertAuth := &KubeCertificate{}
err = json.NewDecoder(strings.NewReader(jsonString)).Decode(testKubeCertAuth)
if err != nil {
t.Fail()
}
if testKubeCertAuth.Certificate != kubeCertAuth.Certificate {
t.Fail()
}
if testKubeCertAuth.CertificateKey != kubeCertAuth.CertificateKey {
t.Fail()
}
}