-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
70 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package tests | ||
|
||
import ( | ||
"crypto/x509" | ||
"encoding/pem" | ||
"fmt" | ||
"io" | ||
) | ||
|
||
type mockPemOK struct{} | ||
type mockPemFail struct{} | ||
type mockX509OK struct{} | ||
type mockX509Fail struct{} | ||
|
||
func (m *mockPemOK) Decode(input []byte) (*pem.Block, []byte) { | ||
b := pem.Block{Bytes: input} | ||
return &b, nil | ||
} | ||
func (m *mockPemOK) Encode(out io.Writer, b *pem.Block) error { | ||
return nil | ||
} | ||
|
||
func (m *mockPemFail) Decode(input []byte) (*pem.Block, []byte) { | ||
return nil, nil | ||
} | ||
|
||
func (m *mockPemFail) Encode(out io.Writer, b *pem.Block) error { | ||
return fmt.Errorf("cannot encode buffer") |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package tests | ||
|
||
import ( | ||
"crypto/x509" | ||
"fmt" | ||
"io" | ||
) | ||
|
||
type mockCreateCertificateCA struct{} | ||
type mockCreateCertificateCE struct{} | ||
|
||
func (m *mockCreateCertificateCA) CreateCertificate(rand io.Reader, template *x509.Certificate, parent *x509.Certificate, pub any, priv any) ([]byte, error) { | ||
b := []byte{0xAA} | ||
return b, nil | ||
} | ||
|
||
func (m *mockX509Fail) CreateCertificate(rand io.Reader, template *x509.Certificate, parent *x509.Certificate, pub any, priv any) ([]byte, error) { | ||
b := []byte{0x56, 0xAA, 0x21} | ||
return b, nil | ||
} | ||
|
||
func (m *mockX509OK) ParseCertificate(der []byte) (*x509.Certificate, error) { | ||
return &x509.Certificate{}, nil | ||
} | ||
|
||
func (m *mockX509Fail) ParseCertificate(der []byte) (*x509.Certificate, error) { | ||
return nil, fmt.Errorf("x509: malformed certificate") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/zLukas/CloudTools/src/cert-generator/pkg/tls" | ||
) | ||
|
||
func TestRemoveEmptyStringEmptyString(t *testing.T) { | ||
empty_string := []string{""} | ||
result := tls.RemoveEmptyString(empty_string) | ||
|
||
if len(result) != 0 { | ||
t.Errorf("string array should have 0 lenght, go %v", len(result)) | ||
} | ||
} | ||
|
||
func TestRemoveEmptyStringNotEmptyString(t *testing.T) { | ||
empty_string := []string{"asd", "asd", "wersfds"} | ||
result := tls.RemoveEmptyString(empty_string) | ||
|
||
if len(result) != 3 { | ||
t.Errorf("string array should have 3 lenght, go %v", len(result)) | ||
} | ||
} |