Skip to content

Commit

Permalink
test: add tests for common/cryptoutils (#1074)
Browse files Browse the repository at this point in the history
* test: add tests for common/cryptoutils

Signed-off-by: Vamsi Krishna <vamsikrishnasatyasi971@gmail.com>

* fix: update certificate

Signed-off-by: Vamsi Krishna <vamsikrishnasatyasi971@gmail.com>

---------

Signed-off-by: Vamsi Krishna <vamsikrishnasatyasi971@gmail.com>
Co-authored-by: Hari <harikrishmenon@gmail.com>
  • Loading branch information
SVKREP and HarikrishnanBalagopal authored Aug 22, 2023
1 parent 43a1ca8 commit 516df66
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
53 changes: 53 additions & 0 deletions common/cryptoutils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright IBM Corporation 2021, 2022
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package common_test

import (
"os"
"testing"

"github.com/konveyor/move2kube/common"
)

func TestEncryption(t *testing.T) {

t.Run("RSA with Certificate", func(t *testing.T) {
certificatePath := "testdata/testDataForCryptoutils/RSA_Cert.pem"
certificateContent, err := os.ReadFile(certificatePath)
if err != nil {
t.Fatalf("Failed to read certificate file: %v", err)
}
data := "data_to_encrypt"
encryptedData := common.EncryptRsaCertWrapper(string(certificateContent), data)

if encryptedData == "" {
t.Errorf("Expected encrypted data, but got an empty string")
}
})

t.Run("AES with Pbkdf", func(t *testing.T) {
key := "qwerty"
data := "data_to_encrypt"

encryptedData := common.EncryptAesCbcWithPbkdfWrapper(key, data)

if encryptedData == "" {
t.Errorf("Expected encrypted data, but got an empty string")
}
})

}
18 changes: 18 additions & 0 deletions common/testdata/testDataForCryptoutils/RSA_Cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC7DCCAdQCCQDdzJPF7WGfbDANBgkqhkiG9w0BAQsFADA4MQswCQYDVQQGEwJV
UzETMBEGA1UECAwKQ2FsaWZvcm5pYTEUMBIGA1UEBwwLU2FudGEgQ2xhcmEwHhcN
MjMwODIwMTIyMzAxWhcNMjQwODE5MTIyMzAxWjA4MQswCQYDVQQGEwJVUzETMBEG
A1UECAwKQ2FsaWZvcm5pYTEUMBIGA1UEBwwLU2FudGEgQ2xhcmEwggEiMA0GCSqG
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtCRNP9FNocEB5ELCBW84quUjX7yaNPHyH
FsCkNHZpzovKzXVENgiH52EbvL5BGBpH0cHoB9E4zDcIQL1FkujHViB8wOYtgcLa
NmrFs+IPcevWdd76UB4YB1hkfpEED+DcU1H9beONGiyKBniiHywiAJE1eElX4rW3
gGmYI+tEciVETet7+TF4TSrcyBqDxJULxrs5CvKLKPNqIpTG8yHsz6QASF1Gbo0B
TX4Ga3tptq/HHFcUopdG+GaLBJASj+7zP8jRf38L5lGI1GOTdpXWp4A8vljxxBpl
xl1x572yyLXfOBi6bRnDN9T88VqkdhSjINIyf7wt0zKM8gPhQrBrAgMBAAEwDQYJ
KoZIhvcNAQELBQADggEBACTV7GBxVn6E2QqIy2Am/kAsgWnkZ3N9PF78zoufzkGg
3YfM5YnGSqxWjCcTAbg3UyZs+2HLYKHOyZlysc0qlvRteNMo31jMG/jKLWlvo5H1
+DRYUaG1PA4rADcRI6xcPmNaGISkV936ykxYiEO2lXR2DnVaU/qpKlNqvAOwqxtV
grqemFcdij0wS4Oi6L0gL/NV+YAbSuOvz7ZS1eUhTPuJmSshUzArn+yaR+LSzEln
Ba0oRs5mQwLi95ux4Ml2cZGbgQjXE1Co/+l1zQ5BzvnDVyEWMbzH5KUB0pSeU774
Uz77ugBLGaRiERZijPnxq94g2CF3/p1NYnZjBTWOv0w=
-----END CERTIFICATE-----

0 comments on commit 516df66

Please sign in to comment.